@@ -492,6 +492,162 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
492
492
testEnv .Test (t , f )
493
493
}
494
494
495
+ // TestOpenWorkspaceFromOutdatedPrebuild
496
+ // - create a prebuild on older commit
497
+ // - open a workspace from a later commit with a prebuild initializer
498
+ // - make sure the workspace's init task ran (the init task will create a file `incremental.txt` see https://github.com/gitpod-io/test-incremental-workspace/blob/main/.gitpod.yml)
499
+ func TestOpenWorkspaceFromOutdatedPrebuild (t * testing.T ) {
500
+
501
+ f := features .New ("prebuild" ).
502
+ WithLabel ("component" , "ws-manager" ).
503
+ Assess ("it should open a workspace from with an older prebuild initializer successfully and run the init task" , func (_ context.Context , t * testing.T , cfg * envconf.Config ) context.Context {
504
+ tests := []struct {
505
+ Name string
506
+ RemoteUri string
507
+ CloneTargetForPrebuild string
508
+ CloneTargetForWorkspace string
509
+ WorkspaceRoot string
510
+ CheckoutLocation string
511
+ FF []wsmanapi.WorkspaceFeatureFlag
512
+ }{
513
+ {
514
+ Name : "classic" ,
515
+ RemoteUri : "https://github.com/gitpod-io/test-incremental-workspace" ,
516
+ CloneTargetForPrebuild : "prebuild" ,
517
+ CloneTargetForWorkspace : "main" ,
518
+ CheckoutLocation : "test-incremental-workspace" ,
519
+ WorkspaceRoot : "/workspace/test-incremental-workspace" ,
520
+ },
521
+ }
522
+
523
+ ctx , cancel := context .WithTimeout (context .Background (), time .Duration (10 * len (tests ))* time .Minute )
524
+ defer cancel ()
525
+
526
+ for _ , test := range tests {
527
+ t .Run (test .Name , func (t * testing.T ) {
528
+
529
+ api := integration .NewComponentAPI (ctx , cfg .Namespace (), kubeconfig , cfg .Client ())
530
+ t .Cleanup (func () {
531
+ api .Done (t )
532
+ })
533
+
534
+ // create a prebuild
535
+ ws , prebuildStopWs , err := integration .LaunchWorkspaceDirectly (t , ctx , api , integration .WithRequestModifier (func (req * wsmanapi.StartWorkspaceRequest ) error {
536
+ req .Type = wsmanapi .WorkspaceType_PREBUILD
537
+ req .Spec .Envvars = append (req .Spec .Envvars , & wsmanapi.EnvironmentVariable {
538
+ Name : "GITPOD_TASKS" ,
539
+ Value : `[{ "init": "./init.sh" }]` ,
540
+ })
541
+ req .Spec .FeatureFlags = test .FF
542
+ req .Spec .Initializer = & csapi.WorkspaceInitializer {
543
+ Spec : & csapi.WorkspaceInitializer_Git {
544
+ Git : & csapi.GitInitializer {
545
+ RemoteUri : test .RemoteUri ,
546
+ TargetMode : csapi .CloneTargetMode_REMOTE_BRANCH ,
547
+ CloneTaget : test .CloneTargetForPrebuild ,
548
+ CheckoutLocation : test .CheckoutLocation ,
549
+ Config : & csapi.GitConfig {},
550
+ },
551
+ },
552
+ }
553
+ req .Spec .WorkspaceLocation = test .CheckoutLocation
554
+ return nil
555
+ }))
556
+ if err != nil {
557
+ t .Fatalf ("cannot launch a workspace: %q" , err )
558
+ }
559
+ defer func () {
560
+ // stop workspace in defer function to prevent we forget to stop the workspace
561
+ if err := stopWorkspace (t , cfg , prebuildStopWs ); err != nil {
562
+ t .Errorf ("cannot stop workspace: %q" , err )
563
+ }
564
+ }()
565
+ prebuildSnapshot , prebuildVSInfo , err := watchStopWorkspaceAndFindSnapshot (ctx , ws .Req .Id , api )
566
+ if err != nil {
567
+ t .Fatalf ("stop workspace and find snapshot error: %v" , err )
568
+ }
569
+
570
+ t .Logf ("prebuild snapshot: %s" , prebuildSnapshot )
571
+
572
+ // launch the workspace on a later commit using this prebuild
573
+ ws , stopWs , err := integration .LaunchWorkspaceDirectly (t , ctx , api , integration .WithRequestModifier (func (req * wsmanapi.StartWorkspaceRequest ) error {
574
+ req .Spec .Envvars = append (req .Spec .Envvars , & wsmanapi.EnvironmentVariable {
575
+ Name : "GITPOD_TASKS" ,
576
+ Value : `[{ "init": "./init.sh" }]` ,
577
+ })
578
+ req .Spec .FeatureFlags = test .FF
579
+ req .Spec .Initializer = & csapi.WorkspaceInitializer {
580
+ Spec : & csapi.WorkspaceInitializer_Prebuild {
581
+ Prebuild : & csapi.PrebuildInitializer {
582
+ Prebuild : & csapi.SnapshotInitializer {
583
+ Snapshot : prebuildSnapshot ,
584
+ },
585
+ Git : []* csapi.GitInitializer {
586
+ {
587
+ RemoteUri : test .RemoteUri ,
588
+ TargetMode : csapi .CloneTargetMode_REMOTE_BRANCH ,
589
+ CloneTaget : test .CloneTargetForWorkspace ,
590
+ CheckoutLocation : test .CheckoutLocation ,
591
+ Config : & csapi.GitConfig {},
592
+ },
593
+ },
594
+ },
595
+ },
596
+ }
597
+ req .Spec .VolumeSnapshot = prebuildVSInfo
598
+ req .Spec .WorkspaceLocation = test .CheckoutLocation
599
+ return nil
600
+ }))
601
+ if err != nil {
602
+ t .Fatalf ("cannot launch a workspace: %q" , err )
603
+ }
604
+
605
+ defer func () {
606
+ // stop workspace in defer function to prevent we forget to stop the workspace
607
+ if err := stopWorkspace (t , cfg , stopWs ); err != nil {
608
+ t .Errorf ("cannot stop workspace: %q" , err )
609
+ }
610
+ }()
611
+
612
+ rsa , closer , err := integration .Instrument (integration .ComponentWorkspace , "workspace" , cfg .Namespace (), kubeconfig , cfg .Client (),
613
+ integration .WithInstanceID (ws .Req .Id ),
614
+ )
615
+ if err != nil {
616
+ t .Fatal (err )
617
+ }
618
+ t .Cleanup (func () {
619
+ rsa .Close ()
620
+ })
621
+ integration .DeferCloser (t , closer )
622
+
623
+ var ls agent.ListDirResponse
624
+ err = rsa .Call ("WorkspaceAgent.ListDir" , & agent.ListDirRequest {
625
+ Dir : test .WorkspaceRoot ,
626
+ }, & ls )
627
+ if err != nil {
628
+ t .Fatal (err )
629
+ }
630
+ rsa .Close ()
631
+
632
+ var found bool
633
+ for _ , f := range ls .Files {
634
+ t .Logf ("file: %s" , f )
635
+ if filepath .Base (f ) == "incremental.txt" {
636
+ found = true
637
+ }
638
+ }
639
+ if ! found {
640
+ t .Fatal ("did not find incremental.txt" )
641
+ }
642
+ })
643
+ }
644
+ return ctx
645
+ }).
646
+ Feature ()
647
+
648
+ testEnv .Test (t , f )
649
+ }
650
+
495
651
// TestPrebuildAndRegularWorkspaceDifferentWorkspaceClass
496
652
// - create a prebuild with small workspace class (20Gi disk)
497
653
// - create the workspace from prebulid with large workspace class (30Gi disk)
0 commit comments