fix: sync upstream bug fixes from swift-openapi-urlsession PRs #94 and #95 - #11
Merged
Conversation
…d #95 - Add `cancel(error:)` to `HTTPBodyOutputStreamBridge` so URLSession task errors can be propagated to the stream bridge (PR #94) - Fix `errorOccurred` state machine: `.initial` and `.waitingForBytes` now both close the stream; `.closed` is handled gracefully (PR #95) - Fix `wroteFinalChunk`/`endEncountered`: `.closed` state logs and returns instead of calling `preconditionFailure` (PR #95) - Propagate URLSession errors to the stream bridge in `BidirectionalStreamingURLSessionDelegate.didCompleteWithError` (PR #94) - Replace `NSLock` in `HTTPBody` with the internal pthread-based `Lock` - Add `Scripts/check-upstream.sh` to simplify future upstream syncs
…eterministic wait
The `log()` handler fires `Task { await collector.append(entry) }`, so
entries arrive asynchronously. Using a fixed 100ms sleep was racy —
in `loggingMiddlewareLogsDifferentMethods` the response Task could arrive
before the request Task, causing an order-sensitive `entries[0]` check
to fail.
- Add `waitForEntries(count:)` to `LogCollector` that polls via
`Task.yield()` until the expected number of entries arrive
- Replace all `Task.sleep(for: .milliseconds(100))` calls with it
- Find the request log by content ("⬆️") rather than assuming index 0
- Use `waitForEntries(count: 1)` in the error test (only request is logged)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
HTTPBodyOutputStreamBridge: Added missingcancel(error:)method; fixed state machine so.closedis handled gracefully inerrorOccurred,wroteFinalChunk, andendEncounteredinstead of callingpreconditionFailureBidirectionalStreamingURLSessionDelegate: Propagate URLSession task errors to the stream bridge indidCompleteWithErrorviarequestStream?.cancel(error:)HTTPBody: ReplaceNSLockwith the internal pthread-basedLock(removing ObjC dependency for locking)Scripts/check-upstream.sh: New script to compare upstream files against local copies, making future syncs easy to spotUpstream references
Test plan
swift buildpassesHTTPBodyTests,ClientTests,MiddlewareTests,MultipartFormDataTests,LoggingMiddlewareTests,ErrorTests,HTTPBodyProgressTests)