runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Intermittent System.Numerics.Tests.divremTest.RunDivRemTests failed in CI on CentOS, Windows

Open stephentoub opened this issue 10 years ago • 18 comments

http://dotnet-ci.cloudapp.net/job/dotnet_corefx/job/master/job/outerloop_centos7.1_debug_tst/3/consoleFull

00:29:07    System.Numerics.Tests.divremTest.RunDivRemTests [FAIL]
00:29:07       Assert.Throws() Failure
00:29:07       Expected: typeof(System.DivideByZeroException)
00:29:07       Actual:   typeof(Xunit.Sdk.TrueException): Out parameters not matching
00:29:07       Expected: True
00:29:07       Actual:   False
00:29:07       Stack Trace:
00:29:07             at System.Numerics.Tests.StackCalc.VerifyOutParameter()
00:29:07             at System.Numerics.Tests.divremTest.VerifyDivRemString(String opstring)
00:29:07             at System.Numerics.Tests.divremTest.<>c__DisplayClass8_0.<RunDivRemTests>b__0()

stephentoub avatar Apr 17 '16 12:04 stephentoub

I'm not able to reproduce this, unfortunately. I initially assumed it must have something to do with the random numbers being generated in the test. The test class uses a predictable seed value, but the Random instance is static and shared across the test cases. Technically, I think xUnit is free to run tests in whatever order it wants, which could result in unpredictable values being used in different test cases. In practice, though, I'm only seeing it run the tests in the same order, so the test cases should be using the same test values in every run.

mellinoe avatar Jun 08 '16 19:06 mellinoe

Failed again here: http://dotnet-ci.cloudapp.net/job/dotnet_corefx/job/master/job/outerloop_win10_debug/64/consoleText

System.Numerics.Tests.divremTest.RunDivRemTests [FAIL]
        Assert.Equal() Failure
        Expected: 0
        Actual:   -4966759395308350

stephentoub avatar Jun 14 '16 11:06 stephentoub

Failed again here, this time on Fedora: https://ci.dot.net/job/dotnet_corefx/job/master/job/outerloop_fedora23_release/44/consoleText

     System.Numerics.Tests.divremTest.RunDivRemTests [FAIL]
        Assert.Throws() Failure
        Expected: typeof(System.DivideByZeroException)
        Actual:   typeof(Xunit.Sdk.EqualException): Assert.Equal() Failure
        Expected: 0
        Actual:   -4966759395308350
    StackTrace:
/mnt/resource/j/workspace/dotnet_corefx/master/outerloop_fedora23_release/src/System.Runtime.Numerics/tests/BigInteger/stackcalculator.cs(252,0): at System.Numerics.Tests.StackCalc.VerifyOutParameter()
/mnt/resource/j/workspace/dotnet_corefx/master/outerloop_fedora23_release/src/System.Runtime.Numerics/tests/BigInteger/divrem.cs(185,0): at System.Numerics.Tests.divremTest.VerifyDivRemString(String opstring)

stephentoub avatar Oct 23 '16 12:10 stephentoub

Technically, I think xUnit is free to run tests in whatever order it wants, which could result in unpredictable values being used in different test cases. In practice, though, I'm only seeing it run the tests in the same order, so the test cases should be using the same test values in every run.

Tests do not always run in the same order. If the tests are expecting to be run in a particular order, we need to fix the tests.

stephentoub avatar Oct 23 '16 12:10 stephentoub

Even besides the test ordering problem, Random isn't threadsafe. Tests are run in parallel. So part of what we're seeing is possibly due to its internal state being corrupted. The remarks claim that concurrent access results in a 0 being returned, but the current code doesn't seem to do anything to ensure that (...and if the code isn't threadsafe, detection strikes me as unlikely anyways). Also, such a 0 strikes me as problematic anyways, since 0 may be valid or invalid input, depending on method and parameters used.

Clockwork-Muse avatar Oct 24 '16 05:10 Clockwork-Muse

Not sure if it's the same underlying cause, but another divremTest test failed here: http://dotnet-ci1.westus.cloudapp.azure.com/job/dotnet_corefx/job/master/job/outerloop_ubuntu16.04_release/1/consoleText

System.Numerics.Tests.divremTest.RunDivRem_OneSmallOne0BI [FAIL]
        Assert.Equal() Failure
        Expected: 0
        Actual:   31122745322556859589923417330907291586
        Stack Trace:
           /mnt/j/workspace/dotnet_corefx/master/outerloop_ubuntu16.04_release/src/System.Runtime.Numerics/tests/BigInteger/stackcalculator.cs(252,0): at System.Numerics.Tests.StackCalc.VerifyOutParameter()
           /mnt/j/workspace/dotnet_corefx/master/outerloop_ubuntu16.04_release/src/System.Runtime.Numerics/tests/BigInteger/divrem.cs(185,0): at System.Numerics.Tests.divremTest.VerifyDivRemString(String opstring)
           /mnt/j/workspace/dotnet_corefx/master/outerloop_ubuntu16.04_release/src/System.Runtime.Numerics/tests/BigInteger/divrem.cs(96,0): at System.Numerics.Tests.divremTest.RunDivRem_OneSmallOne0BI()

stephentoub avatar Nov 03 '16 20:11 stephentoub

