Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Async calls from AsyncHTTPClient #555

Merged
merged 5 commits into from
Jun 22, 2023
Merged

Use Async calls from AsyncHTTPClient #555

merged 5 commits into from
Jun 22, 2023

Conversation

adam-fowler
Copy link
Member

@adam-fowler adam-fowler commented Jun 20, 2023

This was complex. Trying to return back the AsyncSequence from AHC in a generic way until I found AnyAsyncSequence in AHC. This simplified passing the body back from AHC through my own types.

  • Added AnyAsyncSequence as a generic method for passing AsyncSequences about.
  • Added ByteBufferAsyncSequence as a way to convert a ByteBuffer into an AsyncSequence of ByteBuffer slices.
  • Added HTTPBody to hold response payloads. This'll probably be also used in requests but I haven't got to that yet. If so I'll rename back to AWSPayload for some consistency. The HTTPBody no longer defines the type of data it holds (eg xml, json, raw data) this data is got from the serviceProtocol

Streaming requests and response currently don't work, so related code and tests may be commented out

@adam-fowler adam-fowler requested a review from 0xTim June 20, 2023 15:17
@codecov
Copy link

codecov bot commented Jun 20, 2023

Codecov Report

Merging #555 (f4f2f5c) into 7.x.x (6a566f1) will decrease coverage by 5.64%.
The diff coverage is 76.58%.

@@            Coverage Diff             @@
##            7.x.x     #555      +/-   ##
==========================================
- Coverage   77.17%   71.54%   -5.64%     
==========================================
  Files          75       76       +1     
  Lines        7860     7847      -13     
==========================================
- Hits         6066     5614     -452     
- Misses       1794     2233     +439     
Impacted Files Coverage Δ
Sources/SotoCore/AWSClient+EndpointDiscovery.swift 42.39% <ø> (ø)
Sources/SotoCore/AWSClient+Paginate.swift 100.00% <ø> (ø)
...rces/SotoCore/Concurrency/ByteBufferSequence.swift 0.00% <0.00%> (ø)
Sources/SotoCore/HTTP/AWSHTTPTypes.swift 70.00% <65.90%> (-30.00%) ⬇️
Sources/SotoCore/HTTP/AsyncHTTPClient.swift 89.65% <90.47%> (+0.26%) ⬆️
Sources/SotoCore/AWSClient.swift 81.55% <92.85%> (-12.00%) ⬇️
...ources/SotoCore/Concurrency/AnyAsyncSequence.swift 100.00% <100.00%> (ø)
...toCore/Credential/MetaDataCredentialProvider.swift 91.59% <100.00%> (+0.14%) ⬆️
Sources/SotoCore/Message/AWSResponse.swift 94.91% <100.00%> (-0.04%) ⬇️

... and 11 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

XCTFail("Unexpected error: \(error)")
}
}
/* func testRequestStreaming() async throws {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to be added back in or deleted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have made it clear streaming requests/responses don't work yet. They will the subject of the next few PRs. So I commented out the tests that would fail and will uncomment them as features are implemented.

_ = try await responseTask
XCTAssertEqual(countAtomic.load(ordering: .relaxed), 0)
}
/* func testStreamingResponse() async {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

let eventLoop = eventLoop ?? self.eventLoopGroup.any()
return try await self.execute(request: request, timeout: timeout, on: eventLoop, logger: logger, stream: stream).get()
) async throws -> HTTPClientResponse {
preconditionFailure("Not supported")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just remove this if it's not supported?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will get removed in the next PR. Currently it a stub used by another section of code

Comment on lines +37 to +41
/* case .asyncSequence(let sequence, let length):
requestBody = .stream(
sequence,
length: length.map { .known($0) } ?? .unknown
) */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is commented out while streaming requests don't work. It will be re-instated when I get them working

@adam-fowler
Copy link
Member Author

Fixed the tests. There was a weird interaction between the test server which can only receive one request at a time and me not flush the response body when I don't expect one

@adam-fowler adam-fowler requested a review from 0xTim June 20, 2023 20:15
@adam-fowler adam-fowler merged commit e9bf08c into 7.x.x Jun 22, 2023
@adam-fowler adam-fowler deleted the async-http-client branch June 22, 2023 07:46
adam-fowler added a commit that referenced this pull request Jul 5, 2023
* Use async HTTPClient calls

Currently streaming is not working

* Comments

* Extract HTTPBody out so it can be used in request

* Flush body, when not expecting anything

* Remove eventLoop from function comment headers
adam-fowler added a commit that referenced this pull request Jul 5, 2023
* Use async HTTPClient calls

Currently streaming is not working

* Comments

* Extract HTTPBody out so it can be used in request

* Flush body, when not expecting anything

* Remove eventLoop from function comment headers
adam-fowler added a commit that referenced this pull request Jul 5, 2023
* Use async HTTPClient calls

Currently streaming is not working

* Comments

* Extract HTTPBody out so it can be used in request

* Flush body, when not expecting anything

* Remove eventLoop from function comment headers
adam-fowler added a commit that referenced this pull request Jul 5, 2023
* Use async HTTPClient calls

Currently streaming is not working

* Comments

* Extract HTTPBody out so it can be used in request

* Flush body, when not expecting anything

* Remove eventLoop from function comment headers
adam-fowler added a commit that referenced this pull request Jul 24, 2023
* Use async HTTPClient calls

Currently streaming is not working

* Comments

* Extract HTTPBody out so it can be used in request

* Flush body, when not expecting anything

* Remove eventLoop from function comment headers
adam-fowler added a commit that referenced this pull request Jul 29, 2023
* Use async HTTPClient calls

Currently streaming is not working

* Comments

* Extract HTTPBody out so it can be used in request

* Flush body, when not expecting anything

* Remove eventLoop from function comment headers
adam-fowler added a commit that referenced this pull request Aug 12, 2023
* Use async HTTPClient calls

Currently streaming is not working

* Comments

* Extract HTTPBody out so it can be used in request

* Flush body, when not expecting anything

* Remove eventLoop from function comment headers
adam-fowler added a commit that referenced this pull request Dec 24, 2023
* Use async HTTPClient calls

Currently streaming is not working

* Comments

* Extract HTTPBody out so it can be used in request

* Flush body, when not expecting anything

* Remove eventLoop from function comment headers
adam-fowler added a commit that referenced this pull request Apr 5, 2024
* Use async HTTPClient calls

Currently streaming is not working

* Comments

* Extract HTTPBody out so it can be used in request

* Flush body, when not expecting anything

* Remove eventLoop from function comment headers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants