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

Misc fix test #248

Merged
merged 10 commits into from
Apr 4, 2021
Merged

Misc fix test #248

merged 10 commits into from
Apr 4, 2021

Conversation

dannys42
Copy link
Contributor

No description provided.

@CLAassistant
Copy link

CLAassistant commented Mar 14, 2021

CLA assistant check
All committers have signed the CLA.

…signment

- SSL initalizer: NIOSSLClientHandler is now initialized with hostname
- end() now assumes default ports based on scheme when not supplied in
  URL string.  (Previously it always assumed 8080?!)
@dannys42
Copy link
Contributor Author

Woohoo! It's passing! Hopefully once merged I'll be able to get the Kitura tests to pass too.

Copy link
Member

@mbarnach mbarnach left a comment

Choose a reason for hiding this comment

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

I would feel better if we could avoid the force unwrapping, otherwise, good job!

@@ -535,11 +535,12 @@ public class ClientRequest {
*/
public func end(close: Bool = false) {
closeConnection = close

let percentEncodedURL = URL(string: self.percentEncodedURL)!
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure about the force unwrapping? It looks dangerously un-recoverable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm also a bit leery about it, but I was opting for minimal changes. I think it will take quite a bit more restructuring to better handle these situations.

var isHTTPS = false

let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
if (URL(string: percentEncodedURL)?.scheme)! == "https" {
if (percentEncodedURL.scheme)! == "https" {
Copy link
Member

Choose a reason for hiding this comment

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

Same here, even if it was already forced before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I don't know how you'd recover from a missing scheme? But I'll take another look... maybe there's a better way.

Copy link
Member

Choose a reason for hiding this comment

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

If we'd have a huge concrete wall of tests, I'd be happy with it, but in its current state my lack of understanding and the code I see scares me too.

But I don't have any better approaches right now either.

Personally I think force unwrapping is fine if there are multiple good quality and self validating unit tests which reason about the implementation and is convincing of its safety.

Otherwise I'd take the route of being super-defensive; and log warnings & errors whenever the sad path kicks in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My goal right now is just to get tests consistently passing. So if you can agree that I at least haven't introduced any new problems, can we save the larger restructuring until later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Curiously the existing code does not use URL() as it's base way of storing URLs. I think one reason for some of the complexity in the code is the way Kitura handles http/https vs Unix domain sockets. If we're keeping this functionality (which I think is nice to have), it might make some of the code easier to follow one of these (non-standard) conventions for naming Unix domain sockets: whatwg/url#577

@@ -10,11 +12,16 @@ if [ $SWIFT_TEST_STATUS -ne 0 ]; then
return $SWIFT_TEST_STATUS
fi

# For now, short-circuit kitura tests until those are stabalized.
return 0
Copy link
Member

Choose a reason for hiding this comment

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

I've create issue #249 to remember that...

Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest to add a // TODO: statement as well. Most IDEs collect and aggregate them. I for example use CLion, and this way I won't lose track of unkept promises.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -10,11 +12,16 @@ if [ $SWIFT_TEST_STATUS -ne 0 ]; then
return $SWIFT_TEST_STATUS
fi

# For now, short-circuit kitura tests until those are stabalized.
return 0
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest to add a // TODO: statement as well. Most IDEs collect and aggregate them. I for example use CLion, and this way I won't lose track of unkept promises.

@@ -15,17 +15,23 @@ matrix:
dist: xenial
sudo: required
services: docker
env: DOCKER_IMAGE=swift:5.0.3-xenial SWIFT_SNAPSHOT=5.0.3 DOCKER_PRIVILEGED=true SWIFT_TEST_ARGS="--parallel"
env: DOCKER_IMAGE=docker.kitura.net/kitura/swift-ci:5.0.3 SWIFT_SNAPSHOT=5.0.3 DOCKER_PRIVILEGED=true SWIFT_TEST_ARGS="--parallel"
Copy link
Member

Choose a reason for hiding this comment

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

wow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

?

var isHTTPS = false

let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
if (URL(string: percentEncodedURL)?.scheme)! == "https" {
if (percentEncodedURL.scheme)! == "https" {
Copy link
Member

Choose a reason for hiding this comment

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

If we'd have a huge concrete wall of tests, I'd be happy with it, but in its current state my lack of understanding and the code I see scares me too.

But I don't have any better approaches right now either.

Personally I think force unwrapping is fine if there are multiple good quality and self validating unit tests which reason about the implementation and is convincing of its safety.

Otherwise I'd take the route of being super-defensive; and log warnings & errors whenever the sad path kicks in.

portNumber = 80
} else {
portNumber = 8080
Log.error("Unknown port for url: \(url) Assuming 8080")
Copy link
Member

Choose a reason for hiding this comment

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

Well, technically it's not an error, since you have recovered in a transparent & seamless way.
I'd suggest implementing it as a warning instead of an error.

Copy link
Contributor Author

@dannys42 dannys42 Mar 28, 2021

Choose a reason for hiding this comment

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

That's true... but at the same time I don't think having a default 8080 port makes any sense. I kept it there to avoid introducing more error paths and since the previous code had it. You think it should be a warning instead of an error? I'll add a comment to keep people from relying on this behavior.

portNumber = 8080
Log.error("Unknown port for url: \(url) Assuming 8080")
}
}
if self.headers["Host"] == nil {
let isNotDefaultPort = (portNumber != 443 && portNumber != 80) //Check whether port is not 443/80
Copy link
Member

Choose a reason for hiding this comment

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

This whole play of port literals gave me an idea:

We could introduce a small harmless enum in one of the Kitura base modules which would encapsulate the typical ports and give names to them?

The bigger benefit is that it could open the door for future additional features to port handling without change risks.

@dannys42 && @mbarnach what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I like the idea: it makes it more obvious (like which port is the default for Kitura), but also keep tracks of standard and custom ports in a robust fashion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm.. you mean an enum equivalent to the /etc/services file? Might be interesting, but not sure it belongs in Kitura since Kitura really only deals with web traffic?

Copy link
Member

Choose a reason for hiding this comment

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

The way I understand it is: instead of 80, you have something like .http and instead of 443, .https. For 8080, it would be .default (names are poorly chosen!). It could also be extended to use .localhost and .domain(let custom) for the hostnames. Feature wise, the same, but better to add semantic and group the value in a single place. As part of the port enum, the var isDefaultPort: Bool { self == .http || self == .https } could be introduced.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another idea, if we're using URL() as a base type, then adding an extension for "isStandardPort" where we can check that if a port was given that it matches the standard for the given scheme. It might also be interesting to do a run-time check of /etc/services rather than having a hard-coded database.

Anyway I think this is a future project. Okay to punt on this for now?

@mbarnach
Copy link
Member

@dannys42 Shall we create the tickets to keep track of those and merge the PR?

@dannys42
Copy link
Contributor Author

dannys42 commented Apr 2, 2021

Created an issue to keep track of the various topics discussed here: #250

@sonarcloud
Copy link

sonarcloud bot commented Apr 3, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@dannys42
Copy link
Contributor Author

dannys42 commented Apr 3, 2021

I'm not sure why, but with Xcode 10.3, swift-nio-ssl doesn't build properly. Looking at the source, it should be requiring macOS 10.15, but Travis-CI's Xcode 10.3 image is clearly running macOS 10.14. So I'm not sure why there was an issue. I'm just going to deprecate Xcode 10.3. We do see that Swift 5.0.1 still builds fine on Linux so I think this is probably fine.

@dannys42 dannys42 merged commit d870257 into Kitura:master Apr 4, 2021
@dannys42 dannys42 deleted the MISC-fix_test branch April 4, 2021 05:22
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.

4 participants