Integration Tests: add MainThreadMonitor to ensure main thread is not blocked#2463
Merged
Conversation
NachoSoto
commented
May 1, 2023
Contributor
Author
There was a problem hiding this comment.
I couldn't make this a XCTFail because it wouldn't be reported if the main thread is completely blocked.
2e64d23 to
f779252
Compare
tonidero
approved these changes
May 4, 2023
Contributor
There was a problem hiding this comment.
This is a cool idea. Any thoughts on using this in other integration tests (not only backend integration tests)?
Contributor
Author
There was a problem hiding this comment.
This is the base class for all integration tests.
f779252 to
aee4f96
Compare
NachoSoto
added a commit
that referenced
this pull request
May 17, 2023
See #2463. If you're actively debugging and interrupt the main thread, it'll end up asserting, which isn't very convenient. Copied the logic from https://stackoverflow.com/a/33177600/401024. It's not the safest code, but this only runs in tests.
NachoSoto
added a commit
that referenced
this pull request
May 18, 2023
) See #2463. If you're actively debugging and interrupt the main thread, it'll end up asserting, which isn't very convenient. Copied the logic from https://stackoverflow.com/a/33177600/401024. It's not the safest code, but this only runs in tests.
NachoSoto
added a commit
that referenced
this pull request
May 25, 2023
… not blocked (#2463) We've had a few reports of deadlocks (#2412, #2375). This might have not detected them, but it would detect future issues, as well as busy operations running on the main thread. Example: 
NachoSoto
added a commit
that referenced
this pull request
May 25, 2023
) See #2463. If you're actively debugging and interrupt the main thread, it'll end up asserting, which isn't very convenient. Copied the logic from https://stackoverflow.com/a/33177600/401024. It's not the safest code, but this only runs in tests.
This was referenced May 31, 2023
NachoSoto
added a commit
that referenced
this pull request
Jul 14, 2023
This was introduced in #2463, as a way to verify the SDK didn't have any deadlocks (#2412, #2375). However, it has caused more trouble than it's worth, because that loop keeps the main thread busy. This solution proposed by @aboedo makes it only check every 3 seconds. If there is a deadlock, it would still detect it. But after it's verified there is no deadlock, it won't check again until that interval has elapsed again. This makes it so that on a test that takes 6 seconds to run, we only execute this code 2 times instead of... a lot.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We've had a few reports of deadlocks (#2412, #2375). This might have not detected them, but it would detect future issues, as well as busy operations running on the main thread.
Example:
