-
Notifications
You must be signed in to change notification settings - Fork 123
fix missing connect timeout and make tests safer #267
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
fix missing connect timeout and make tests safer #267
Conversation
XCTFail("Error should have been ChannelError.connectTimeout not \(type(of: error))") | ||
XCTAssertThrowsError(try httpClient.get(url: "https://localhost:\(port)/get").wait()) { error in | ||
switch error { | ||
case ChannelError.connectTimeout(let timeout): |
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.
@weissi do you know if there is a safer pattern for this case, where enum has an associated value?
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.
What don't you like about this pattern?
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 is potentially dangerous, if you miss the XCTFail
call in the default clause, you might miss when the test breaks. This is why I'm replacing do-try-XCTFail-catch
pattern with XCTAssertThrowsError
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 see what you mean. No, there isn't really a better pattern here sadly.
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 usually do this
XCTAssertEqul(.connectTimeout(.milliSeconds(150)), error as? ChannelError)
as it's much safer
failed due to #265 |
@swift-server-bot test this please |
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.
Thank you LGTM
* fix missing connect timeout and make tests safer * swiftformat and linux tests * fix timeout test * speedup another test * make tests safer
Fix missing connect timeout and make some tests faster and safer.
Motivation:
testConnectionFailError
is slow, 10 seconds, due to not having a timeout settestConnectionFailError
andtestTLSVersionError
use dangerousdo-try-XCFail-catch
patternModifications:
testTLSVersionError
fasterXCTAssertThrowsError
intestConnectionFailError
andtestTLSVersionError
testConnectionFailError
is NIOTS-specific.Result:
Fixes an issue where connection timeout configuration was not respected, hopefully makes tests more robust