@@ -104,35 +104,7 @@ func TestReadGitAuthProvidersFromEnv(t *testing.T) {
104
104
})
105
105
}
106
106
107
- // This cannot be ran in parallel because it uses a signal.
108
- // nolint:tparallel,paralleltest
109
107
func TestServer (t * testing.T ) {
110
- t .Run ("Production" , func (t * testing.T ) {
111
- if runtime .GOOS != "linux" || testing .Short () {
112
- // Skip on non-Linux because it spawns a PostgreSQL instance.
113
- t .SkipNow ()
114
- }
115
- connectionURL , closeFunc , err := postgres .Open ()
116
- require .NoError (t , err )
117
- defer closeFunc ()
118
-
119
- // Postgres + race detector + CI = slow.
120
- ctx := testutil .Context (t , testutil .WaitSuperLong * 3 )
121
-
122
- inv , cfg := clitest .New (t ,
123
- "server" ,
124
- "--http-address" , ":0" ,
125
- "--access-url" , "http://example.com" ,
126
- "--postgres-url" , connectionURL ,
127
- "--cache-dir" , t .TempDir (),
128
- )
129
- clitest .Start (t , inv .WithContext (ctx ))
130
- accessURL := waitAccessURL (t , cfg )
131
- client := codersdk .New (accessURL )
132
-
133
- _ , err = client .CreateFirstUser (ctx , coderdtest .FirstUserParams )
134
- require .NoError (t , err )
135
- })
136
108
t .Run ("BuiltinPostgres" , func (t * testing.T ) {
137
109
t .Parallel ()
138
110
if testing .Short () {
@@ -855,38 +827,6 @@ func TestServer(t *testing.T) {
855
827
})
856
828
})
857
829
858
- // This cannot be ran in parallel because it uses a signal.
859
- //nolint:paralleltest
860
- t .Run ("Shutdown" , func (t * testing.T ) {
861
- if runtime .GOOS == "windows" {
862
- // Sending interrupt signal isn't supported on Windows!
863
- t .SkipNow ()
864
- }
865
- ctx , cancelFunc := context .WithCancel (context .Background ())
866
- defer cancelFunc ()
867
-
868
- root , cfg := clitest .New (t ,
869
- "server" ,
870
- "--in-memory" ,
871
- "--http-address" , ":0" ,
872
- "--access-url" , "http://example.com" ,
873
- "--provisioner-daemons" , "1" ,
874
- "--cache-dir" , t .TempDir (),
875
- )
876
- serverErr := make (chan error , 1 )
877
- go func () {
878
- serverErr <- root .WithContext (ctx ).Run ()
879
- }()
880
- _ = waitAccessURL (t , cfg )
881
- currentProcess , err := os .FindProcess (os .Getpid ())
882
- require .NoError (t , err )
883
- err = currentProcess .Signal (os .Interrupt )
884
- require .NoError (t , err )
885
- // We cannot send more signals here, because it's possible Coder
886
- // has already exited, which could cause the test to fail due to interrupt.
887
- err = <- serverErr
888
- require .NoError (t , err )
889
- })
890
830
t .Run ("TracerNoLeak" , func (t * testing.T ) {
891
831
t .Parallel ()
892
832
@@ -1493,6 +1433,66 @@ func TestServer(t *testing.T) {
1493
1433
})
1494
1434
}
1495
1435
1436
+ //nolint:paralleltest // This test spawns or connects to an existing PostgreSQL instance.
1437
+ func TestServer_Production (t * testing.T ) {
1438
+ if runtime .GOOS != "linux" || testing .Short () {
1439
+ // Skip on non-Linux because it spawns a PostgreSQL instance.
1440
+ t .SkipNow ()
1441
+ }
1442
+ connectionURL , closeFunc , err := postgres .Open ()
1443
+ require .NoError (t , err )
1444
+ defer closeFunc ()
1445
+
1446
+ // Postgres + race detector + CI = slow.
1447
+ ctx := testutil .Context (t , testutil .WaitSuperLong * 3 )
1448
+
1449
+ inv , cfg := clitest .New (t ,
1450
+ "server" ,
1451
+ "--http-address" , ":0" ,
1452
+ "--access-url" , "http://example.com" ,
1453
+ "--postgres-url" , connectionURL ,
1454
+ "--cache-dir" , t .TempDir (),
1455
+ )
1456
+ clitest .Start (t , inv .WithContext (ctx ))
1457
+ accessURL := waitAccessURL (t , cfg )
1458
+ client := codersdk .New (accessURL )
1459
+
1460
+ _ , err = client .CreateFirstUser (ctx , coderdtest .FirstUserParams )
1461
+ require .NoError (t , err )
1462
+ }
1463
+
1464
+ //nolint:paralleltest // This test cannot be run in parallel due to signal handling.
1465
+ func TestServer_Shutdown (t * testing.T ) {
1466
+ if runtime .GOOS == "windows" {
1467
+ // Sending interrupt signal isn't supported on Windows!
1468
+ t .SkipNow ()
1469
+ }
1470
+ ctx , cancelFunc := context .WithCancel (context .Background ())
1471
+ defer cancelFunc ()
1472
+
1473
+ root , cfg := clitest .New (t ,
1474
+ "server" ,
1475
+ "--in-memory" ,
1476
+ "--http-address" , ":0" ,
1477
+ "--access-url" , "http://example.com" ,
1478
+ "--provisioner-daemons" , "1" ,
1479
+ "--cache-dir" , t .TempDir (),
1480
+ )
1481
+ serverErr := make (chan error , 1 )
1482
+ go func () {
1483
+ serverErr <- root .WithContext (ctx ).Run ()
1484
+ }()
1485
+ _ = waitAccessURL (t , cfg )
1486
+ currentProcess , err := os .FindProcess (os .Getpid ())
1487
+ require .NoError (t , err )
1488
+ err = currentProcess .Signal (os .Interrupt )
1489
+ require .NoError (t , err )
1490
+ // We cannot send more signals here, because it's possible Coder
1491
+ // has already exited, which could cause the test to fail due to interrupt.
1492
+ err = <- serverErr
1493
+ require .NoError (t , err )
1494
+ }
1495
+
1496
1496
func generateTLSCertificate (t testing.TB , commonName ... string ) (certPath , keyPath string ) {
1497
1497
dir := t .TempDir ()
1498
1498
0 commit comments