Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Random test failure when using TestCaseSource: The parent fixture of this test experienced a failure
abelb
#1 Posted : Sunday, September 28, 2014 11:59:35 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
We use TestCaseSource a lot, but it didn't give us much trouble so far. However, today I added a couple of tests that do little more than checking whether the commandline help file contains an entry for a given commandline option.

All tests should succeed, however:

  • On first run, one or two tests fail
  • On second run, more tests fail
  • On later runs, all tests fail
  • Running it again, in a new task runner or in the same, they will always fail
  • Clicking "reload and return selected component" sometimes helps, but only for the first run


If I remove the TestCaseSource, or even if I leave it in, but do not use it inside the test, the tests succeed. The strange thing is, we have around a thousand tests that use TestCaseSource and they all run fine with NCrunch. This particular case is dramatically simpler, but now they fail.

I thought for a moment it had to do with the order in which the tests are executed, or with multithreading, but the same behavior appears when I run only one test, even if I disable all other tests in the same block.

The error is internal to NCrunch and does not come from my test, which seems to suggest I encountered a bug:

Quote:
The parent fixture of this test experienced a failure during test execution


I read this post, but I don't think it applies: http://forum.ncrunch.net...Unit-TestCaseSource.aspx
abelb
#2 Posted : Monday, September 29, 2014 12:22:18 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
It seems like the testdata for TestCaseSource must be typed. I use F#, which uses type inference, so it oughtn't be needed. Still it does not explain why on the first run it typically works normally and subsequent runs show more and more failures.
Remco
#3 Posted : Monday, September 29, 2014 2:01:45 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi,

Try setting your 'Log verbosity' setting to 'Detailed', then examining the trace output for a failed test run inside the processing queue. Does the log give you any indication of what may be failing?

You may have already read this, but I thought I'd suggest it anyway as it's often good to be aware of test process life-cycle differences between NCrunch and other test runners - http://www.ncrunch.net/documentation/considerations-and-constraints_test-atomicity.


Cheers,

Remco
abelb
#4 Posted : Monday, September 29, 2014 12:32:59 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
I did as you suggested, set "Logging verbosity" under "General Settings" to "Detailed". Howver, the "NCrunch Diagnostic Output" remains empty and the output in the NCrunch Tests runner remains that one line: "The parent fixture of this test experienced a failure during test execution"

At this time I am wondering whether it may be caused by redirecting stdout/stderr, but the redirection deliberately only takes place just before the test is run and is reset afterwards. I will do a few more tests to see if it is related. In fact, I will try to create a minimum test that shows this behavior, so that you can reproduce it locally.
abelb
#5 Posted : Monday, September 29, 2014 1:03:04 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
A few more observations:


  • I restarted Visual Studio after setting the logging verbosity, after restart, it was reset to "Summary", seems like the change in settings is not saved, and probably wasn't set even though it showed "Detailed" prior to restarting
  • The problem *only* occurs with "should contain "some string" from FsUnit, which translates to Assert.Contains
  • Other string tests, like "should startWith" (Assert.StartWith) do not suffer from this issue
  • Creating a Fake test that does not call the main program (Program.Main) but instead mimics the behavior by rerouting the stdout/stderr and writing some messages to both of them does not show the same problematic behavior. They are consistently succeeding (or failing).


This limits the issue to two things: (1) it cannot easily be reproduced and (2) verbosity logging is likely a necessity to track this one down, but currently that setting is not saved.
abelb
#6 Posted : Monday, September 29, 2014 1:48:14 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
I followed your link and did the following as well, though I don't think they are a requirement, I do realize that Console.XXX are static methods, so:


  • Adding a "lock someStaticObject" statement around the potentially offensive part in the code (where the stdout/stderr are redirected)
  • Adding the IsolatedAttribute to the offending tests
  • Adding IgnoreAttribute to any other test that uses this method, to prevent them from being in each others way


