Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiBM committed Oct 13, 2024
1 parent 3502459 commit f5f0ffc
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Tests/PennyTests/Fake/FakeResponseStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ actor FakeResponseStorage {
private var continuations = Continuations()
private var unhandledResponses = UnhandledResponses()

static var shared: FakeResponseStorage!
static var shared = FakeResponseStorage()

private static let idGenerator = ManagedAtomic(UInt(0))

Expand Down Expand Up @@ -50,7 +50,7 @@ actor FakeResponseStorage {
sourceLocation: Testing.SourceLocation
) {
self.backgroundRunner.process {
await _expect(
await self._expect(
at: endpoint,
expectFailure: expectFailure,
continuation: continuation,
Expand All @@ -68,7 +68,7 @@ actor FakeResponseStorage {
if let response = unhandledResponses.retrieve(endpoint: endpoint) {
if expectFailure {
Issue.record(
"Was expecting a failure at '\(endpoint.testingKey)'. continuations: \(continuations) | unhandledResponses: \(unhandledResponses)",
"Was expecting a failure at '\(endpoint.testingKey)'. continuations: \(self.continuations) | unhandledResponses: \(self.unhandledResponses)",
sourceLocation: sourceLocation
)
continuation.resume(returning: AnyBox(Optional<Never>.none as Any))
Expand All @@ -80,10 +80,10 @@ actor FakeResponseStorage {
continuations.append(endpoint: endpoint, id: id, continuation: continuation)
self.backgroundRunner.process {
try? await Task.sleep(for: .seconds(3))
if continuations.retrieve(id: id) != nil {
if await self.retrieveFromContinuations(id: id) != nil {
if !expectFailure {
Issue.record(
"Penny did not respond in-time at '\(endpoint.testingKey)'. continuations: \(continuations) | unhandledResponses: \(unhandledResponses)",
"Penny did not respond in-time at '\(endpoint.testingKey)'. continuations: \(await self.continuations) | unhandledResponses: \(await self.unhandledResponses)",
sourceLocation: sourceLocation
)
}
Expand All @@ -92,15 +92,19 @@ actor FakeResponseStorage {
} else {
if expectFailure {
Issue.record(
"Expected a failure at '\(endpoint.testingKey)'. continuations: \(continuations) | unhandledResponses: \(unhandledResponses)",
"Expected a failure at '\(endpoint.testingKey)'. continuations: \(await self.continuations) | unhandledResponses: \(await self.unhandledResponses)",
sourceLocation: sourceLocation
)
}
}
}
}
}


private func retrieveFromContinuations(id: UInt) -> Continuations.Cont? {
self.continuations.retrieve(id: id)
}

/// Used to notify this storage that a response have been received.
func respond(to endpoint: any Endpoint, with payload: AnyBox) {
if let continuation = continuations.retrieve(endpoint: endpoint) {
Expand Down

0 comments on commit f5f0ffc

Please sign in to comment.