github.com/tilt-dev/tilt@v0.36.0/integration/live_update_after_crash_rebuild_test.go (about) 1 //go:build integration 2 // +build integration 3 4 package integration 5 6 import ( 7 "context" 8 "fmt" 9 "testing" 10 "time" 11 12 v1 "k8s.io/api/core/v1" 13 14 "github.com/stretchr/testify/require" 15 ) 16 17 func TestLiveUpdateAfterCrashRebuild(t *testing.T) { 18 f := newK8sFixture(t, "live_update_after_crash_rebuild") 19 20 f.SetRestrictedCredentials() 21 22 pw := f.newPodWaiter("app=live-update-after-crash-rebuild"). 23 withExpectedPhase(v1.PodRunning) 24 initialPods := pw.wait() 25 26 f.TiltUp() 27 28 fmt.Println("> Waiting for pods from initial build") 29 30 pw = pw.withExpectedPodCount(1) 31 32 initialBuildPods := pw.withDisallowedPodIDs(initialPods).wait() 33 34 ctx, cancel := context.WithTimeout(f.ctx, time.Minute) 35 defer cancel() 36 f.CurlUntil(ctx, "http://localhost:31234", "🍄 One-Up! 🍄") 37 38 // Live update 39 fmt.Println("> Perform a live update") 40 f.ReplaceContents("compile.sh", "One-Up", "Two-Up") 41 42 ctx, cancel = context.WithTimeout(f.ctx, time.Minute) 43 defer cancel() 44 f.CurlUntil(ctx, "http://localhost:31234", "🍄 Two-Up! 🍄") 45 46 // Check that the pods were changed in place, and that we didn't create new ones 47 afterLiveUpdatePods := pw.withDisallowedPodIDs(initialPods).wait() 48 require.Equal(t, initialBuildPods, afterLiveUpdatePods, "after first live update") 49 50 // Delete the pod and make sure it got replaced with something that prints the 51 // same thing (crash rebuild). 52 fmt.Println("> Kill pod, wait for crash rebuild") 53 f.runCommandSilently("kubectl", "delete", "pod", afterLiveUpdatePods[0], namespaceFlag) 54 55 ctx, cancel = context.WithTimeout(f.ctx, time.Minute) 56 defer cancel() 57 f.CurlUntil(ctx, "http://localhost:31234", "🍄 Two-Up! 🍄") 58 59 afterCrashRebuildPods := pw.withDisallowedPodIDs(afterLiveUpdatePods).wait() 60 61 // Another live update! Make sure that, after the crash rebuild, we're able to run more 62 // live updates (i.e. that we have one and only one pod associated w/ the manifest) 63 fmt.Println("> Perform another live update") 64 f.ReplaceContents("compile.sh", "Two-Up", "Three-Up") 65 66 ctx, cancel = context.WithTimeout(f.ctx, time.Minute) 67 defer cancel() 68 f.CurlUntil(ctx, "http://localhost:31234", "🍄 Three-Up! 🍄") 69 70 afterSecondLiveUpdatePods := pw.withDisallowedPodIDs(afterLiveUpdatePods).wait() 71 72 // Check that the pods were changed in place, and that we didn't create new ones 73 require.Equal(t, afterCrashRebuildPods, afterSecondLiveUpdatePods) 74 }