@@ -1279,6 +1279,10 @@ func TestServer(t *testing.T) {
1279
1279
_ = os .Remove (fi3 .Name ())
1280
1280
}()
1281
1281
1282
+ // NOTE(mafredri): This test might end up downloading Terraform
1283
+ // which can take a long time and end up failing the test.
1284
+ // This is why we wait extra long below for server to listen on
1285
+ // HTTP.
1282
1286
root , _ := clitest .New (t ,
1283
1287
"server" ,
1284
1288
"--verbose" ,
@@ -1289,26 +1293,38 @@ func TestServer(t *testing.T) {
1289
1293
"--log-json" , fi2 .Name (),
1290
1294
"--log-stackdriver" , fi3 .Name (),
1291
1295
)
1296
+ // Attach pty so we get debug output from the command if this test
1297
+ // fails.
1298
+ pty := ptytest .New (t )
1299
+ root .SetOut (pty .Output ())
1300
+ root .SetErr (pty .Output ())
1301
+
1292
1302
serverErr := make (chan error , 1 )
1293
1303
go func () {
1294
1304
serverErr <- root .ExecuteContext (ctx )
1295
1305
}()
1306
+ defer func () {
1307
+ cancelFunc ()
1308
+ <- serverErr
1309
+ }()
1296
1310
1297
- assert .Eventually (t , func () bool {
1311
+ require .Eventually (t , func () bool {
1312
+ line := pty .ReadLine ()
1313
+ return strings .HasPrefix (line , "Started HTTP listener at " )
1314
+ }, testutil .WaitLong * 2 , testutil .IntervalMedium , "wait for server to listen on http" )
1315
+
1316
+ require .Eventually (t , func () bool {
1298
1317
stat , err := os .Stat (fi1 .Name ())
1299
1318
return err == nil && stat .Size () > 0
1300
- }, testutil .WaitLong , testutil .IntervalMedium )
1301
- assert .Eventually (t , func () bool {
1319
+ }, testutil .WaitShort , testutil .IntervalMedium , "log human size > 0" )
1320
+ require .Eventually (t , func () bool {
1302
1321
stat , err := os .Stat (fi2 .Name ())
1303
1322
return err == nil && stat .Size () > 0
1304
- }, testutil .WaitLong , testutil .IntervalMedium )
1305
- assert .Eventually (t , func () bool {
1323
+ }, testutil .WaitShort , testutil .IntervalMedium , "log json size > 0" )
1324
+ require .Eventually (t , func () bool {
1306
1325
stat , err := os .Stat (fi3 .Name ())
1307
1326
return err == nil && stat .Size () > 0
1308
- }, testutil .WaitLong , testutil .IntervalMedium )
1309
-
1310
- cancelFunc ()
1311
- <- serverErr
1327
+ }, testutil .WaitShort , testutil .IntervalMedium , "log stackdriver size > 0" )
1312
1328
})
1313
1329
})
1314
1330
}
0 commit comments