2

Closed

Using [Fact(Timeout=)] causes test to run on different thread from ctor

description

Repro:
  1. Create a test class
  2. Initialize a new instance of a Mutex in the ctor of the test class
  3. Attempt to release the Mutex in the test
Expected: Success
Actual: Fails with an exception stating you don't own the mutex

The problem is that, when using a Timeout, the TimeoutCommand executes the test on a new thread so that it can watch for success or failure on the main testing thread, and return as soon as the timeout has been reached. Since TimeoutCommand is late in the delegated command cycle, everything else has already been run (including the object's constructor and the before/after attributes).

Moving the TimeoutCommand to the front of the stack should fix the issue, but then the timer will already be running while we do object creation and executing the before/after attributes, which may give an unnecessarily skewed view of how long the test took to run.
Closed Jun 20, 2010 at 9:34 PM by BradWilson
Shipped in xUnit.net 1.6.

comments

BradWilson wrote Dec 30, 2009 at 12:10 AM

Fixed in changeset #53283.