Skip to content

Conversation

@akoeplinger
Copy link
Member

#55569 didn't fix the issue since xunit retrieves the MemberData and checks for non-empty before evaluating the ConditionalTheory condition.

dotnet#55569 didn't fix the issue since xunit retrieves the MemberData and checks for non-empty *before* evaluating the ConditionalTheory condition.
@stephentoub
Copy link
Member

xunit retrieves the MemberData and checks for non-empty before evaluating the ConditionalTheory condition

This tool is driving me nuts ;-)

@akoeplinger
Copy link
Member Author

@stephentoub btw. I saw that we have Enumerable.Empty<object[]>() here for Windows and I don't know why this doesn't cause an error:

public static IEnumerable<object[]> UninstallableSignals() => Enumerable.Empty<object[]>();

Could you please check whether it runs on Windows?

@stephentoub
Copy link
Member

Could you please check whether it runs on Windows?

    Discovering: System.Runtime.InteropServices.Tests (method display = ClassAndMethod, method display options = None)
    Discovered:  System.Runtime.InteropServices.Tests (found 663 of 694 test cases)
    Starting:    System.Runtime.InteropServices.Tests (parallel test collections = on, max threads = 12)
      System.Runtime.InteropServices.Tests.CULongTests.Ctor_NUInt_LargeValue [SKIP]
        Condition(s) not met: "NativeIntConstructorCannotOverflow"
      System.Runtime.InteropServices.Tests.CLongTests.Ctor_NInt_LargeValue [SKIP]
        Condition(s) not met: "NativeIntConstructorCannotOverflow"
      System.Runtime.InteropServices.Tests.NFloatTests.Ctor_Double_OutOfRange [SKIP]
        Condition(s) not met: "Is32BitProcess"
      System.Runtime.InteropServices.Tests.NFloatTests.ToStringTest32 [SKIP]
        Condition(s) not met: "Is32BitProcess"
    Finished:    System.Runtime.InteropServices.Tests
  === TEST EXECUTION SUMMARY ===
     System.Runtime.InteropServices.Tests  Total: 1871, Errors: 0, Failed: 0, Skipped: 4, Time: 1.437s
  ----- end Wed 07/14/2021 10:40:41.55 ----- exit code 0 ----------------------------------------------------------

Build succeeded.
    0 Warning(s)
    0 Error(s)

@stephentoub
Copy link
Member

