Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
Signed-off-by: apostasie <[email protected]>
  • Loading branch information
apostasie committed Oct 18, 2024
1 parent eef0633 commit 9f55259
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 46 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test-canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ jobs:
- name: "Run unit tests"
run: go test -v ./pkg/...
- name: "Run integration tests"
run: docker run -t --rm --privileged test-integration ./hack/test-integration.sh
run: docker run -t --rm --privileged test-integration ./hack/test-integration.sh -test.only-flaky=false
- name: "Run integration tests (flaky)"
run: docker run -t --rm --privileged test-integration ./hack/test-integration.sh -test.only-flaky
run: docker run -t --rm --privileged test-integration ./hack/test-integration.sh -test.only-flaky=true

windows:
timeout-minutes: 30
Expand Down Expand Up @@ -94,6 +94,6 @@ jobs:
ctrdVersion: ${{ env.CONTAINERD_VERSION }}
run: powershell hack/configure-windows-ci.ps1
- name: "Run integration tests"
run: ./hack/test-integration.sh
run: ./hack/test-integration.sh -test.only-flaky=false
- name: "Run integration tests (flaky)"
run: ./hack/test-integration.sh -test.only-flaky
run: ./hack/test-integration.sh -test.only-flaky=true
8 changes: 3 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,9 @@ jobs:
docker run --privileged --rm tonistiigi/binfmt --install linux/arm64
docker run --privileged --rm tonistiigi/binfmt --install linux/arm/v7
- name: "Run integration tests"
run: |
docker run -t --rm --privileged test-integration ./hack/test-integration.sh -test.only-flaky=false
run: docker run -t --rm --privileged test-integration ./hack/test-integration.sh -test.only-flaky=false
- name: "Run integration tests (flaky)"
run: |
docker run -t --rm --privileged test-integration ./hack/test-integration.sh -test.only-flaky=true
run: docker run -t --rm --privileged test-integration ./hack/test-integration.sh -test.only-flaky=true

test-integration-ipv6:
timeout-minutes: 60
Expand Down Expand Up @@ -287,7 +285,7 @@ jobs:
- name: "Ensure that the IPv6 integration test suite is compatible with Docker"
run: ./hack/test-integration.sh -test.target=docker -test.only-ipv6
- name: "Ensure that the integration test suite is compatible with Docker (flaky only)"
run: /hack/test-integration.sh -test.target=docker -test.only-flaky
run: ./hack/test-integration.sh -test.target=docker -test.only-flaky

test-integration-windows:
timeout-minutes: 30
Expand Down
2 changes: 1 addition & 1 deletion docs/testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ explicitly allow it (with a call to `t.Parallel()`).

```bash
docker build -t test-integration --target test-integration .
docker run -t --rm --privileged test-integration ./hack/test-integration.sh
docker run -t --rm --privileged test-integration
```

### Principles
Expand Down
2 changes: 0 additions & 2 deletions hack/test-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ args=(--format=testname --jsonfile /tmp/test-integration.log --packages="$root"/
if [ "$#" == 0 ]; then
"$root"/test-integration.sh -test.only-flaky=false
"$root"/test-integration.sh -test.only-flaky=true
"$root"/test-integration.sh -test.only-ipv6
"$root"/test-integration.sh -test.only-kube
exit
fi

Expand Down
58 changes: 31 additions & 27 deletions pkg/testutil/nerdtest/registry/cesanta.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,38 @@ func (cc *CesantaConfig) Save(path string) error {
return err
}

// FIXME: this is a copy of the utility method EnsureContainerStarted
// We cannot reference it (circular dep), so the copy.
// To be fixed later when we will be done migrating test helpers to the new framework and we can split them
// in meaningful subpackages.

func ensureContainerStarted(helpers test.Helpers, con string) {
const maxRetry = 5
const sleep = time.Second
success := false
for i := 0; i < maxRetry && !success; i++ {
time.Sleep(sleep)
count := i
cmd := helpers.Command("container", "inspect", con)
cmd.Run(&test.Expected{
Output: func(stdout string, info string, t *testing.T) {
var dc []dockercompat.Container
err := json.Unmarshal([]byte(stdout), &dc)
assert.NilError(t, err, "Unable to unmarshal output\n"+info)
assert.Equal(t, 1, len(dc), "Unexpectedly got multiple results\n"+info)
if dc[0].State.Running {
success = true
return
}
if count == maxRetry-1 {
// FIXME: there is currently no simple way to capture stderr
// Sometimes, it is convenient for debugging, like here
// Here we cheat with unbuffer which will bundle stderr and stdout together
// This is just bad
t.Error(helpers.Err("logs", con))
t.Fatalf("container %s still not running after %d retries", con, count)
}
},
})
started := false
for i := 0; i < 5 && !started; i++ {
helpers.Command("container", "inspect", con).
Run(&test.Expected{
ExitCode: -2,
Output: func(stdout string, info string, t *testing.T) {
var dc []dockercompat.Container
err := json.Unmarshal([]byte(stdout), &dc)
if err != nil || len(dc) == 0 {
return
}
assert.Equal(t, len(dc), 1, "Unexpectedly got multiple results\n"+info)
started = dc[0].State.Running
},
})
time.Sleep(time.Second)
}

if !started {
ins := helpers.Capture("container", "inspect", con)
lgs := helpers.Capture("logs", con)
ps := helpers.Capture("ps", "-a")
helpers.T().Log(ins)
helpers.T().Log(lgs)
helpers.T().Log(ps)
helpers.T().Fatalf("container %s still not running after %d retries", con, 5)
}
}

Expand Down
7 changes: 0 additions & 7 deletions pkg/testutil/nerdtest/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,10 @@ func EnsureContainerStarted(helpers test.Helpers, con string) {
}

if !started {
var dckr string
helpers.Custom("sudo", "journalctl", "-u", "docker", "--no-pager").Run(&test.Expected{
Output: func(stdout string, info string, t *testing.T) {
dckr = stdout
},
})
ins := helpers.Capture("container", "inspect", con)
lgs := helpers.Capture("logs", con)
ps := helpers.Capture("ps", "-a")
helpers.T().Log(ins)
helpers.T().Log(dckr)
helpers.T().Log(lgs)
helpers.T().Log(ps)
helpers.T().Fatalf("container %s still not running after %d retries", con, maxRetry)
Expand Down

0 comments on commit 9f55259

Please sign in to comment.