From e53f3b04b78f696a5da58430daf8c91311196b4d Mon Sep 17 00:00:00 2001 From: Michael Long Date: Fri, 21 Apr 2023 15:15:21 -0500 Subject: [PATCH] Update to TTL scope test --- Tests/FactoryTests/FactoryScopeTests.swift | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Tests/FactoryTests/FactoryScopeTests.swift b/Tests/FactoryTests/FactoryScopeTests.swift index d3e7000d..96ceec68 100644 --- a/Tests/FactoryTests/FactoryScopeTests.swift +++ b/Tests/FactoryTests/FactoryScopeTests.swift @@ -385,18 +385,17 @@ final class FactoryScopeTests: XCTestCase { container1.manager.trace.toggle() } - func testSingletonScopeTimeToLive() throws { + @available(iOS 13, *) + func testSingletonScopeTimeToLive() async throws { + Container.shared.singletonService.timeToLive(0.01) let service1 = Container.shared.singletonService() let service2 = Container.shared.singletonService() XCTAssertTrue(service1.id == service2.id) - Container.shared.singletonService.timeToLive(-60) + // delay + try await Task.sleep(nanoseconds: 10_100_000) + // resolution should fail ttl test and return new instance let service3 = Container.shared.singletonService() - // should fail ttl test and return new instance XCTAssertTrue(service2.id != service3.id) - Container.shared.singletonService.timeToLive(60) - let service4 = Container.shared.singletonService() - // should passs ttl test and return old instance - XCTAssertTrue(service3.id == service4.id) } }