D:\repos\runtime\src\libraries\System.Runtime.InteropServices\tests [main ≡]> dotnet build /t:test /p:XunitOptions="-class System.Tests.PosixSignalRegistrationTests"
Microsoft (R) Build Engine version 17.0.0-preview-21325-03+e9593e841 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  System.Runtime -> D:\repos\runtime\artifacts\bin\System.Runtime\ref\net6.0-Debug\System.Runtime.dll
  Microsoft.Win32.Primitives -> D:\repos\runtime\artifacts\bin\Microsoft.Win32.Primitives\ref\net6.0-Debug\Microsoft.Win32.Primitives.dll
  System.Runtime.Extensions -> D:\repos\runtime\artifacts\bin\System.Runtime.Extensions\ref\net6.0-Debug\System.Runtime.Extensions.dll
  System.Security.Principal -> D:\repos\runtime\artifacts\bin\System.Security.Principal\ref\net6.0-Debug\System.Security.Principal.dll
  System.ComponentModel -> D:\repos\runtime\artifacts\bin\System.ComponentModel\ref\net6.0-Debug\System.ComponentModel.dll
  System.Collections -> D:\repos\runtime\artifacts\bin\System.Collections\ref\net6.0-Debug\System.Collections.dll
  System.IO.Pipes -> D:\repos\runtime\artifacts\bin\System.IO.Pipes\ref\net6.0-Debug\System.IO.Pipes.dll
  System.Collections.NonGeneric -> D:\repos\runtime\artifacts\bin\System.Collections.NonGeneric\ref\net6.0-Debug\System.Collections.NonGeneric.dll
  System.ObjectModel -> D:\repos\runtime\artifacts\bin\System.ObjectModel\ref\net6.0-Debug\System.ObjectModel.dll
  System.Runtime.InteropServices -> D:\repos\runtime\artifacts\bin\System.Runtime.InteropServices\ref\net6.0-Debug\System.Runtime.InteropServices.dll
  System.ComponentModel.Primitives -> D:\repos\runtime\artifacts\bin\System.ComponentModel.Primitives\ref\net6.0-Debug\System.ComponentModel.Primitives.dll
  System.Memory -> D:\repos\runtime\artifacts\bin\System.Memory\ref\net6.0-Debug\System.Memory.dll
  System.Collections.Specialized -> D:\repos\runtime\artifacts\bin\System.Collections.Specialized\ref\net6.0-Debug\System.Collections.Specialized.dll
  System.Net.Primitives -> D:\repos\runtime\artifacts\bin\System.Net.Primitives\ref\net6.0-Debug\System.Net.Primitives.dll
  System.Net.WebSockets -> D:\repos\runtime\artifacts\bin\System.Net.WebSockets\ref\net6.0-Debug\System.Net.WebSockets.dll
  System.Security.Claims -> D:\repos\runtime\artifacts\bin\System.Security.Claims\ref\net6.0-Debug\System.Security.Claims.dll
  System.Security.Principal.Windows -> D:\repos\runtime\artifacts\bin\System.Security.Principal.Windows\ref\net6.0-Debug\System.Security.Principal.Windows.dll
  System.Security.AccessControl -> D:\repos\runtime\artifacts\bin\System.Security.AccessControl\ref\net6.0-Debug\System.Security.AccessControl.dll
  System.IO.Pipes.AccessControl -> D:\repos\runtime\artifacts\bin\System.IO.Pipes.AccessControl\ref\net6.0-Debug\System.IO.Pipes.AccessControl.dll
  Microsoft.Win32.Registry -> D:\repos\runtime\artifacts\bin\Microsoft.Win32.Registry\ref\net6.0-Debug\Microsoft.Win32.Registry.dll
  TestUtilities -> D:\repos\runtime\artifacts\bin\TestUtilities\net6.0-Debug\TestUtilities.dll
  System.Runtime.InteropServices.Tests -> D:\repos\runtime\artifacts\bin\System.Runtime.InteropServices.Tests\net6.0-windows-Debug\System.Runtime.InteropServices.Tests.dll
  ----- start Wed 07/14/2021 10:42:05.06 ===============  To repro directly: =====================================================
  pushd D:\repos\runtime\artifacts\bin\System.Runtime.InteropServices.Tests\net6.0-windows-Debug\
  "D:\repos\runtime\artifacts\bin\testhost\net6.0-windows-Debug-x64\dotnet.exe" exec --runtimeconfig System.Runtime.InteropServices.Tests.runtimeconfig.json --depsfile System.Runtime.InteropServices.Tests.deps.json xunit.console.dll System.Runtime.InteropServices.Tests.dll -xml testResults.xml -nologo -notrait category=OuterLoop -notrait category=failing -class System.Tests.PosixSignalRegistrationTests
  popd
  ===========================================================================================================
    Discovering: System.Runtime.InteropServices.Tests (method display = ClassAndMethod, method display options = None)
    Discovered:  System.Runtime.InteropServices.Tests (found 6 of 694 test cases)
    Starting:    System.Runtime.InteropServices.Tests (parallel test collections = on, max threads = 12)
    Finished:    System.Runtime.InteropServices.Tests
  === TEST EXECUTION SUMMARY ===
     System.Runtime.InteropServices.Tests  Total: 19, Errors: 0, Failed: 0, Skipped: 0, Time: 0.141s
  ----- end Wed 07/14/2021 10:42:05.96 ----- exit code 0 ----------------------------------------------------------

Build succeeded.
    0 Warning(s)
    0 Error(s)

@akoeplinger
Copy link
Member Author

akoeplinger commented Jul 14, 2021

@stephentoub just to make sure can you open the testResults.xml and verify it did run the Create_UninstallableSignal_Throws test?

@stephentoub
Copy link
Member

stephentoub commented Jul 14, 2021

It didn't run it because there's nothing to run.

