Task, async, testing, disappearing

I have to test some async functions. All of them have almost identical skeleton, like this:

func testSomeAsyncFuntion() throws {
     //...some settings
     Task<Void, Error> {
           let result = try await MyClass.someAsyncFunction(settings: settings)
           print (result) // I don't know result, so I print. :)
     }
}

All tested functions have nested try await... functions, Task.checkCancellation() in many of them. Only one disapear with no word for goodbye.
In most cases, it returns result and print it to console, in one case only it ends immediately with raport in console:

Test Case '-[HyperValueTests.GridTests testDefineGrid]' started.
Test Case '-[HyperValueTests.GridTests testDefineGrid]' passed (0.003 seconds).
Test Suite 'GridTests' passed at 2023-11-14 21:57:12.565.
	 Executed 1 test, with 0 failures (0 unexpected) in 0.003 (0.004) seconds
Test Suite 'HyperValueTests.xctest' passed at 2023-11-14 21:57:12.565.
	 Executed 1 test, with 0 failures (0 unexpected) in 0.003 (0.004) seconds
Test Suite 'Selected tests' passed at 2023-11-14 21:57:12.565.
	 Executed 1 test, with 0 failures (0 unexpected) in 0.003 (0.006) seconds
Program ended with exit code: 0

If I change all functions to not async after 1.5 sec I have a nice result.

Does somebody have an idea where to look?

The test function itself can be made async, so you don’t need it to spawn a Task.

OK. Now I can see result. Five hours in my back. Thanks!

1 Like