Skip to content

[HTTP2] More Integration Tests #471

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

Merged
merged 9 commits into from
Nov 11, 2021

Conversation

dnadoba
Copy link
Collaborator

@dnadoba dnadoba commented Nov 10, 2021

No description provided.

Comment on lines 263 to 262
XCTAssertThrowsError(try task.futureResult.timeout(after: .seconds(2)).wait(), "Should fail") { error in
guard case let error = error as? HTTPClientError, error == .cancelled else {
return XCTFail("Should fail with cancelled")
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
XCTAssertThrowsError(try task.futureResult.timeout(after: .seconds(2)).wait(), "Should fail") { error in
guard case let error = error as? HTTPClientError, error == .cancelled else {
return XCTFail("Should fail with cancelled")
}
}
XCTAssertThrowsError(try task.futureResult.timeout(after: .seconds(2)).wait()) {
XCTAssertEqual($0 as? HTTPClientError, . cancelled)
}

Comment on lines 232 to 236
if let clientError = error as? HTTPClientError, clientError == .cancelled {
continue
} else {
XCTFail("Unexpected error: \(error)")
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if let clientError = error as? HTTPClientError, clientError == .cancelled {
continue
} else {
XCTFail("Unexpected error: \(error)")
}
XCTAssert(error as? HTTPClientError, .cancelled)

Comment on lines 301 to 296
XCTAssertThrowsError(try task.futureResult.timeout(after: .seconds(2)).wait(), "Should fail") { error in
guard case let error = error as? HTTPClientError, error == .cancelled else {
return XCTFail("Should fail with cancelled")
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
XCTAssertThrowsError(try task.futureResult.timeout(after: .seconds(2)).wait(), "Should fail") { error in
guard case let error = error as? HTTPClientError, error == .cancelled else {
return XCTFail("Should fail with cancelled")
}
}
XCTAssertThrowsError(try task.futureResult.timeout(after: .seconds(2)).wait()) {
XCTAssertEqual($0 as? HTTPClientError, .cancelled)
}

Comment on lines 816 to 819
case "/sendheaderandwait":
// sends some headers and waits indefinitely afterwards
context.writeAndFlush(wrapOutboundOut(.head(HTTPResponseHead(version: HTTPVersion(major: 1, minor: 1), status: .ok))), promise: nil)
return
Copy link
Member

Choose a reason for hiding this comment

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

Please create a small ChannelInboundHandler for this in the specific test case. There is so much stuff in this single handler and all is mixed.

}

var backpressureEventLoop: EventLoop?
var stateDidChangeCallback: ((State) -> Void)?
Copy link
Member

Choose a reason for hiding this comment

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

this should be at least a let. however in your tests your mainly using this to get a callback once the head was received. I think, a specialized delegate only for this one job, might be a better idea.

@dnadoba dnadoba force-pushed the dn-http2-intergration-tests branch 2 times, most recently from 02d3a90 to 1323450 Compare November 10, 2021 16:11
@@ -67,7 +82,7 @@ class HTTP2ClientTests: XCTestCase {
func testConcurrentRequestsFromDifferentThreads() {
let bin = HTTPBin(.http2(compress: false))
defer { XCTAssertNoThrow(try bin.shutdown()) }
let client = self.makeDefaultHTTPClient()
let client = self.makeClientWithActiveHTTP2Connection(to: bin)
Copy link
Member

Choose a reason for hiding this comment

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

why do we need a client with an active connection?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch, we don't.

Copy link
Member

@fabianfett fabianfett left a comment

Choose a reason for hiding this comment

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

Three small things at the end.

Comment on lines 380 to 389
context.writeAndFlush(wrapOutboundOut(.head(HTTPResponseHead(
version: HTTPVersion(major: 1, minor: 1),
status: .ok
))
), promise: nil)
Copy link
Member

Choose a reason for hiding this comment

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

This will send at least two response headers for each request... you'll need to unwrap the incoming requests for .head and .end

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

could we also use channelActive instead?

Copy link
Member

@fabianfett fabianfett Nov 11, 2021

Choose a reason for hiding this comment

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

nope... you need to wait for the request. you can not assume to get a request as soon as the channel become active.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

okay thanks, we now only send it after we received .end.

Comment on lines 52 to 55
init(
backpressureEventLoop: EventLoop? = nil,
stateDidChangeCallback: ((State) -> Void)? = nil
) {
Copy link
Member

Choose a reason for hiding this comment

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

I think all changes in this file can now be reverted, can't they?

}

/// sends some headers and waits indefinitely afterwards
private final class SendHeaderAndWaitChannelHandler: ChannelInboundHandler {
Copy link
Member

Choose a reason for hiding this comment

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

oh we should use this one to test idleReadTimeout as well. can be another pr.

@dnadoba dnadoba force-pushed the dn-http2-intergration-tests branch from c67e336 to c82a3a5 Compare November 11, 2021 10:08
@fabianfett fabianfett added the semver/none No version bump required. label Nov 11, 2021
@fabianfett fabianfett added this to the HTTP/2 support milestone Nov 11, 2021
@dnadoba dnadoba merged commit 38bbe25 into swift-server:main Nov 11, 2021
@dnadoba dnadoba deleted the dn-http2-intergration-tests branch November 11, 2021 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/none No version bump required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants