Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Oct 22, 2024
1 parent 298bd77 commit f0c1acb
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions Blockchain/Tests/BlockchainTests/DispatchQueueSchedulerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,24 @@ struct DispatchQueueSchedulerTests {
}

@Test func scheduleDelayedTask() async throws {
try await confirmation { confirm in
let delay = 0.5
let now = Date()
let end: ThreadSafeContainer<Date?> = .init(nil)
let cancel = scheduler.schedule(delay: delay, repeats: false) {
end.value = Date()
confirm()
}
await withKnownIssue("unstable when cpu is busy", isIntermittent: true) {
try await confirmation { confirm in
let delay = 0.5
let now = Date()
let end: ThreadSafeContainer<Date?> = .init(nil)
let cancel = scheduler.schedule(delay: delay, repeats: false) {
end.value = Date()
confirm()
}

try await Task.sleep(for: .seconds(1))
try await Task.sleep(for: .seconds(1))

_ = cancel
_ = cancel

let diff = try #require(end.value).timeIntervalSince(now) - delay
let diffAbs = abs(diff)
#expect(diffAbs < 1)
let diff = try #require(end.value).timeIntervalSince(now) - delay
let diffAbs = abs(diff)
#expect(diffAbs < 0.5)
}
}
}

Expand All @@ -65,7 +67,7 @@ struct DispatchQueueSchedulerTests {
let expectedInterval = delay * Double(index + 1)
let actualInterval = time.timeIntervalSince(now)
let difference = abs(actualInterval - expectedInterval)
#expect(difference < 1)
#expect(difference < 0.5)
}
}
}
Expand Down

0 comments on commit f0c1acb

Please sign in to comment.