-
Notifications
You must be signed in to change notification settings - Fork 123
[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
[HTTP2] More Integration Tests #471
Conversation
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") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) | |
} |
if let clientError = error as? HTTPClientError, clientError == .cancelled { | ||
continue | ||
} else { | ||
XCTFail("Unexpected error: \(error)") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if let clientError = error as? HTTPClientError, clientError == .cancelled { | |
continue | |
} else { | |
XCTFail("Unexpected error: \(error)") | |
} | |
XCTAssert(error as? HTTPClientError, .cancelled) |
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") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) | |
} |
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 |
There was a problem hiding this comment.
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)? |
There was a problem hiding this comment.
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.
02d3a90
to
1323450
Compare
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
context.writeAndFlush(wrapOutboundOut(.head(HTTPResponseHead( | ||
version: HTTPVersion(major: 1, minor: 1), | ||
status: .ok | ||
)) | ||
), promise: nil) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
init( | ||
backpressureEventLoop: EventLoop? = nil, | ||
stateDidChangeCallback: ((State) -> Void)? = nil | ||
) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
we needed an event loop group which outlives the http client
c67e336
to
c82a3a5
Compare
No description provided.