The lock method did not change behavior (first run: correct, subsequent runs: most of the time the same message). Adding the IsolatedAttribute though did have effect: now all successfull tests consistently fail with the message "The parent fixture of this test experienced a failure during test execution" and all failing tests consistently fail as they should.
abelb
#7 Posted : Monday, September 29, 2014 2:24:22 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
Ok, now I know that I misunderstood the behavior of "should contain someString", which, instead of containing a string (Is.StringContaining) is mapped to the CollectionContains assertion. This does not explain the inconsistent behavior though (string are themselves collections, the test may have been wrong, but why does it yield the error we saw?).

What I found now is that: if I add a line prior to the offending line doing an Assert.That (stdout, (Is.StringContaining testData)), then the following lines consistently behave as they should.

I have checked the generated assembly with Reflector for both the code with and without that extra line, but could not readily find a cause for this behavior. I think the only thing we can do at this phase is to try to debug NCrunch, or try to get the "Logging verbosity" set (it still is not working). I am willing to send you the project in private and in trust (it contains copyrighted material) if you want to investigate this further.
abelb
#8 Posted : Monday, September 29, 2014 3:42:50 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
Hmm, forget what I said about misunderstanding "should contain someString", as it is correctly mapped to testing for a string. It also reports "Expected: String containing "xxx"".

I did the following, in my effort to get the logging verbosity working: I increased the Builg process memory limit by 1 byte. This prompted a full unload of NCrunch. After the reload of NCrunch, the problem went away (at least to the extend that I can't reproduce it anymore). It is strange that this helped, because restarting Visual Studio had a lesser effect than changing the max memory limit.

At the upside, this gives me a way to fully unload/reload/rebuild NCrunch that I can't seem to do in any other way: increase or decrease the memory limit.

About the logging verbosity: I needed to set the "Log to output window" to True. Still strange that it did no remember my verbosity level change, I think that is a bug. Also, I still have the bug of always showing "Running" (as mentioned in another post).

I am still at a loss as to why the behavior was the way it was, and why only with that particular line of code. The fix (increase/decrease memory) is also kind-of far-fetched and may not be related to the original issue arising.
Remco
#9 Posted : Monday, September 29, 2014 10:35:20 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Sorry, I meant to look in the Processing Queue Window details pane for the log details after you've set your Log Verbosity to Detailed.

NCrunch won't place logged data into the diagnostic output window unless you also turn on the 'Log to output window' option. This window isn't usually very good for trying to trace problems that relate to a specific test run, as it quickly gets very noisy. The details pane in the Processing Queue Window will filter logs to the selected task, which makes it much easier to find things.

On each load, NCrunch will deliberately set the Log Verbosity back to Summary. This is done because logging is hugely expensive in terms of CPU and memory consumption, and having it left on accidentally greatly inhibits the performance of Visual Studio. Early versions of NCrunch didn't do this, and this forum was exploding with people complaining about performance problems :(

The change in behaviour caused by IsolatedAttribute confirms that the variation in this test's behaviour is being surfaced by either test execution sequence or NCrunch's re-use of the test runner process. I recommend leaving this attribute on the test until we've figured out why it is falsely failing, and possibly afterwards too unless you're able to find the state that is conflicting between test runs. Note that adding locks to the test won't make any difference, as NCrunch's parallelisation works across multiple processes (not threads).
abelb
#10 Posted : Wednesday, October 1, 2014 8:11:10 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
Well, as you may have seen in my previous comment: the problem disappeared at some point (more specifically, after I switched the amount of allowed build process memory to 1 byte higher, which seemed to trigger a full sweep of any temporary files, a handy shortcut if I need to do a "reset" of NCrunch).

I tried to bring back the error from a previous version of the tests, but the problem did not reappear, even though I am sure that with such previous version it did occur. Since only cached and temp files are not in our DCVS, these are the only ones that have changed in-between. Unless the issue pops up again, I am afraid there will be little I can do to help solve this.

Good to know about the type of parallelism, it rules out quite a few potential issues.
Remco
#11 Posted : Wednesday, October 1, 2014 9:14:04 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
I think that the failure here is surfacing because of the variations in test execution sequence and/or batching of tests in the processing queue. Setting memory limits on the processes will likely suppress the problem but it will also degrade performance as NCrunch is then unable to re-use processes between runs. If you disable the process memory limits, I think there is a high probability you will see the problem again. When it does show, I'll be happy to help you troubleshoot further.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.078 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download