mardi 13 septembre 2016

xUnit.net tests fail to run due to std::launch::async in C++ dependency

In our application, the main logic is in C++ DLLs and is called from C# via a thin C++ CLI wrapper. The C++ layer uses std::async to process some work asynchronously.

When attempting to run integration tests (written in C# using xUnit.net) in Visual Studio 2013 using ReSharper 2016, the test runner reports "Inconclusive: Test not run". After a process of elimination, it was found that the launch policy of the std::async calls was to blame - changing it from std::launch::async to std::launch::sync allowed the tests to run successfully.

(Side note - is it possible to see more detailed information about why a test was not run in VS?)

We're currently using xUnit.net 2.1 - is there any way to get the tests to run whilst still using std::launch::async? If not, is there an easy way to detect whether the code is being run under the test runner so we can switch between the launch policies?

I've included a simplified, pseudo-version of the code that fails to run below.

C++:

public void AsyncTask()
{
    // Changing the launch policy to std::launch::sync allows the test to be run
    auto future = std::async(std::launch::async,
                             [/*capture list*/]
                             {/*some function*/});
}

C#:

[Fact]
public void AsyncTest()
{
    // Arrange
    var sut = new AsyncTaskWrapper();

    // Act
    sut.SomeMethodThatEventuallyCallsAsyncTask();

    // Assert
    // ...
}

Aucun commentaire:

Enregistrer un commentaire