<?xml version="1.0" encoding="utf-8"?>
<assemblies timestamp="07/14/2021 10:42:05">
  <assembly name="System.Runtime.InteropServices.Tests.dll" environment="64-bit .NET  [collection-per-class, parallel (12 threads)]" test-framework="xUnit.net 2.4.1.0" run-date="2021-07-14" run-time="10:42:05" total="19" passed="19" failed="0" skipped="0" time="0.141" errors="0">
    <errors />
    <collection total="19" passed="19" failed="0" skipped="0" name="Test collection for System.Tests.PosixSignalRegistrationTests" time="0.006">
      <test name="System.Tests.PosixSignalRegistrationTests.Create_ValidSignal_Success(signal: SIGINT)" type="System.Tests.PosixSignalRegistrationTests" method="Create_ValidSignal_Success" time="0.0031328" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Create_ValidSignal_Success(signal: SIGQUIT)" type="System.Tests.PosixSignalRegistrationTests" method="Create_ValidSignal_Success" time="0.0000084" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Create_ValidSignal_Success(signal: SIGTERM)" type="System.Tests.PosixSignalRegistrationTests" method="Create_ValidSignal_Success" time="0.0000027" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Create_ValidSignal_Success(signal: SIGHUP)" type="System.Tests.PosixSignalRegistrationTests" method="Create_ValidSignal_Success" time="0.0000021" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Create_RegisterForMultipleSignalsMultipletimes_Success" type="System.Tests.PosixSignalRegistrationTests" method="Create_RegisterForMultipleSignalsMultipletimes_Success" time="0.0005182" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Create_InvalidSignal_Throws(signal: SIGTSTP)" type="System.Tests.PosixSignalRegistrationTests" method="Create_InvalidSignal_Throws" time="0.0012678" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Create_InvalidSignal_Throws(signal: SIGTTOU)" type="System.Tests.PosixSignalRegistrationTests" method="Create_InvalidSignal_Throws" time="0.0000258" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Create_InvalidSignal_Throws(signal: SIGTTIN)" type="System.Tests.PosixSignalRegistrationTests" method="Create_InvalidSignal_Throws" time="0.0000185" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Create_InvalidSignal_Throws(signal: SIGWINCH)" type="System.Tests.PosixSignalRegistrationTests" method="Create_InvalidSignal_Throws" time="0.0000161" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Create_InvalidSignal_Throws(signal: SIGCONT)" type="System.Tests.PosixSignalRegistrationTests" method="Create_InvalidSignal_Throws" time="0.0000152" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Create_InvalidSignal_Throws(signal: SIGCHLD)" type="System.Tests.PosixSignalRegistrationTests" method="Create_InvalidSignal_Throws" time="0.0000151" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Create_InvalidSignal_Throws(signal: 0)" type="System.Tests.PosixSignalRegistrationTests" method="Create_InvalidSignal_Throws" time="0.0000208" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Create_InvalidSignal_Throws(signal: -1000)" type="System.Tests.PosixSignalRegistrationTests" method="Create_InvalidSignal_Throws" time="0.0000156" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Create_InvalidSignal_Throws(signal: 1000)" type="System.Tests.PosixSignalRegistrationTests" method="Create_InvalidSignal_Throws" time="0.0000159" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Create_NullHandler_Throws" type="System.Tests.PosixSignalRegistrationTests" method="Create_NullHandler_Throws" time="0.0008053" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Dispose_Idempotent(signal: SIGINT)" type="System.Tests.PosixSignalRegistrationTests" method="Dispose_Idempotent" time="0.0000941" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Dispose_Idempotent(signal: SIGQUIT)" type="System.Tests.PosixSignalRegistrationTests" method="Dispose_Idempotent" time="0.0000041" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Dispose_Idempotent(signal: SIGTERM)" type="System.Tests.PosixSignalRegistrationTests" method="Dispose_Idempotent" time="0.0000022" result="Pass" />
      <test name="System.Tests.PosixSignalRegistrationTests.Dispose_Idempotent(signal: SIGHUP)" type="System.Tests.PosixSignalRegistrationTests" method="Dispose_Idempotent" time="0.0000021" result="Pass" />
    </collection>
  </assembly>
</assemblies>

@akoeplinger
Copy link
Member Author

akoeplinger commented Jul 14, 2021

Yeah but I'd have expected the discovery to fail due to the empty MemberData. If I take this and run it I get an error (with a dotnet new xunit project):

using System;
using System.Linq;
using System.Collections.Generic;
using Xunit;

using Microsoft.DotNet.XUnitExtensions;

public class UnitTest
{
    public static IEnumerable<object[]> UninstallableSignals() => Enumerable.Empty<object[]>();
    public static bool IsSupported => false;

