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

test:Ensure worker thread waits for test assertion #1103

Merged
merged 1 commit into from
Jul 8, 2020

Conversation

marcotc
Copy link
Member

@marcotc marcotc commented Jul 8, 2020

While testing Datadog::Workers::Async::Thread#running?, we could encounter a race condition where we start a background task but that task finishes before we can check the result of #running?:

context 'when started' do
before do
worker.perform
try_wait_until { worker.running? }
end
after { worker.terminate }
it { is_expected.to be true }
end

This happens because the task we schedule to run is empty, finishing very quickly.

This PR changes the background task to wait for some time, so we can assert on it. The thread won't hold our test suite back because we call worker#terminal, which forcefully terminates the thread.

@marcotc marcotc added the dev/testing Involves testing processes (e.g. RSpec) label Jul 8, 2020
@marcotc marcotc requested review from ericmustin and a team July 8, 2020 19:47
@marcotc marcotc self-assigned this Jul 8, 2020
Copy link
Contributor

@ericmustin ericmustin left a comment

Choose a reason for hiding this comment

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

Good catch, 👍 lgtm

@marcotc marcotc merged commit 61ef72b into master Jul 8, 2020
@marcotc marcotc deleted the test/fix-flaky-async-test branch July 8, 2020 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev/testing Involves testing processes (e.g. RSpec)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants