Skip to content

Commit

Permalink
Update to TTL scope test
Browse files Browse the repository at this point in the history
  • Loading branch information
hmlongco committed Apr 21, 2023
1 parent 3f4efc8 commit e53f3b0
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions Tests/FactoryTests/FactoryScopeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
Expand Down

0 comments on commit e53f3b0

Please sign in to comment.