dotnet测试失败,显示“活动的测试运行已中止。原因:”

时间:2018-07-31 23:26:11

标签: c# linux unit-testing .net-core

Dotnet测试运行随机失败,并显示以下消息:

The active test run was aborted. Reason:

没有给出原因,并且在Jenkins Linux主机上运行时会随机发生此故障。在Windows上的Visual Studio或命令行中没有问题。

我能够通过几个函数找到故障的位置,简化的代码如下所示:

    [Fact]
    public void FailAfterExpiration()
    {
        // Step 1: open session that expires after 30 seconds
        OpenExpiringSession(); 

        // Step 2: Wait for expiration of the session
        Thread.Sleep(35 * 1000);

        // Step 3: check that failure happened
        Assert.False(CheckSessionState());
    }

有时此功能会按预期工作,但是大多数情况下,在1-2秒的睡眠后,它无法在步骤2上执行。发生这种行为的原因可能是什么? Thread.Sleep是否导致单元测试失败?

0 个答案:

没有答案