-
Notifications
You must be signed in to change notification settings - Fork 751
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
Random test result using nunit + parallel execution #884
Comments
Hello, I see the same problem. When I set When I set When I set I use [assembly: I did not see this behaviour with the last preview nuget packet of 2.2. Does anybody have an idea where this could come from? |
@gasparnagy Do you have an idea? |
@SabotageAndi No... @elias551 @Peter-B- Could you please try to place the symbol file (.pdb) next to the techtalk.specflow.dll in order to see a line number for the failure? The sybbol files for v2.2 can be downloaded from here. |
@gasparnagy the dll I got from nuget do not match your pdbs, I have the same stack trace. I retried with the last source in the repo, I still have null reference exception but not at the same place:
The behavior is quite the same, the first batch runs fine. Then the start of some of the next fail. It seems like the method ContextManager.Init disposes the current instance if it is not null. But another thread may dispose it before on a race condition. Adding a lock solves the problem in my case:
Even if it solves the same problem, the root cause is not the same because the stack traces are very different, so I can't say if it is a good solution. |
@elias551 thx for the info. And if you put the lock into the context manager, do you still get the other error or with this "fix" the other error also goes away? |
@elias551 one more thing: how does the test output look like (where is shows the executed steps and the called step definition methods)? Do you see things like |
Hello I copied the pdbs and I get NullReferenceExceptions with differen stacks:
and
My steps all look like:
I have no Does that help you? |
@gasparnagy |
@gasparnagy @Peter-B- my bad, my project was still using 2.1.0, so I updraded to 2.2.0, and the stack traces are now the same as Peter's. |
@Peter-B- @elias551 thx. could you make a comment on my question related to the test output? #884 (comment) |
@gasparnagy Sorry, I didn't read properly. When i switch to parallel execution, I don't see the outputs any more. Sometimes I see my own |
:( my suspicion is that SpecFlow does not recognize properly that NUnit runs the tests in parallel and it does not initialize the necessary thread safe infrastructures. (e.g. it creates a Normally, parallel execution is detected if the test runner initialized by the test (at I will think how to test this... |
Indeed logging is strange, only the first running test has the output and it contains the traces of every test:
The first failing test has the following line in logging: |
@gasparnagy Thanks a lot for your effort. I hope I find some time to take a deeper into this issue later this week. Maybe I can dig out something that might help you. |
@elias551 @Peter-B- There are some hints in the related issues (#869, #902, #913) that would be worth trying.
Could you please check these? |
I ran the tests a few times with the attribute, indeed there is no more errors! I still have all of the logs in the first test though |
My nunit version is 3.7.1 btw |
@elias551 and are they still run parallel? Because the documentation of that attribute does not say much about what it is good for actually. |
@gasparnagy Downgrading to NUnit 3.6.1 indeed solved the problem. I injected |
I updated to NUnit 3.8.1 today. That fixed the issue for me. @elias551 If updating NUnit solves the problem for you also, I think we can close the issue. |
@gasparnagy I have checked your assumption from #884 (comment) and it's correct. When running tests from the same fixture in parallel, NUnit creates one instance of the fixture class, calls There is also an issue on SpecFlow side -
I have also checked NUnit 3.8.1 and the issue is still reproducible.
|
@aliaksandrbasau @gasparnagy can you please let me know if this issue is still open or has been resolved as part of any specflow release. |
@aliaksandrbasau can you please let me know if the work around you have provided is available in any release version of NUnit. |
@gasparnagy will we also face same issue if we use SPECRUN as an unit test provider instead of NUNIT. |
@RajaAutomation I have checked the latest stable release of SpecFlow (2.4.1) and both issues I mentioned earlier ( |
@aliaksandrbasau Thank you for the quick response. Currently we are using specflow 2.3.2 and the issue is occurring. |
@RajaAutomation If you are talking about the original issue (random test failures when tests are being executed in parallel), than it's not an issue with your hooks setup nor expected behavior of specflow but a defect in specflow. |
@aliaksandrbasau .... I have multiple feature files and each feature file has multiple scenario outlines and each scenario outline has multiple examples. When i use Parallelizable(ParallelScope.Fixtures)], one example of scenario outline 1 of feature A runs in parallel with another example of scenario outline 1 of feature B. Feature A --> Scenario Outline 1 -->Run all examples in parallel, then |
@RajaAutomation And if you are running Tests in parallel instead of Fixtures, you get random test failures, right? |
All tests fail with one of the below reasons -
|
@RajaAutomation Yep. You've found the right issue. Unfortunately there is no fix or workaround for it besides running Fixtures in parallel instead of Tests. |
Hello all, I'm not working anymore on the project where I was facing this problem, but I can confirm that adding the |
@aliaksandrbasau Thank you for the information. |
@RajaAutomation I'm not a part of specflow team so I don't really know. |
@RajaAutomation after scanning through the discussion, I think what you should check first if the issue still exsits if you upgrade to SpecFlow v2.4.1, because there is a good chance that is has been fixed. |
@gasparnagy I have upgraded the specflow to v2.4.1 and for some reason i am not able to see the tests in the UNIT TEST EXPLORER. Is this a known issue. |
@RajaAutomation No. It should work. Make sure you have the latest NUnit visual studio test adapter. (Restart of VS might be also needed). |
@gasparnagy I have checked it and i am using NUnit Visual Studio Test Adapter (3.13.0) which is the latest stable version available. |
According to this issue on Stack Overflow, this can happen if there is a mismatch with the bit version of your target platform and the architecture specified under Test -> Test Settings -> Default Processor Architecture. There's quite a lot of posts there (some more recent than others), so might be worth reading through to see if there is any information of use to your case. |
@Stephen-Mc Implemented all the posts available in that forum however issue still persists. @gasparnagy @Stephen-Mc I have found similar open issue reported when specflow upgraded to v2.3.2 from v2.2.1 (#1201) . In my case its an upgrade from v2.3.2 to v2.4.1. |
@gasparnagy @Stephen-Mc After adding SpecFlowSingleFileGenerator as the custom tool value in feature file properties the tests are visible in test explorer. |
@gasparnagy Issue still persists |
NUnit3TestAdapter 3.12.0 If, in your assembly, you have If, in your assembly, you have Will we get the ability to run parallelization at the test level, rather than the fixture level? |
@MattKeenum Because how SpecFlow work, parallelization on test level will not work without a lot of rewrite. |
@SabotageAndi Thank you for clarifying. Is SpecFlow being rewritten for .Net Core? Or can we expect the same behavior there as well? |
There was no rewrite for .NET Core. It will be the same behaviour in SpecFlow 3 as in SpecFlow 2. |
@SabotageAndi Are there any workarounds to get this working with NUnit? I have a lot of scenario outlines that should run in parallel, but I get the same errors as others mentioned. If it's not possible at all with NUnit, is there another runner besides Specrun that can handle this? I read that XUnit doesn't run datarow tests in parallel at all. How about mstest? |
@janissimsons No there isn't a workaround. Other test runners have also the same problem. The issue is with SpecFlow. |
@janissimsons We are using NUnit and we are writing a custom SingleFileGenerator to generate a .cs file like the SpecFlow does, but still utilizing SpecFlow's extension for the Step Definition generation and feature file because SpecFlow does an amazing job at that. We'll also have to write a back end tool to connect the auto-generated Step Definitions with our auto-generated NUnit tests, but that shouldn't be difficult. It won't have all of the features that SpecFlow has, but we are hoping we can run methods in parallel from this. It's purely exploratory right now. |
Any update . I am using .net core along with Specflow and getting object reference error |
@Prateek1908 No |
Hello,
I have reproduced an error that occured randomly on my CI server:
https://github.com/elias551/specflow-nunit-parallelism-error-poc
I'm using specflow + nunit. It seems like the tests executed in parallel tend to fail often.
In the example I have 10 tests, that I allow to execute in parallel (no tests are dependent to each other), if my machine have 8 cores, then the first 8 tests executed will have the correct result. But then, when a core is freed, the test that will be executed next may throw with the following error:
This error will happen more often if you reduce the level of parallelism with this:
[assembly: LevelOfParallelism(1)]
On the contrary, if you increase the level of parallelism to a greater value than the total number of tests, the tests will always have the correct value.
Given my test project I was not able to define a greater number than the total number of tests (> 50), because in this case every test run at the same time, and nunit never returns a result.
The text was updated successfully, but these errors were encountered: