Description
I have this code to ensure that an object doesn't leak at the end of tests:
self.addTeardownBlock { [weak instance = Singleton.shared] in
expect { instance == nil }.toEventually(beTrue(), description: "Instance has leaked")
}
That .toEventually comes from Nimble, it basically polls after some interval, until a certain timeout, verifying the condition.
On CI I noticed sometimes we get a crash:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libswiftCore.dylib 0x10bc64589 swift::runtime::AccessSet::insert(swift::runtime::Access*, void*, void*, swift::ExclusivityFlags) + 73
1 libswiftCore.dylib 0x10bc647e2 swift_beginAccess + 66
2 BackendIntegrationTests 0x13ab37c76 default argument 1 of Expectation.toEventually(_:timeout:pollInterval:description:) + 54
3 BackendIntegrationTests 0x13ab37b44 closure #1 in BaseBackendIntegrationTests.verifyPurchasesDoesNotLeak() + 276 (BaseBackendIntegrationTests.swift:167)
Which I believe is due to some race-condition accessing that weak var.
I believe changing the code to this works around it:
weak var instance = Singleton.shared
self.addTeardownBlock {
expect { instance == nil }.toEventually(beTrue(), description: "Instance has leaked")
}
Environment
swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0
Xcode 14.3
Build version 14E222b
- Deployment target: iOS 16.4
Description
I have this code to ensure that an object doesn't leak at the end of tests:
That
.toEventuallycomes fromNimble, it basically polls after some interval, until a certain timeout, verifying the condition.On CI I noticed sometimes we get a crash:
Which I believe is due to some race-condition accessing that
weakvar.I believe changing the code to this works around it:
Environment