Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ final class BidirectionalStreamingURLSessionDelegate: NSObject, URLSessionTaskDe
{
callbackLock.withLock {
debug("Task delegate: didReceive response")
self.responseContinuation?.resume(returning: response)
responseContinuation?.resume(returning: response)
responseContinuation = nil
return .allow
}
}
Expand All @@ -173,7 +174,10 @@ final class BidirectionalStreamingURLSessionDelegate: NSObject, URLSessionTaskDe
callbackLock.withLock {
debug("Task delegate: didCompleteWithError (error: \(String(describing: error)))")
responseBodyStreamSource.finish(throwing: error)
if let error { responseContinuation?.resume(throwing: error) }
if let error {
responseContinuation?.resume(throwing: error)
responseContinuation = nil
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ class URLSessionBidirectionalStreamingTests: XCTestCase {
}
}

func testStreamingDownload_1kChunk_100Chunks_100BDownloadWatermark() async throws {
try await testStreamingDownload(
responseChunk: (1...1024).map { _ in .random(in: (.min..<(.max))) }[...],
numResponseChunks: 100,
responseStreamWatermarks: (low: 100, high: 100),
verification: .none
)
}

func testStreamingDownload_1kChunk_10kChunks_100BDownloadWatermark() async throws {
try await testStreamingDownload(
responseChunk: (1...1024).map { _ in .random(in: (.min..<(.max))) }[...],
Expand Down Expand Up @@ -306,6 +315,8 @@ class URLSessionBidirectionalStreamingTests: XCTestCase {
case count
// Add some artificial delay to simulate business logic to show how the backpressure mechanism works (or not).
case delay(TimeAmount)
// Do no verification: useful for just pulling as fast as possible for testing for races.
case none
}

func testStreamingDownload(
Expand Down Expand Up @@ -389,6 +400,7 @@ class URLSessionBidirectionalStreamingTests: XCTestCase {
print("Client doing fake work for \(delay)s")
try await Task.sleep(nanoseconds: UInt64(delay.nanoseconds))
}
case .none: break
}

group.cancelAll()
Expand Down