Open evandelaney opened 5 months ago
I believe this is caused by Swift Concurrency and the use of the thread safe wrapper. In normal code, since we're event loop based we don't hit that, but that's not the case for tests.
One option would be to migrate to a NIOLockedValueBox
, that should be a quick fix that can be done in a small PR. The real solution is migrate the library to async/await, but that's going to take more time
Unit tests crash in
XCTestCase
subclasses inside ofoverride func setUp() async throws
at the point where.oAuth(from:authenticate:callback:scope:completion:)
is called in production code.The stack trace shows
OAuthService.services.getter
force unwrapping the globalservices
variable, which is of typeThreadSpecificVariable<OAuthServiceContainer>
.According to the headerdocs for
ThreadSpecificVariable.init(value:)
:I suspect this is a multithreading issue. Maybe the first instance of a test class (to run
testFoo
) sets up the OAuth route on Thread A, and the next instance of the test class (to runtestBar
) tries to set up the OAuth route on Thread B.I was, in fact, able to confirm this with breakpoints in Xcode. Anytime
setUp()
jumps to a different thread, the test run will crash.Here is an example minimal project that reproduces the issue.