    [ConditionalTheory(typeof(UnitTest), nameof(UnitTest.IsSupported))]
    [MemberData(nameof(UninstallableSignals))]
    public void TestSignal(int signal)
    {
        Assert.True(signal > 0);
    }
}
$ dotnet test

Test run for /Users/alexander/dev/test/xunittest/bin/Debug/net6.0/xunittest.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.0.0-preview-20210512-01
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:02.12]     UnitTest.TestSignal [FAIL]
  Failed UnitTest.TestSignal [1 ms]
  Error Message:
   System.InvalidOperationException : No data found for UnitTest.TestSignal


Failed!  - Failed:     1, Passed:     0, Skipped:     0, Total:     1, Duration: < 1 ms - /Users/alexander/dev/test/xunittest/bin/Debug/net6.0/xunittest.dll (net6.0)

@akoeplinger
Copy link
Member Author

Hm I wonder if this is a difference in how dotnet test works vs. the xunit runner we use in dotnet/runtime on desktop? We have a custom xunit runner for mobile which might be closer to the dotnet test behavior.

@stephentoub
Copy link
Member

D:\repos\runtime\src\libraries\System.Runtime.InteropServices\tests [main ≡]> dotnet test
  Determining projects to restore...
  All projects are up-to-date for restore.
  System.Runtime -> D:\repos\runtime\artifacts\bin\System.Runtime\ref\net6.0-Debug\System.Runtime.dll
  System.Security.Principal -> D:\repos\runtime\artifacts\bin\System.Security.Principal\ref\net6.0-Debug\System.Security.Principal.dll
  System.Runtime.Extensions -> D:\repos\runtime\artifacts\bin\System.Runtime.Extensions\ref\net6.0-Debug\System.Runtime.Extensions.dll
  Microsoft.Win32.Primitives -> D:\repos\runtime\artifacts\bin\Microsoft.Win32.Primitives\ref\net6.0-Debug\Microsoft.Win32.Primitives.dll
  System.IO.Pipes -> D:\repos\runtime\artifacts\bin\System.IO.Pipes\ref\net6.0-Debug\System.IO.Pipes.dll
  System.Collections.NonGeneric -> D:\repos\runtime\artifacts\bin\System.Collections.NonGeneric\ref\net6.0-Debug\System.Collections.NonGeneric.dll
  System.ComponentModel -> D:\repos\runtime\artifacts\bin\System.ComponentModel\ref\net6.0-Debug\System.ComponentModel.dll
  System.Collections -> D:\repos\runtime\artifacts\bin\System.Collections\ref\net6.0-Debug\System.Collections.dll
  System.ObjectModel -> D:\repos\runtime\artifacts\bin\System.ObjectModel\ref\net6.0-Debug\System.ObjectModel.dll
  System.ComponentModel.Primitives -> D:\repos\runtime\artifacts\bin\System.ComponentModel.Primitives\ref\net6.0-Debug\System.ComponentModel.Primitives.dll
  System.Runtime.InteropServices -> D:\repos\runtime\artifacts\bin\System.Runtime.InteropServices\ref\net6.0-Debug\System.Runtime.InteropServices.dll
  System.Collections.Specialized -> D:\repos\runtime\artifacts\bin\System.Collections.Specialized\ref\net6.0-Debug\System.Collections.Specialized.dll
  System.Memory -> D:\repos\runtime\artifacts\bin\System.Memory\ref\net6.0-Debug\System.Memory.dll
  System.Net.Primitives -> D:\repos\runtime\artifacts\bin\System.Net.Primitives\ref\net6.0-Debug\System.Net.Primitives.dll
  System.Net.WebSockets -> D:\repos\runtime\artifacts\bin\System.Net.WebSockets\ref\net6.0-Debug\System.Net.WebSockets.dll
  System.Security.Claims -> D:\repos\runtime\artifacts\bin\System.Security.Claims\ref\net6.0-Debug\System.Security.Claims.dll
  System.Security.Principal.Windows -> D:\repos\runtime\artifacts\bin\System.Security.Principal.Windows\ref\net6.0-Debug\System.Security.Principal.Windows.dll
  System.Security.AccessControl -> D:\repos\runtime\artifacts\bin\System.Security.AccessControl\ref\net6.0-Debug\System.Security.AccessControl.dll
  System.IO.Pipes.AccessControl -> D:\repos\runtime\artifacts\bin\System.IO.Pipes.AccessControl\ref\net6.0-Debug\System.IO.Pipes.AccessControl.dll
  Microsoft.Win32.Registry -> D:\repos\runtime\artifacts\bin\Microsoft.Win32.Registry\ref\net6.0-Debug\Microsoft.Win32.Registry.dll
  TestUtilities -> D:\repos\runtime\artifacts\bin\TestUtilities\net6.0-Debug\TestUtilities.dll
  System.Runtime.InteropServices.Tests -> D:\repos\runtime\artifacts\bin\System.Runtime.InteropServices.Tests\net6.0-windows-Debug\System.Runtime.InteropServices.Tests.dll
