Skip to content

TestThread does not synchronize properly #1067

Closed

Description

@lostmsu

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)

Activity

  1. added a commit that references this issue on Mar 6, 2020
    925c166
  2. ddneilson commented on Mar 6, 2020

    @ddneilson

    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.

  3. lostmsu commented on Mar 6, 2020

    @lostmsu
    MemberAuthor

    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.

  4. ddneilson commented on Mar 9, 2020

    @ddneilson

    @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.

  5. added a commit that references this issue on Jun 29, 2020
    608d2cc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions