From 0582099de61f39876e08e930fad07fbc4051fe53 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 15 Feb 2018 11:39:21 -0800 Subject: [PATCH] integration/TestUpdateCPUQUota: use exec An implementation of exec in TestUpdateCPUQUota had a few issues, including resource leaking and calling both ContainerExecAttach and ContainerExecRun. The last one makes the test flaky: update_linux_test.go:136: expected cgroup value 20000, got: Error: Exec command f923baf709525f6b38f6511126addc5d9bb88fb477eeca1c22440551090fa2bb is already running Fix by using the integration/internal/exec package. While at it, use require/assert to further improve code readability. Signed-off-by: Kir Kolyshkin Upstream-commit: 8a7d6143fca69623e2f5d409328c97603843ccb6 Component: engine --- .../container/update_linux_test.go | 54 +++---------------- 1 file changed, 8 insertions(+), 46 deletions(-) diff --git a/components/engine/integration/container/update_linux_test.go b/components/engine/integration/container/update_linux_test.go index ef9397c209..e13ac60c88 100644 --- a/components/engine/integration/container/update_linux_test.go +++ b/components/engine/integration/container/update_linux_test.go @@ -88,55 +88,17 @@ func TestUpdateCPUQUota(t *testing.T) { } inspect, err := client.ContainerInspect(ctx, cID) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) + assert.Equal(t, test.update, inspect.HostConfig.CPUQuota) - if inspect.HostConfig.CPUQuota != test.update { - t.Fatalf("quota not updated in the API, expected %d, got: %d", test.update, inspect.HostConfig.CPUQuota) - } + res, err := container.Exec(ctx, client, cID, + []string{"/bin/cat", "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"}) + require.NoError(t, err) + require.Empty(t, res.Stderr()) + require.Equal(t, 0, res.ExitCode) - execCreate, err := client.ContainerExecCreate(ctx, cID, types.ExecConfig{ - Cmd: []string{"/bin/cat", "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"}, - AttachStdout: true, - AttachStderr: true, - }) - if err != nil { - t.Fatal(err) - } - - attach, err := client.ContainerExecAttach(ctx, execCreate.ID, types.ExecStartCheck{}) - if err != nil { - t.Fatal(err) - } - - if err := client.ContainerExecStart(ctx, execCreate.ID, types.ExecStartCheck{}); err != nil { - t.Fatal(err) - } - - buf := bytes.NewBuffer(nil) - ready := make(chan error) - - go func() { - _, err := stdcopy.StdCopy(buf, buf, attach.Reader) - ready <- err - }() - - select { - case <-time.After(60 * time.Second): - t.Fatal("timeout waiting for exec to complete") - case err := <-ready: - if err != nil { - t.Fatal(err) - } - } - - actual := strings.TrimSpace(buf.String()) - if actual != strconv.Itoa(int(test.update)) { - t.Fatalf("expected cgroup value %d, got: %s", test.update, actual) - } + assert.Equal(t, strconv.FormatInt(test.update, 10), strings.TrimSpace(res.Stdout())) } - } func getContainerSysFSValue(ctx context.Context, client client.APIClient, cID string, path string) (string, error) {