Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TestThread does not synchronize properly #1067

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

Closed
lostmsu opened this issue Feb 27, 2020 · 3 comments · Fixed by #1070
Closed

TestThread does not synchronize properly #1067

lostmsu opened this issue Feb 27, 2020 · 3 comments · Fixed by #1070

Comments

@lostmsu
Copy link
Member

lostmsu commented Feb 27, 2020

PyScopeTest.TestThread does not properly synchronize access to res and th_cnt variables.

A lock needs to be added to ensure update calls are serialized.

We should increase the number of threads to make the issue stand out if regressed.

For more details see #1022 (comment)

@ddneilson
Copy link

ddneilson commented Mar 6, 2020

Have you considered a race condition at the fixture level? The PyScopeTest is not thread safe, in general. It is set up to have a single private PyScope at the class level that is created/disposed during SetUp/Dispose, and referenced in each test. However, tests within the fixture can, and do, run in parallel.
So, ps can be modified mid-test for any test in this fixture. TestThread is one of the longer tests in the fixture, so one might expect it to be more vulnerable to the data races expected of a shared state variable being replaced.
Have you considered setting either setting NonParallelizable on all of the tests in the fixture, or making the fixture itself threadsafe by making each test create its own, locally scoped, PyScope?

edit: Correction, TestThread is the only test in this fixture that exits & reenters the GIL. So, it is the only one that can possibly see ps being mutated mid-test.

@lostmsu
Copy link
Member Author

lostmsu commented Mar 6, 2020

However, tests within the fixture can, and do, run in parallel.

@ddneilson , can you point to the relevant documentation. AFAIK, by default NUnit runs all tests sequentially.

From https://github.com/nunit/docs/wiki/Framework-Parallel-Test-Execution :

By default, no parallel execution takes place. Attributes are used to indicate which tests may run in parallel and how they relate to other tests.

@ddneilson
Copy link

@lostmsu Interesting. We had seen this test fail as well, and traced our problem down to the fixture not being thread-safe; we were seeing the shared PyScope being mutated. Didn't realize that the tests were intended to be run in serial.

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 a pull request may close this issue.

2 participants