-
-
Notifications
You must be signed in to change notification settings - Fork 204
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
Fix flakey async test thread error #849
Comments
Same same:
|
|
From poking at this in #915:
|
So, I'm not sure if this the same thing or not, but: I have a suite of tests using shared examples to test various combinations of invalid attributes posted to an endpoint. If I write really minimal, fast examples like: it 'returns an invalid response' do
post holdings_tasks_url, params: { holdings_task: invalid_attributes }
expect(response).not_to be_successful
end — then each test passes individually, but in a suite, all tests after the first one or two fail with When I put some breakpoints in trying to figure out where the connection was being closed:
Likewise, if I write a more complicated example like: it 'does not create a task or schedule a job' do
expect(GoodJob::Batch).not_to receive(:enqueue)
job_classes.each do |jc|
expect(jc).not_to receive(:perform)
end
expect do
post holdings_tasks_url, params: { holdings_task: invalid_attributes }
end.not_to change(HoldingsTask, :count)
expect(response).not_to be_successful
expect(GoodJob::BatchRecord.exists?).to eq(false)
end — which takes, like, 1-2 seconds to run — the suite passes. My hypothesis is that I'm seeing something like:
— but I don't really know. (Anyway, my workaround is just to put all my assertions in one fat, slow example.) |
(Note BTW that no jobs are run in the course of these tests -- in fact we're asserting that they're not. 🙂) |
As a more general workaround, this seems to work: after do
GoodJob::Notifier.instances.each(&:shutdown)
end |
@dmolesUC glad you found a workaround 👍 you can also use Are you intentionally running the adapter in I really appreciate your detailed hypothesis of what's happening. That's super helpful! I admit I don't quite understand the complete lifecycle of the Active Record connections and pool 😅 |
@bensheldon I am using async mode intentionally for this particular group of tests -- wanting to make sure we haven't accidentally baked in any assumptions about things happening serially or in a certain thread. (The price is a lot of shenanigans involving callbacks and rescue handlers and The workaround proved not to be reliable, unfortunately, but I think I finally pinned down my underlying problem, and found a different workaround: DatabaseCleaner/database_cleaner-active_record#86 |
The text was updated successfully, but these errors were encountered: