Skip to content

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

Merged

Conversation

artemredkin
Copy link
Collaborator

Fix missing connect timeout and make some tests faster and safer.

Motivation:

  1. During pool implementation/refactoring we lost connection timeout, this PR fixes that
  2. testConnectionFailError is slow, 10 seconds, due to not having a timeout set
  3. testConnectionFailError and testTLSVersionError use dangerous do-try-XCFail-catch pattern

Modifications:

  1. Set connection timeout if specified
  2. Set connect timeout to 150 ms to make testTLSVersionError faster
  3. Use XCTAssertThrowsError in testConnectionFailError and testTLSVersionError
  4. Add general connection timeout test, since testConnectionFailError is NIOTS-specific.

Result:
Fixes an issue where connection timeout configuration was not respected, hopefully makes tests more robust

@artemredkin artemredkin added this to the 1.2.0 milestone Jun 19, 2020
@artemredkin artemredkin requested review from weissi and Lukasa June 19, 2020 10:38
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):
Copy link
Collaborator Author

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?

Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Copy link
Collaborator

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.

Copy link
Contributor

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

@artemredkin
Copy link
Collaborator Author

failed due to #265

@artemredkin
Copy link
Collaborator Author

@swift-server-bot test this please

Copy link
Contributor

@weissi weissi left a comment

Choose a reason for hiding this comment

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

Thank you LGTM

@artemredkin artemredkin merged commit afe6ae4 into swift-server:master Jun 22, 2020
@artemredkin artemredkin deleted the fix_missing_connect_timeout branch June 22, 2020 15:19
artemredkin added a commit to artemredkin/async-http-client that referenced this pull request Jun 23, 2020
* fix missing connect timeout and make tests safer

* swiftformat and linux tests

* fix timeout test

* speedup another test

* make tests safer
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.

3 participants