Skip to content

fix race condition in Test_StartStop#1700

Merged
mdelapenya merged 2 commits intotestcontainers:mainfrom
gflarity:log_producer_race
Oct 13, 2023
Merged

fix race condition in Test_StartStop#1700
mdelapenya merged 2 commits intotestcontainers:mainfrom
gflarity:log_producer_race

Conversation

@gflarity
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes an intermittent failure in Test_StartStop caused by a race condition with the TestLogConsumer and the test itself. The root of the issue is that on certain systems (like my slow M1 Macbook) it can take a while for the producer to spin up, mean while the old producer is still producing. The cleanest way to fix this is just to update the TestLogConsumer to publish log lines and then wait for the expected lines before proceeding, in particular the ones after we call StartLogProducer for the second time.

Why is it important?

Fixes a test that can sometimes fail, particularly on slower systems.

Follow-ups

There's another potential race condition inside the Log Producer Start/Stop logic. I'll submit it as a separate PR since it didn't actually solve this race condition when I tried it first, but it seems like it's a good idea to implement still.

@gflarity gflarity requested a review from a team as a code owner September 29, 2023 21:05
@netlify
Copy link
Copy Markdown

netlify bot commented Sep 29, 2023

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 2cd8362
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/6528ee9689c9570008299f45
😎 Deploy Preview https://deploy-preview-1700--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@gflarity
Copy link
Copy Markdown
Contributor Author

FYI, all the tests seem to pass reliably on my system after this one :)

@gflarity
Copy link
Copy Markdown
Contributor Author

gflarity commented Oct 2, 2023

@mdelapenya can we try re-running these tests?

This change only just for log messages to come through before stopping the producer. I skimmed some of the error messages and they seem pretty strange:

mount: permission denied (are you root?)
Could not mount /sys/kernel/security.
AppArmor detection and --privileged mode might break.
sed: write error

I also just re-ran make all-tests locally and it passed... very strange.

mdelapenya
mdelapenya previously approved these changes Oct 2, 2023
Copy link
Copy Markdown
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

I left two comments to be addressed before the merge. They are not blockers in any case, but want to check with you first.

Said that, LGTM, thanks for this!

@mdelapenya mdelapenya self-assigned this Oct 2, 2023
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Oct 2, 2023
@gflarity
Copy link
Copy Markdown
Contributor Author

gflarity commented Oct 5, 2023

Updated commit with the requested changes. 👍

@gflarity gflarity requested a review from mdelapenya October 5, 2023 20:16
@mdelapenya mdelapenya added the hacktoberfest Pull Requests accepted for Hacktoberfest. label Oct 13, 2023
Copy link
Copy Markdown
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for this! Never had time myself to debug the flakiness in this test. Really appreciate your efforts!

@mdelapenya mdelapenya merged commit 9fa3ed4 into testcontainers:main Oct 13, 2023
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Oct 16, 2023
* main: (137 commits)
  Fix wrong module names (testcontainers#1776)
  docs: add default options to k6 module (testcontainers#1744)
  fix race condition in Test_StartStop (testcontainers#1700)
  chore(deps): bump github.com/aws/aws-sdk-go-v2/{service/s3,credentials,config} in /modules/localstack (testcontainers#1773)
  chore(deps): bump cloud.google.com/go/{datastore,bigtable,spanner} in /modules/gcloud (testcontainers#1774)
  chore(deps): bump golang.org/x/net from 0.15.0 to 0.17.0 (testcontainers#1772)
  docs: Fix typo and mention the relevant function name in doc (testcontainers#1745)
  DOCKER_HOST var typo (testcontainers#1743)
  feat: Add Cassandra module (testcontainers#1726)
  K6 module (testcontainers#1721)
  Rancher Desktop instructions (testcontainers#1724)
  chore(deps): bump github.com/shirou/gopsutil/v3 from 3.23.8 to 3.23.9 (testcontainers#1720)
  chore(deps): bump urllib3 from 2.0.5 to 2.0.6 (testcontainers#1718)
  chore(deps): bump github.com/twmb/franz-go/pkg/kadm in /modules/redpanda (testcontainers#1714)
  chore(deps): bump github.com/couchbase/gocb/v2 in /modules/couchbase (testcontainers#1704)
  chore(deps): bump github.com/neo4j/neo4j-go-driver/v5 in /modules/neo4j (testcontainers#1713)
  chore(deps): bump github.com/nats-io/nats.go in /modules/nats (testcontainers#1705)
  chore(deps): bump cloud.google.com/go/firestore from 1.12.0 to 1.13.0, google.golang.org/api from 0.142.0 to 0.143.0 and cloud.google.com/ge, google.golang.org/api from 0.142.0 to 0.143.0 and cloud.google.com/go/bigquery from 1.53.0 to 1.55 in /modules/gcloud (testcontainers#1716)
  chore(deps): bump github.com/aws/aws-sdk-go-v2/service/s3 from 1.39.0 to 1.40.0 and github.com/aws/aws-sdk-go from 1.45.15 to 1.45.19 in /modules/localstack (testcontainers#1717)
  chore: prepare for next minor development cycle (0.26.0)
  ...
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Oct 16, 2023
* main: (137 commits)
  Fix wrong module names (testcontainers#1776)
  docs: add default options to k6 module (testcontainers#1744)
  fix race condition in Test_StartStop (testcontainers#1700)
  chore(deps): bump github.com/aws/aws-sdk-go-v2/{service/s3,credentials,config} in /modules/localstack (testcontainers#1773)
  chore(deps): bump cloud.google.com/go/{datastore,bigtable,spanner} in /modules/gcloud (testcontainers#1774)
  chore(deps): bump golang.org/x/net from 0.15.0 to 0.17.0 (testcontainers#1772)
  docs: Fix typo and mention the relevant function name in doc (testcontainers#1745)
  DOCKER_HOST var typo (testcontainers#1743)
  feat: Add Cassandra module (testcontainers#1726)
  K6 module (testcontainers#1721)
  Rancher Desktop instructions (testcontainers#1724)
  chore(deps): bump github.com/shirou/gopsutil/v3 from 3.23.8 to 3.23.9 (testcontainers#1720)
  chore(deps): bump urllib3 from 2.0.5 to 2.0.6 (testcontainers#1718)
  chore(deps): bump github.com/twmb/franz-go/pkg/kadm in /modules/redpanda (testcontainers#1714)
  chore(deps): bump github.com/couchbase/gocb/v2 in /modules/couchbase (testcontainers#1704)
  chore(deps): bump github.com/neo4j/neo4j-go-driver/v5 in /modules/neo4j (testcontainers#1713)
  chore(deps): bump github.com/nats-io/nats.go in /modules/nats (testcontainers#1705)
  chore(deps): bump cloud.google.com/go/firestore from 1.12.0 to 1.13.0, google.golang.org/api from 0.142.0 to 0.143.0 and cloud.google.com/ge, google.golang.org/api from 0.142.0 to 0.143.0 and cloud.google.com/go/bigquery from 1.53.0 to 1.55 in /modules/gcloud (testcontainers#1716)
  chore(deps): bump github.com/aws/aws-sdk-go-v2/service/s3 from 1.39.0 to 1.40.0 and github.com/aws/aws-sdk-go from 1.45.15 to 1.45.19 in /modules/localstack (testcontainers#1717)
  chore: prepare for next minor development cycle (0.26.0)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Changes that do not impact the existing functionality hacktoberfest Pull Requests accepted for Hacktoberfest.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants