Holding a thread longer open then a test runs through causes coverlet to problably crash internaly and dont calc code coverage #1678
Labels
needs more info
More details are needed
question
This issue is a question
stale
untriaged
To be investigated
Hi,
yesterday I opened #1677, which i further investigated today, because the title + text are complelty different I choosed to close the old one and open a new one with a bunch of more details.
Today I was able to pinpoint the bug (maybe even not even a bug, maybe a known behaviour):
When I open in a thread that needs longer then a test-run is, the thread blocking coverlet from getting any results for the complete project in it (not only the class or the test the failure code is in).
I was able to write a reproduce:
`public class TestServiceA : ITestServiceA
{
public string DoubleText(string str)
{
new Thread(async () =>
{
try
{
Thread.Sleep(10);
}
catch (Exception e)
{
}
}).Start();
}`
`namespace EmailService.Services;
public interface ITestServiceB
{
}
public class TestServiceB(ITestServiceA testServiceA) : ITestServiceB
{
public string Cut(string str)
{
var newStr = testServiceA.DoubleText(str);
return newStr.Substring(0,5);
}
}`
` [Test]
public void Rep()
{
var serviceA = new TestServiceA();
var result = serviceA.DoubleText("Test");
Assert.That(result, Is.EqualTo("TestTest"));
}
So what we have here is a Thread within the code that should be tested.
The code above produces the code coverage just fine.
If we now start adding more ms to the Thread.Sleep until a point where the test execution is faster then the Thread opened, the coverage for ALL tests in the given test project is 0,0% (e.g. 1000ms)
There is no errorcode or whatever, it just seems that the code coverage calc crashes internaly (?).
In my real life usecase when I found this bug, I have 15 tests are with 0% coverage because I wait 1second to long in the thread.
If I remove the Thread.Sleep or reduce it, all 15 tests will be having code coverage caluclated, even only 1 out of the 15 tests using the method where the thread is in.
The text was updated successfully, but these errors were encountered: