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

Parallelization causes test cases to stop respecting fixture's apartment state #2388

Closed
jnm2 opened this issue Aug 28, 2017 · 6 comments · Fixed by #2537
Closed

Parallelization causes test cases to stop respecting fixture's apartment state #2388

jnm2 opened this issue Aug 28, 2017 · 6 comments · Fixed by #2537

Comments

@jnm2
Copy link
Contributor

jnm2 commented Aug 28, 2017

Affected versions: 3.7.0–3.8.0

Fails:

[assembly: Parallelizable(ParallelScope.Children)]

[Apartment(ApartmentState.STA)]
public class StaFixture
{
    [TestCase(1)]
    [TestCase(2)]
    public void Test_cases_should_inherit_apartment_from_fixture(int n)
    {
        Assert.That(Thread.CurrentThread.GetApartmentState(), Is.EqualTo(ApartmentState.STA));
    }
}

Also fails if [Parallelizable(ParallelScope.Children)] is specified on the fixture or the method.

Does not fail if nothing is parallelizable.

Does not fail if the apartment is specified on the method:

[assembly: Parallelizable(ParallelScope.Children)]

public class StaFixture
{
    [TestCase(1)]
    [TestCase(2)]
    [Apartment(ApartmentState.STA)]
    public void Test_cases_should_inherit_apartment_from_fixture(int n)
    {
        Assert.That(Thread.CurrentThread.GetApartmentState(), Is.EqualTo(ApartmentState.STA));
    }
}

Does not fail for non-parameterized test methods.

@jnm2
Copy link
Contributor Author

jnm2 commented Aug 28, 2017

@CharliePoole, you're the most knowledgeable here. Are you in a position to take this on?

@CharliePoole
Copy link
Member

It's pretty obvious where it is happening. Essentially, apartment state is similar to parallelism in that it is determined by both the test itself and the containing tests from which it "inherits"* the behavior.

I'm tied up for the moment but I put my name on it to get to in a week or so.

========

*I put "inheritance" in quotes because it has nothing to do with either test object or attribute inheritance. One of those overloaded terms! 😸

@CharliePoole
Copy link
Member

I'm going away on a family trip for a couple of weeks so I'm taking my name off this to free it up for somebody else to work on.

@CharliePoole
Copy link
Member

I'll add this to the PR I'm working on.

CharliePoole added a commit that referenced this issue Oct 30, 2017
@CharliePoole CharliePoole removed their assignment Oct 31, 2017
@rprouse rprouse modified the milestones: 3.8.2, 3.9 Nov 3, 2017
@rprouse
Copy link
Member

rprouse commented Nov 5, 2017

I tested with 3.9.0-dev-04639 and this has not been fixed with our recent parallel fixes.

@CharliePoole
Copy link
Member

Right, that's why I threw it back in the pond. It's not exactly a parallelization error, or not in the same way as the other errors are due to parallelization. It's simply that the ParallelWorkItemDispatcher, when dispatching the suite that wraps the individual cases looses the information that everything should be run in parallel. I think there's another issue that relates to this, which someone is working on. Can't find it at the moment though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants