-
Notifications
You must be signed in to change notification settings - Fork 259
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
TestContext not Thread Safe #386
Comments
@jchesshir , thanks for bringing this issue up. I agree that currently TestContext is not Thread Safe, & can have repercussions in case of method level parallelism. Also in case you do get a chance to work on it, please feel free to pick it up 😃 |
I encountered this issue. TestContext is not thread safe. Please escalate this one. The issue can be replicated easily by running the following test methods in parallel with execution scope at MethodLevel. After the execution, in the output of one or many test methods you can see its mixed up showing output from the many methods.
|
@saparia If I switch Console.Writeline to TestContext.Writeline the example works for me
|
I think the issue raised in this ticket was fixed as a side-effect of some other fix. I cannot reproduce the issue on newer version of MSTest but I can repro on old versions. I will move forward by closing this issue. Please feel free to ping if you are still facing the issue. |
Description
The concept of the TestContext as a property of a class is not thread safe. This is especially true if it is made static, but is even true if it is class instance specific. It needs to be made an optional parameter to the test level functions to make it so. This bug is related to #385. Although they address slightly different problems, if you had to choose between the two to fix, I think this way of addressing the threading issues would be cleaner.
Steps to reproduce
Add the .cs file in the attached zip into a MSTest 1.3.0-beta2 project with MethodLevel scope parallelize functionality activated.
ParallelTestContextBug.zip
Expected behavior
The Test Initialize and Test Cleanup functions, at the very least, should be able to take a TestContext parameter. For Data Driven tests with attached data sources, the Test Method functions should also get one, as the DataRow property in a Class level TestContext variable is bound to get jumbled between the functions. If you get to the point of parallelizing a data driven function's test cases, this separation will become even more critical.
Actual behavior
Because the TestContext object is shared at the class level, the output from the two test functions and their respective Test Initialize and Cleanup functions gets jumbled.
The text was updated successfully, but these errors were encountered: