MCPcopy
hub / github.com/google/gvisor / TestMultiContainerEvent

Function TestMultiContainerEvent

runsc/container/multi_container_test.go:2365–2489  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2363}
2364
2365func TestMultiContainerEvent(t *testing.T) {
2366 tests := []string{"enableCgroups", "disableCgroups"}
2367 for _, name := range tests {
2368 conf := testutil.TestConfig(t)
2369 t.Run(name, func(t *testing.T) {
2370 rootDir, cleanup, err := testutil.SetupRootDir()
2371 if err != nil {
2372 t.Fatalf("error creating root dir: %v", err)
2373 }
2374 defer cleanup()
2375 conf.RootDir = rootDir
2376
2377 // Setup the containers.
2378 sleep := []string{"/bin/sh", "-c", "/bin/sleep 100 | grep 123"}
2379 busy := []string{"/bin/bash", "-c", "i=0 ; while true ; do (( i += 1 )) ; done"}
2380 quick := []string{"/bin/true"}
2381 podSpecs, ids := createSpecs(sleep, busy, quick)
2382 if name == "enableCgroups" {
2383 mnt := specs.Mount{
2384 Destination: "/sys/fs/cgroup",
2385 Type: "cgroup",
2386 Options: nil,
2387 }
2388 podSpecs[0].Mounts = append(podSpecs[0].Mounts, mnt)
2389 podSpecs[1].Mounts = append(podSpecs[1].Mounts, mnt)
2390 podSpecs[2].Mounts = append(podSpecs[2].Mounts, mnt)
2391 }
2392 containers, cleanup, err := startContainers(conf, podSpecs, ids)
2393 if err != nil {
2394 t.Fatalf("error starting containers: %v", err)
2395 }
2396 defer cleanup()
2397
2398 t.Logf("Running container sleep %s", containers[0].ID)
2399 t.Logf("Running container busy %s", containers[1].ID)
2400 t.Logf("Running container quick %s", containers[2].ID)
2401
2402 // Wait for containers to start (last container should complete).
2403 if err := waitForProcessCount(containers[0], 3); err != nil {
2404 t.Errorf("failed to wait for sleep to start: %v", err)
2405 }
2406 if err := waitForProcessCount(containers[1], 1); err != nil {
2407 t.Errorf("failed to wait for bash to start: %v", err)
2408 }
2409 if ws, err := containers[2].Wait(); err != nil || ws != 0 {
2410 t.Fatalf("Container.Wait, status: %v, err: %v", ws, err)
2411 }
2412
2413 // Check events for running containers.
2414 for i, cont := range containers[:2] {
2415 ret, err := cont.Event()
2416 if err != nil {
2417 t.Errorf("Container.Event(%q): %v", cont.ID, err)
2418 }
2419 evt := ret.Event
2420 if want := "stats"; evt.Type != want {
2421 t.Errorf("Wrong event type, cid: %q, want: %s, got: %s", cont.ID, want, evt.Type)
2422 }

Callers

nothing calls this directly

Calls 14

TestConfigFunction · 0.92
SetupRootDirFunction · 0.92
PollFunction · 0.92
waitForProcessCountFunction · 0.85
createSpecsFunction · 0.70
startContainersFunction · 0.70
RunMethod · 0.65
FatalfMethod · 0.65
LogfMethod · 0.65
ErrorfMethod · 0.65
WaitMethod · 0.65
DestroyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…