massiveinteractive/MassiveUnit — Issue #14: Throwing exception in AsyncTest ends test but doesn't cancel aysnc timeout
Author: misprintt
Created: 2011-12-31 00:38:24+00:00
State: open

### Description

Throwing an exception inside an async test catches the error, but doesn't remove the AsyncDelegate timeout. This causes the test runner to report the async error after the test has finished (often once other test classes have started executing).

#### Code to replicate issue

@AsyncTest
public function shouldCancelAsyncTimeoutInTestRunner(factory:AsyncFactory)
{
var handler:Dynamic = factory.createHandler(this, handler, 50);
throw "exception";
}

function handler()
{
Assert.isTrue(true);
}

### Proposed Solution

To prevent this, TestRunner.executeTestCase should check inside catch statement for asyncPending and then be able to cancel a AsyncDelegate.

#### massive.munit.TestRunner#executeTestCase

try
{
...
}
catch(e:Dynamic)
{
if(async && asyncPending)
{
//cancel delegate
}

...
}

Currently there is no way to access the generated delegate outside of the test being executed. AsyncFactory.createHandler should either hash generated AsyncDelegates using the asyncDelegateCount or at least store the most recent delegate in an internal property so that they can be retrieved for canceling.

### massive.munit.async.AsyncFactory

//add functionality to retrieve the current AsyncDelegate instance

The AsyncDelegate will also require a public method for canceling the internal timer:

### massive.munit.async.AsyncDelegate

public function cancel():Void
{
timer.stop();
}