Skip to content

Wait longer for a stable goroutine count in tests#49017

Merged
thaJeztah merged 2 commits intomoby:masterfrom
robmry:stable_goroutine_count
Dec 3, 2024
Merged

Wait longer for a stable goroutine count in tests#49017
thaJeztah merged 2 commits intomoby:masterfrom
robmry:stable_goroutine_count

Conversation

@robmry
Copy link
Copy Markdown
Contributor

@robmry robmry commented Dec 2, 2024

- What I did

Test 'TestDockerCLIRunSuite/TestRunAttachFailedNoLeak' does this ...

  • start a container that exits immediately, its comment says:
    • "Run a dummy container to ensure all goroutines are up and running before we get a count"
  • wait for the number of goroutines to be stable for 400ms, and remember that number
  • start a container
  • start another container, expecting it to fail with a port-mapping clash
  • stop the running container
  • wait for up to 30s for the number of goroutines to fall back to the remembered number.

In a CI run - hacking in some debug to count goroutines once a second, before waiting for the number to stablilise for 400ms, showed that the initial (dummy) container run had no immediate effect. But, three more goroutines appeared within a few seconds. For example:

=== RUN   TestDockerCLIRunSuite/TestRunAttachFailedNoLeak
  docker_cli_run_test.go:3822: goroutines before container run: 47 err <nil>
  docker_cli_run_test.go:3830: goroutines after container run: 47 i 0 err <nil>
  docker_cli_run_test.go:3830: goroutines after container run: 48 i 1 err <nil>
  docker_cli_run_test.go:3830: goroutines after container run: 48 i 2 err <nil>
  docker_cli_run_test.go:3830: goroutines after container run: 48 i 3 err <nil>
  docker_cli_run_test.go:3830: goroutines after container run: 48 i 4 err <nil>
  docker_cli_run_test.go:3830: goroutines after container run: 50 i 5 err <nil>
  docker_cli_run_test.go:3830: goroutines after container run: 50 i 6 err <nil>
  docker_cli_run_test.go:3830: goroutines after container run: 50 i 7 err <nil>
  docker_cli_run_test.go:3830: goroutines after container run: 50 i 8 err <nil>
  docker_cli_run_test.go:3830: goroutines after container run: 50 i 9 err <nil>

That means a delay while running the rest of the test risks finding the extra goroutines that are going to start anyway and not go away (regardless of whether more containers are started).

- How I did it

So - wait for the goroutine count to be stable for 7s, rather than 400ms.

- How to verify it

CI

- Description for the changelog

n/a

- A picture of a cute animal (not mandatory but encouraged)

@robmry robmry self-assigned this Dec 2, 2024
@robmry robmry added kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. area/testing labels Dec 2, 2024
@robmry robmry added this to the 28.0.0 milestone Dec 2, 2024
@robmry robmry marked this pull request as ready for review December 2, 2024 18:39
Test 'TestDockerCLIRunSuite/TestRunAttachFailedNoLeak' does this ...

- start a container that exits immediately, its comment says:
  - "Run a dummy container to ensure all goroutines are up and running
    before we get a count"
- wait for the number of goroutines to be stable for 400ms, and remember
  that number
- start a container
- start another container, expecting it to fail with a port-mapping clash
- stop the running container
- wait for up to 30s for the number of goroutines to fall back to the
  remembered number.

In a CI run - hacking in some debug to count goroutines once a second,
before waiting for the number to stablilise for 400ms, showed that the
initial (dummy) container run had no immediate effect. But, three more
goroutines appeared within a few seconds. For example:

  === RUN   TestDockerCLIRunSuite/TestRunAttachFailedNoLeak
    docker_cli_run_test.go:3822: goroutines before container run: 47 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 47 i 0 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 48 i 1 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 48 i 2 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 48 i 3 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 48 i 4 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 50 i 5 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 50 i 6 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 50 i 7 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 50 i 8 err <nil>
    docker_cli_run_test.go:3830: goroutines after container run: 50 i 9 err <nil>

That means a delay while running the rest of the test risks finding the
extra goroutines that are going to start anyway and not go away (regardless
of whether more containers are started).

So - wait for the goroutine count to be stable for 7s, rather than 400ms.

Signed-off-by: Rob Murray <[email protected]>
@robmry robmry force-pushed the stable_goroutine_count branch from a94962f to d75394b Compare December 2, 2024 18:49
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah thaJeztah merged commit efa041a into moby:master Dec 3, 2024
@robmry robmry deleted the stable_goroutine_count branch December 3, 2024 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/testing kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. status/4-merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants