github.com/tilt-dev/tilt@v0.36.0/integration/same_img_multi_container_test.go (about)

     1  //go:build integration
     2  // +build integration
     3  
     4  package integration
     5  
     6  import (
     7  	"context"
     8  	"testing"
     9  	"time"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  func TestSameImgMultiContainer(t *testing.T) {
    15  	f := newK8sFixture(t, "same_img_multi_container")
    16  
    17  	f.TiltUp()
    18  
    19  	ctx, cancel := context.WithTimeout(f.ctx, time.Minute)
    20  	defer cancel()
    21  	firstPods := f.WaitForAllPodsReady(ctx, "app=sameimg")
    22  
    23  	ctx, cancel = context.WithTimeout(f.ctx, time.Minute)
    24  	defer cancel()
    25  	f.CurlUntil(ctx, "http://localhost:8100", "🍄 One-Up! 🍄")
    26  	f.CurlUntil(ctx, "http://localhost:8101", "🍄 One-Up! 🍄")
    27  
    28  	f.ReplaceContents("source.txt", "One-Up", "Two-Up")
    29  
    30  	ctx, cancel = context.WithTimeout(f.ctx, time.Minute)
    31  	defer cancel()
    32  	f.CurlUntil(ctx, "http://localhost:8100", "🍄 Two-Up! 🍄")
    33  	f.CurlUntil(ctx, "http://localhost:8101", "🍄 Two-Up! 🍄")
    34  
    35  	secondPods := f.WaitForAllPodsReady(ctx, "app=sameimg")
    36  
    37  	// Assert that the pods were changed in-place, and not that we
    38  	// created new pods.
    39  	assert.Equal(t, firstPods, secondPods)
    40  
    41  	// Kill one of the containers, and make sure it gets replaced
    42  	// We expect the `kill` command to die abnormally when the parent process dies.
    43  	_, _ = f.runCommand("kubectl", "exec", secondPods[0], "-c=c2", namespaceFlag,
    44  		"--", "kill", "1")
    45  
    46  	// live update v2 keeps track of all changes since
    47  	// the container started, and will be able to restore in-place.
    48  	ctx, cancel = context.WithTimeout(f.ctx, time.Minute)
    49  	defer cancel()
    50  	f.CurlUntil(ctx, "http://localhost:8100", "🍄 Two-Up! 🍄")
    51  	f.CurlUntil(ctx, "http://localhost:8101", "🍄 Two-Up! 🍄")
    52  
    53  	replacedPods := f.WaitForAllPodsReady(ctx, "app=sameimg")
    54  	assert.Equal(t, secondPods, replacedPods)
    55  }