Also here on macOS: https://ci.dot.net/job/dotnet_corefx/job/release_1.0.0/job/outerloop_osx_debug/15/consoleText

     System.Numerics.Tests.divremTest.RunDivRem_OneLargeOne0BI [FAIL]
        Assert.Throws() Failure
        Expected: typeof(System.DivideByZeroException)
        Actual:   typeof(Xunit.Sdk.EqualException): Assert.Equal() Failure
        Expected: 0
        Actual:   -4966759395308350
        Stack Trace:
              at System.Numerics.Tests.StackCalc.VerifyOutParameter()
              at System.Numerics.Tests.divremTest.VerifyDivRemString(String opstring)
              at System.Numerics.Tests.divremTest.<>c__DisplayClass5_0.<RunDivRem_OneLargeOne0BI>b__0()

stephentoub avatar Nov 04 '16 18:11 stephentoub

@mellinoe could you please try again to repro locally?

Note if you can't repro then @Clockwork-Muse's comment above that Random isn't threadsafe may be the key to making them reliably repro.

danmoseley avatar Nov 07 '16 17:11 danmoseley

@jiangzeng how often are we seeing this?

danmoseley avatar Nov 28 '16 21:11 danmoseley

@danmosemsft I checked the history results from MissionControl in the last month, it looks like it does not happen.

jiangzeng avatar Nov 29 '16 00:11 jiangzeng

@danmosemsft - while it's true that Random isn't threadsafe, on further review it's unlikely that's happening here. Tests are multi-threaded, but this is usually only in independent units (test classes), probably specifically to avoid something like this.

Clockwork-Muse avatar Nov 29 '16 02:11 Clockwork-Muse

If you really need to run tests in a particular order you can force it with the attribute at https://github.com/dotnet/corefx/blob/master/src/System.Linq.Expressions/tests/TestExtensions/TestOrderAttribute.cs and the orderer at https://github.com/dotnet/corefx/blob/master/src/System.Linq.Expressions/tests/TestExtensions/TestOrderer.cs though its best avoided since it breaks isolation (the expressions tests use those to check something before and after a one-way change in static state, so the ordering requirement is unavoidable)

JonHanna avatar Nov 29 '16 02:11 JonHanna

@Clockwork-Muse also it doesn't appear that these tests rely on any particular random numbers (not that you were suggesting they were). I will add logging of the random numbers used, perhaps that will allow us to repro it locally.

danmoseley avatar Nov 29 '16 05:11 danmoseley

@jiangzeng I added some logging to help us when this fails again. Please next time you see this fail, grab as much of the log as you can and put it in this issue. In particular look for text like this

 System.Numerics.Tests.divremTest.RunDivRem_OneSmallOne0BI [FAIL]
        System.Exception : VerifyDivRemString failed: make 197 24 endmake make 0 endmake bDivRem Xunit.Sdk.EqualException: Assert.Equal() Failure
        Expected: 0
        Actual:   2
           at Xunit.Assert.Equal[T](T expected, T actual, IEqualityComparer`1 comparer) in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.assert\Asserts\EqualityAsserts.cs:line 35
           at Xunit.Assert.Equal[T](T expected, T actual) in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.assert\Asserts\EqualityAsserts.cs:line 20
           at System.Numerics.Tests.StackCalc.VerifyOutParameter() in C:\git\corefx.dan\src\System.Runtime.Numerics\tests\BigInteger\stackcalculator.cs:line 250
           at System.Numerics.Tests.divremTest.VerifyDivRemString(String opstring) in C:\git\corefx.dan\src\System.Runtime.Numerics\tests\BigInteger\divrem.cs:line 190
        ---- Assert.Equal() Failure
        Expected: 0
        Actual:   2
        Stack Trace:
           C:\git\corefx.dan\src\System.Runtime.Numerics\tests\BigInteger\divrem.cs(196,0): at System.Numerics.Tests.divremTest.VerifyDivRemString(String opstring)
           C:\git\corefx.dan\src\System.Runtime.Numerics\tests\BigInteger\divrem.cs(94,0): at System.Numerics.Tests.divremTest.RunDivRem_OneSmallOne0BI()
           ----- Inner Stack Trace -----
           C:\git\corefx.dan\src\System.Runtime.Numerics\tests\BigInteger\stackcalculator.cs(250,0): at System.Numerics.Tests.StackCalc.VerifyOutParameter()
           C:\git\corefx.dan\src\System.Runtime.Numerics\tests\BigInteger\divrem.cs(190,0): at System.Numerics.Tests.divremTest.VerifyDivRemString(String opstring)

danmoseley avatar Nov 29 '16 17:11 danmoseley

@danmosemsft Sure

jiangzeng avatar Nov 30 '16 00:11 jiangzeng

@jiangzeng have we seen this recently? any log for it?

danmoseley avatar Dec 27 '16 21:12 danmoseley

@danmosemsft I did not see it in runs of recent one month.

jiangzeng avatar Dec 28 '16 00:12 jiangzeng

I am going to close this on the shaky assumption that some other change has fixed it in the last 2 months. @jiangzeng please reopen with the relevant log (similar to mine above) if this does fail.

danmoseley avatar Dec 28 '16 07:12 danmoseley