Question

I am trying to write a test case using xUnit.net and the AutoRollback attribute provided by the xunit extensions.

My test case goes like this

[Fact, AutoRollback]<br>
public void TestCase()<br>
{

    // insert into data table
    repository.Insert(data);

    // spawn a new thread and read data which you just inserted in the data table
    Task.Factory.StartNew(action_to_read_data);
}

This test case fails and throws a connection timeout exception while reading the data in the new thread. The problem I have found is that the test case starts a transaction because of the AutoRollback attribute and while Inserting the data it locks the table for rollback at the end. The new thread spawned by the test case cannot read data from the same table because it is locked by the parent thread. I can read the data in the same thread though.

Anyone have a solution? I want to run multiple threads reading the data inserted above.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top