Test run for D:\repos\runtime\artifacts\bin\System.Runtime.InteropServices.Tests\net6.0-windows-Debug\System.Runtime.InteropServices.Tests.dll (.NETCoreApp,Version=v6.0)
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.90]     System.Runtime.InteropServices.Tests.NFloatTests.Ctor_Double_OutOfRange [SKIP]
[xUnit.net 00:00:00.90]     System.Runtime.InteropServices.Tests.NFloatTests.ToStringTest32 [SKIP]
  Skipped System.Runtime.InteropServices.Tests.NFloatTests.Ctor_Double_OutOfRange [1 ms]
  Skipped System.Runtime.InteropServices.Tests.NFloatTests.ToStringTest32 [1 ms]
[xUnit.net 00:00:01.08]     System.Runtime.InteropServices.Tests.CULongTests.Ctor_NUInt_LargeValue [SKIP]
  Skipped System.Runtime.InteropServices.Tests.CULongTests.Ctor_NUInt_LargeValue [1 ms]
[xUnit.net 00:00:01.39]     System.Runtime.InteropServices.Tests.CLongTests.Ctor_NInt_LargeValue [SKIP]
  Skipped System.Runtime.InteropServices.Tests.CLongTests.Ctor_NInt_LargeValue [1 ms]
Results File: D:\repos\runtime\artifacts\bin\System.Runtime.InteropServices.Tests\net6.0-windows-Debug\TestResults\stoub_DESKTOP-G9N6CQ5_2021-07-14_11_04_55.trx
Html test results file : D:\repos\runtime\artifacts\bin\System.Runtime.InteropServices.Tests\net6.0-windows-Debug\TestResults\TestResult_stoub_DESKTOP-G9N6CQ5_20210714_110457.html

Passed!  - Failed:     0, Passed:  1867, Skipped:     4, Total:  1871, Duration: 1 s - System.Runtime.InteropServices.Tests.dll (net6.0)
D:\repos\runtime\src\libraries\System.Runtime.InteropServices\tests [main ≡]>

@akoeplinger
Copy link
Member Author

Very strange 😕

@stephentoub
Copy link
Member

stephentoub commented Jul 14, 2021

If I change this:

"preEnumerateTheories": false

to true, then I get that failure message (though I also get a ton of "Skipping test case with duplicate ID" and "Non-serializable data" found warnings). I wonder if this file is being used on Windows but not elsewhere?

@akoeplinger
Copy link
Member Author

Ah interesting, that makes sense. Yes we don't use that file on the mobile xunit runner.

I guess dotnet test picks it up somehow if you run it in our dotnet/runtime projects so that's why we see the same behavior there.

@stephentoub
Copy link
Member

Glad we got to the bottom of it.

FWIW, if memory serves, we disabled preEnumerateTheories because the enumeration was taking a very long time in some situations, and disabling it shaved off a measurable amount of time from running tests. Might be something to look at for our mobile runs, to at least see if there's any measurable impact. It was particularly impactful for PLINQ, where we have something like 200,000 test cases that come from a much, much smaller number of [Theory]s.

@akoeplinger
Copy link
Member Author

Yup. Turns out it was already disabled for the Browser xunit runner, sent a PR to also disable it for iOS/Android :)

@akoeplinger akoeplinger merged commit 62c9312 into dotnet:main Jul 14, 2021
@akoeplinger akoeplinger deleted the skip-posixsignalregistration branch July 14, 2021 17:04
@ghost ghost locked as resolved and limited conversation to collaborators Aug 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants