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

Wait until race condition fix #721

Merged
merged 4 commits into from
Feb 22, 2020

Conversation

AnthonyMDev
Copy link
Contributor

This fixes issue #509. There was a race condition that resulted in the main RunLoop locking up, halting all tests indefinitely.

This occurred sometimes when done() was called asynchronously on a background thread.
We are checking if the result for the test is complete (ie. done() has been called) on line 258, then running the RunLoop. If the background thread marks the test complete between the check on line 258 and the running of the RunLoop on line 260, it stops the RunLoop prior to the RunLoop being started instead of after. This means the RunLoop is never stopped and the test hangs forever. This ensures that the completion of the test and the stopping of the RunLoop is called serially on the main thread, which prevents the race condition.

Unit test is included to verify the fix.

Checklist - While not every PR needs it, new features should consider this list:

  • Does this have tests?
  • Does this have documentation?
  • Does this break the public API (Requires major version bump)?
  • Is this a new feature (Requires minor version bump)?

AnthonyMDev and others added 2 commits January 3, 2020 11:45
Merge Upstream master
This fixes a race condition that resulted in the main RunLoop locking up, halting all tests indefinitely.

This occured sometimes when `done()` was called asynchronously on a background thread.
We are checking if the result for the test is complete (ie. `done()` has been called) on line 258, then running the `RunLoop`. If the background thread marks the test complete between the check on line 258 and the running of the `RunLoop` on line 260, it stops the `RunLoop` **prior** to the `RunLoop` being started instead of after. This means the `RunLoop` is never stopped and the test hangs forever. This ensures that the completion of the test and the stopping of the `RunLoop` is called serially on the main thread, which prevents the race condition.

Unit test is included to verify the fix.
Tests/NimbleTests/AsynchronousTest.swift Outdated Show resolved Hide resolved
Tests/NimbleTests/AsynchronousTest.swift Outdated Show resolved Hide resolved
Tests/NimbleTests/AsynchronousTest.swift Outdated Show resolved Hide resolved
Sources/Nimble/Utils/Await.swift Outdated Show resolved Hide resolved
Copy link
Contributor

@abbeycode abbeycode left a comment

Choose a reason for hiding this comment

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

This looks good to me, but I'm not in a position to merge this. I do have a question, though: do you know why XCTestExpectation doesn't work in your unit test? I wrote a simpler implementation that does fail without your patch, but I couldn't get it to succeed with your patch. It's not entirely surprising as what you're fixing is essentially a wholesale replacement for it, but it seems strange.

Copy link
Member

@ikesyo ikesyo left a comment

Choose a reason for hiding this comment

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

Great appreciate for the fix and the contribution!

Could you please fix the build failure on Linux.

Tests/NimbleTests/AsynchronousTest.swift Show resolved Hide resolved
@AnthonyMDev AnthonyMDev requested a review from ikesyo January 20, 2020 22:32
@dipikasrivastava16
Copy link

Hey Guys.. I am facing the "main loop unresponsive" issue and hence keen to know, when this PR is going to be merged.. Currently I have applied the fix locally to my machine but would be helpful if this PR goes in to keep things dynamic.

@AnthonyMDev
Copy link
Contributor Author

@ikesyo would you be able to approve and merge this now?

Copy link
Member

@ikesyo ikesyo left a comment

Choose a reason for hiding this comment

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

LGTM 👍

I'm sorry it took so long to land this 💦

@ikesyo ikesyo merged commit 8f78f2b into Quick:master Feb 22, 2020
@paulz
Copy link

paulz commented Mar 15, 2020

Could someone please make a minor release with this fix?
Our tests are hanging at random for a very long time which feels frustrating.

@ikesyo
Copy link
Member

ikesyo commented Mar 28, 2020

I'm sorry for the delay, v8.0.6 has been released including the fix 🚀

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.

6 participants