Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integration: Remove dangling container and container names #19

Merged
merged 5 commits into from
Sep 7, 2023

Conversation

pgporada
Copy link
Member

@pgporada pgporada commented Sep 6, 2023

Fixes a flaky minio error when running go test -v ./... in rapid succession due to a bucket already existing.

$ go test -v ./...
minio is up
=== RUN   TestIntegration
    integration_test.go:141: operation error S3: CreateBucket, https response error StatusCode: 409, RequestID: 1782341B6096C63C, HostID: dd9025bab4ad464b049177c95eb6ebf374d3b3fd1af9251148b658df7ac2e3e8, BucketAlreadyOwnedByYou: 
--- FAIL: TestIntegration (0.00s)

integration_test.go Outdated Show resolved Hide resolved
@pgporada pgporada changed the title integration: Check if s3 bucket exists before creating it integration: Remove dangling container and container names Sep 6, 2023
@jsha
Copy link
Contributor

jsha commented Sep 6, 2023

Thanks for the updates! I think we can use podman stop ctile_integration_test_minio instead of relying on podman ps --filter, which seems like it might have some flaky cases. Note that we don't need to check first if the container is still running. We can stop it unconditionally and then ignore errors if it already didn't exist.

Also when we do podman run, we can pass --rm so the container gets cleaned up on exit and we can use the name again.

@pgporada
Copy link
Member Author

pgporada commented Sep 7, 2023

Thanks for the updates! I think we can use podman stop ctile_integration_test_minio instead of relying on podman ps --filter, which seems like it might have some flaky cases. Note that we don't need to check first if the container is still running. We can stop it unconditionally and then ignore errors if it already didn't exist.

Also when we do podman run, we can pass --rm so the container gets cleaned up on exit and we can use the name again.

I simplified the container startup and tear down by having TestMain run --rm --detach which will remove the container name at exit time and run the container in the background avoiding some go process waiting code. We'll still get an error if the container failed to start and the test will panic.

There's a case where a dangling container name could exist from an operator that I handled. Consider the following:

$ podman run -d --name ctile_integration_test_minio minio/minio server /data
389b91d79bb82b499c92a7f38082f6b30c8fd40224d30f06b75f8f51bf376d14

$ podman ps
CONTAINER ID  IMAGE                       COMMAND       CREATED        STATUS            PORTS       NAMES
389b91d79bb8  quay.io/minio/minio:latest  server /data  3 seconds ago  Up 4 seconds ago              ctile_integration_test_minio

# Shut down the container, but the name will be left dangling.
$ podman stop 389
389

# No container running, which is great
$ podman ps
CONTAINER ID  IMAGE       COMMAND     CREATED     STATUS      PORTS       NAMES

# The name is leftover and will cause an error if you try to start the container again.
$ podman ps -a
CONTAINER ID  IMAGE                       COMMAND       CREATED         STATUS                     PORTS       NAMES
389b91d79bb8  quay.io/minio/minio:latest  server /data  38 seconds ago  Exited (0) 16 seconds ago              ctile_integration_test_minio

$ podman run -d --name ctile_integration_test_minio minio/minio server /data
Error: error creating container storage: the container name "ctile_integration_test_minio" is already in use by "389b91d79bb82b499c92a7f38082f6b30c8fd40224d30f06b75f8f51bf376d14". You have to remove that container to be able to reuse that name.: that name is already in use

Copy link
Contributor

@jsha jsha left a comment

Choose a reason for hiding this comment

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

Excellent, and good catch with removing the container as well as stopping it.

One more thing: The same function should be responsible for creating the resource and for cleaning it up. Looking back, we don't really need a TestMain, since all of the testing that relies on minio happens in a single test function. Let's move the setup code from TestMain into the top of TestIntegration, and delete TestMain entirely.

@pgporada
Copy link
Member Author

pgporada commented Sep 7, 2023

Sure, can do.

@pgporada pgporada requested a review from jsha September 7, 2023 18:52
integration_test.go Outdated Show resolved Hide resolved
integration_test.go Outdated Show resolved Hide resolved
@jsha jsha merged commit 64a8481 into main Sep 7, 2023
2 checks passed
@jsha jsha deleted the fix-flaky-minio-test branch September 7, 2023 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants