MCPcopy
hub / github.com/docker/compose / TestWatchMultiServices

Function TestWatchMultiServices

pkg/e2e/watch_test.go:325–369  ·  pkg/e2e/watch_test.go::TestWatchMultiServices
(t *testing.T)

Source from the content-addressed store, hash-verified

323}
324
325func TestWatchMultiServices(t *testing.T) {
326 c := NewCLI(t)
327 const projectName = "test_watch_rebuild"
328
329 defer c.cleanupWithDown(t, projectName)
330
331 tmpdir := t.TempDir()
332 composeFilePath := filepath.Join(tmpdir, "compose.yaml")
333 CopyFile(t, filepath.Join("fixtures", "watch", "rebuild.yaml"), composeFilePath)
334
335 testFile := filepath.Join(tmpdir, "test")
336 assert.NilError(t, os.WriteFile(testFile, []byte("test"), 0o600))
337
338 cmd := c.NewDockerComposeCmd(t, "-p", projectName, "-f", composeFilePath, "up", "--build", "--watch")
339 buffer := bytes.NewBuffer(nil)
340 cmd.Stdout = buffer
341 watch := icmd.StartCmd(cmd)
342
343 poll.WaitOn(t, func(l poll.LogT) poll.Result {
344 if strings.Contains(watch.Stdout(), "Attaching to ") {
345 return poll.Success()
346 }
347 return poll.Continue("%v", watch.Stdout())
348 }, poll.WithTimeout(90*time.Second))
349
350 waitRebuild := func(service string, expected string) {
351 poll.WaitOn(t, func(l poll.LogT) poll.Result {
352 cat := c.RunDockerComposeCmdNoCheck(t, "-p", projectName, "exec", service, "cat", "/data/"+service)
353 if strings.Contains(cat.Stdout(), expected) {
354 return poll.Success()
355 }
356 return poll.Continue("%v", cat.Combined())
357 }, poll.WithTimeout(90*time.Second))
358 }
359 waitRebuild("a", "test")
360 waitRebuild("b", "test")
361 waitRebuild("c", "test")
362
363 assert.NilError(t, os.WriteFile(testFile, []byte("updated"), 0o600))
364 waitRebuild("a", "updated")
365 waitRebuild("b", "updated")
366 waitRebuild("c", "updated")
367
368 c.RunDockerComposeCmdNoCheck(t, "-p", projectName, "kill", "-s", "9")
369}
370
371// TestWatchRebuildIgnoresDependencies verifies that when `compose up --watch`
372// rebuilds a service after a file change, the rebuild does NOT cascade to its

Callers

nothing calls this directly

Calls 7

cleanupWithDownMethod · 0.95
NewDockerComposeCmdMethod · 0.95
NewCLIFunction · 0.85
CopyFileFunction · 0.85
TempDirMethod · 0.80
WriteFileMethod · 0.80

Tested by

no test coverage detected