@@ -180,6 +180,7 @@ func TestPrebuildWorkspaceTaskFail(t *testing.T) {
180
180
const (
181
181
prebuildLogPath string = "/workspace/.gitpod"
182
182
prebuildLog string = "'🤙 This task ran as a workspace prebuild'"
183
+ initTask string = "echo \" some output\" > someFile; sleep 20; exit 0;"
183
184
)
184
185
185
186
func TestOpenWorkspaceFromPrebuild (t * testing.T ) {
@@ -223,7 +224,7 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
223
224
req .Type = wsmanapi .WorkspaceType_PREBUILD
224
225
req .Spec .Envvars = append (req .Spec .Envvars , & wsmanapi.EnvironmentVariable {
225
226
Name : "GITPOD_TASKS" ,
226
- Value : `[{ "init": "echo \"some output\" > someFile; sleep 60; exit 0;" }]` ,
227
+ Value : fmt . Sprintf ( `[{ "init": %q }]` , initTask ) ,
227
228
})
228
229
req .Spec .FeatureFlags = test .FF
229
230
req .Spec .Initializer = & csapi.WorkspaceInitializer {
@@ -298,8 +299,8 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
298
299
integration .DeferCloser (t , closer )
299
300
300
301
// check prebuild log message exists
302
+ var checkPrebuildLogSuccess bool
301
303
var resp agent.ExecResponse
302
- var checkPrebuildSuccess bool
303
304
for i := 0 ; i < 10 ; i ++ {
304
305
err = rsa .Call ("WorkspaceAgent.Exec" , & agent.ExecRequest {
305
306
Dir : prebuildLogPath ,
@@ -310,16 +311,57 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
310
311
},
311
312
}, & resp )
312
313
if err == nil && resp .ExitCode == 0 && strings .Trim (resp .Stdout , " \t \n " ) != "" {
313
- checkPrebuildSuccess = true
314
+ checkPrebuildLogSuccess = true
314
315
break
315
316
}
316
317
317
- // wait 3 seconds and check
318
- time .Sleep (3 * time .Second )
318
+ // wait 6 seconds and check
319
+ time .Sleep (6 * time .Second )
319
320
}
320
321
321
- if ! checkPrebuildSuccess {
322
- t .Fatalf ("cannot found the prebuild message %s in %s, err:%v, exitCode:%d, stdout:%s" , prebuildLog , prebuildLogPath , err , resp .ExitCode , resp .Stdout )
322
+ if ! checkPrebuildLogSuccess {
323
+ // somehow, the prebuild log message '🤙 This task ran as a workspace prebuild' does not exists
324
+ // we fall back to check the the init task message within the /workspace/.gitpod/prebuild-log-* or not
325
+ t .Logf ("cannot found the prebuild message %s in %s, err:%v, exitCode:%d, stdout:%s" , prebuildLog , prebuildLogPath , err , resp .ExitCode , resp .Stdout )
326
+
327
+ // check the init task message exists
328
+ var checkInitTaskMsgSuccess bool
329
+ err = rsa .Call ("WorkspaceAgent.Exec" , & agent.ExecRequest {
330
+ Dir : prebuildLogPath ,
331
+ Command : "bash" ,
332
+ Args : []string {
333
+ "-c" ,
334
+ fmt .Sprintf ("grep %q *" , initTask ),
335
+ },
336
+ }, & resp )
337
+ if err == nil && resp .ExitCode == 0 && strings .Trim (resp .Stdout , " \t \n " ) != "" {
338
+ checkInitTaskMsgSuccess = true
339
+ }
340
+
341
+ if ! checkInitTaskMsgSuccess {
342
+ t .Logf ("cannot found the init task message %s in %s, err:%v, exitCode:%d, stdout:%s" , initTask , prebuildLogPath , err , resp .ExitCode , resp .Stdout )
343
+
344
+ // somehow, the init task message does not exist within the /workspace/.gitpod/prebuild-log-*
345
+ // we fall back to check the file exists or not
346
+ var ls agent.ListDirResponse
347
+ err = rsa .Call ("WorkspaceAgent.ListDir" , & agent.ListDirRequest {
348
+ Dir : test .WorkspaceRoot ,
349
+ }, & ls )
350
+ if err != nil {
351
+ t .Fatal (err )
352
+ }
353
+
354
+ var found bool
355
+ for _ , f := range ls .Files {
356
+ if filepath .Base (f ) == "someFile" {
357
+ found = true
358
+ break
359
+ }
360
+ }
361
+ if ! found {
362
+ t .Fatal ("did not find someFile from previous workspace instance" )
363
+ }
364
+ }
323
365
}
324
366
325
367
// write file foobar.txt and stop the workspace
@@ -414,7 +456,7 @@ func stopWorkspaceAndFindSnapshot(StopWorkspaceFunc integration.StopWorkspaceFun
414
456
if err != nil {
415
457
return "" , nil , err
416
458
}
417
- if lastStatus == nil && lastStatus .Conditions == nil {
459
+ if lastStatus == nil || lastStatus .Conditions == nil || lastStatus . Conditions . VolumeSnapshot == nil {
418
460
return "" , nil , nil
419
461
}
420
462
return lastStatus .Conditions .Snapshot , lastStatus .Conditions .VolumeSnapshot , nil
0 commit comments