diff --git a/src/utest/Async.hx b/src/utest/Async.hx index cb1fa10..e115d9e 100644 --- a/src/utest/Async.hx +++ b/src/utest/Async.hx @@ -28,6 +28,10 @@ class Async { return resolvedInstance; } + static inline function strPos(pos:PosInfos):String { + return pos.fileName + ':' + pos.lineNumber; + } + function new(timeoutMs:Int = 250) { this.timeoutMs = timeoutMs; startTime = Timer.stamp(); @@ -37,9 +41,9 @@ class Async { public function done(?pos:PosInfos) { if(resolved) { if(timedOut) { - throw 'Cannot done() at ${pos.fileName}:${pos.lineNumber} because async is timed out.'; + throw 'Cannot done() at ${strPos(pos)} because async is timed out.'; } else { - throw 'Cannot done() at ${pos.fileName}:${pos.lineNumber} because async is done already.'; + throw 'Cannot done() at ${strPos(pos)} because async is done already.'; } } resolved = true; @@ -52,10 +56,10 @@ class Async { */ public function setTimeout(timeoutMs:Int, ?pos:PosInfos) { if(resolved) { - throw 'Cannot setTimeout($timeoutMs) at ${pos.fileName}:${pos.lineNumber} because async is done.'; + throw 'Cannot setTimeout($timeoutMs) at ${strPos(pos)} because async is done.'; } if(timedOut) { - throw 'Cannot setTimeout($timeoutMs) at ${pos.fileName}:${pos.lineNumber} because async is timed out.'; + throw 'Cannot setTimeout($timeoutMs) at ${strPos(pos)} because async is timed out.'; } timer.stop(); diff --git a/src/utest/Runner.hx b/src/utest/Runner.hx index b26f43d..efca6e3 100644 --- a/src/utest/Runner.hx +++ b/src/utest/Runner.hx @@ -355,7 +355,8 @@ private class ITestRunner { if(setupAsync.timedOut) { setupFailed(SetupError('setupClass timeout', [])); } else { - runFixtures(); + if(runFixtures()) + runCases(); } } diff --git a/test/utest/TestAsyncITest.hx b/test/utest/TestAsyncITest.hx index be98ac7..f41d23e 100644 --- a/test/utest/TestAsyncITest.hx +++ b/test/utest/TestAsyncITest.hx @@ -80,6 +80,22 @@ class TestAsyncITest extends Test { Assert.isTrue(setupCallCount > 0); } + function testAsyncSetupClassWithSyncEverythingElse_doesNotHang(async:Async) { + + var currentResults = Assert.results; + Assert.results = new List(); + + var runner = new Runner(); + runner.addCase(new TestAsyncSetupClassWithSyncEverythingElse()); + + runner.onComplete.add(_ -> { + Assert.results = currentResults; + Assert.pass(); + async.done(); + }); + runner.run(); + } + function teardown(async:Async) { teardownRunning = true; @@ -130,4 +146,15 @@ class TestAsyncITest extends Test { 1750 ); } +} + +private class TestAsyncSetupClassWithSyncEverythingElse extends Test { + @:timeout(50) + function setupClass(async: Async): Void { + haxe.Timer.delay(() -> async.done(), 10); + } + + function testSomething() { + Assert.pass(); + } } \ No newline at end of file