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

Upgrade ContainerPilot to Go 1.9.x and Consul 1.0.x #527

Merged
merged 6 commits into from
Nov 14, 2017

Conversation

jwreagor
Copy link
Contributor

@jwreagor jwreagor commented Nov 12, 2017

Ref: #519

This is a WIP PR.

EDIT: Note that Consul is pegged at 1.0.1-rc1 and we'll want to finalize once a GM is released.

@jwreagor jwreagor changed the title Upgrade ContainerPilot to Go 1.9.x and Consul 1.0.0 ~ WIP Upgrade ContainerPilot to Go 1.9.x and Consul 1.0.1 Nov 12, 2017
defer testServer.Stop()

time.Sleep(300 * time.Millisecond)
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 not crazy about this and would much rather add something that checks for Consul's HTTP API endpoint being live. Any suggestions on that?

Choose a reason for hiding this comment

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

Query localhost:8500/v1/status/leader for a non-empty 200 OK response but do that as part of the Start() call. You can use/clone the testutil/retry package for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Our tests don't require leadership election so I was able to just throw a naive GET request at /v1/agent/self which also uses testutil/retry.

@jwreagor
Copy link
Contributor Author

@magiconair Last commit in this PR adds the exec for consul. Let me know any suggestions you have.

Also, I didn't yet remove the old dependencies from our dep manager. I'll do that after we've discussed the patch.

"consul or skip this test")
}

args := []string{"agent", "-dev"}

Choose a reason for hiding this comment

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

You're not configuring the port. Add "-http-port", strconv.Itoa(httpPort) to args

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doh!

return nil, errors.New("failed starting command")
}

httpAddr := fmt.Sprintf("127.0.0.1:%d", httpPort)

Choose a reason for hiding this comment

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

You can inline this in the struct definition.

return &TestServer{cmd, fmt.Sprintf("127.0.0.1:%d", httpPort)}, nil

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 have a personal preference around inlining. Normally I enjoy the extra bits for readability and searching. In this case I agree, the line can be kept fairly short. 👍

defer testServer.Stop()

time.Sleep(300 * time.Millisecond)

Choose a reason for hiding this comment

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

Query localhost:8500/v1/status/leader for a non-empty 200 OK response but do that as part of the Start() call. You can use/clone the testutil/retry package for that.

@@ -77,18 +77,18 @@ a Consul server for testing. The 'consul' binary must be in the $PATH
ref https://github.com/hashicorp/consul/tree/master/testutil
*/

var testServer *testutil.TestServer
var testServer *TestServer

Choose a reason for hiding this comment

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

Don't use global state for tests. Pass the test server or better just the http address into the sub tests since that is all they need AFAICT.

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 agree, artifact of the previous implementation.

Justin Reagor added 5 commits November 13, 2017 14:59
While upgrading Consul to version 1.0.0 I found that our tests caused a null
pointer exception if there's an error configuring a Consul process to test
against. This was due to the fact that we were ignoring errors when configuring
Consul and continuing forward as if Consul was functional. This commit properly
causes a fatal return from the test and includes the actual error returned by
Consul's own internal testing framework (which we use for bootstrapping our
own testing).
This commit removes the use case within the discovery package's tests that
depended on an internal Consul test package, `testutil`. We replace this with
our own TestServer object which is responsible for executing a locally installed
`consul` binary. Consul is installed by our Makefile target `tools` for local
development use.

Ref: TritonDataCenter#528
* Don't use a global variable in tests
* Actually use HTTP port passed into `TestServer`
* Use `testutil/retry` for waiting for the HTTP API to come up
* Inline returned struct definition within `NewTestServer`
@jwreagor
Copy link
Contributor Author

Rebased against latest master and added @magiconair's CR comments. I also backed down to pinning Consul v1.0.0.

I believe we're in good shape.

@jwreagor jwreagor changed the title Upgrade ContainerPilot to Go 1.9.x and Consul 1.0.1 Upgrade ContainerPilot to Go 1.9.x and Consul 1.0.x Nov 14, 2017
@jwreagor jwreagor merged commit 4f9845a into TritonDataCenter:master Nov 14, 2017
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.

2 participants