-
Notifications
You must be signed in to change notification settings - Fork 506
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
Replace the current e2e script with a test suite running e2e tests. #1514
Conversation
Assigned myself to remember to try this out and go over it in more detail. But I like it. |
@robjloranger @arschles any chance to give a push to this? |
I'm so sorry @fedepaol, I missed it again. I've been working too much at my day job. I will do this on the weekend at the latest. |
@robjloranger no problem! I was just going through blocked PRs of mine and I remembered about this. Take your time, and thanks! |
testing now, finally |
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.
Looks good to me, other than one line ending 😃
appveyor.yml
Outdated
- go test --tags unittests ./... |
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.
silly newline missing
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.
Done
Thanks for your review 👍 |
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.
just waiting for the drone ci to pass
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.
Just the one comment, but otherwise nice work :)
.drone.yml
Outdated
@@ -28,7 +28,7 @@ steps: | |||
# test | |||
- ./scripts/check_gofmt.sh | |||
- go vet ./... | |||
- go test -v ./... | |||
- go test --tags unittests -v ./... |
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.
Just checking: this means that go test ./...
will always try to run e2e tests no?
In other words, everytime you want to run the unit tests you have to pass that tag.
If that's true, then it would be more correct to say go test --tags e2e
instead . Thoughts?
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 call, if true then defaulting to unit tests and hiding e2e behind a flag would be a better UX.
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 point, and I agree. I will change the build tag to be selective for e2e tests, so the default one is for plain unit tests.
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.
Thanks for doing this :) I think the PR can definitely use some tightening up but otherwise awesome work 👍
e2etests/run_athens.go
Outdated
"time" | ||
) | ||
|
||
func buildAthens(goBin string, destPath string, env []string) (string, 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.
nit: goBin, destPath string
-- no need to declare the type twice.
} | ||
|
||
cmd := exec.Command(goBin, "build", "-o", target, binFolder) | ||
cmd.Env = env |
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'd add a bytes.Buffer to cmd.Stderr and return it in case of error because then it will explain why go build failed.
e2etests/run_athens.go
Outdated
|
||
func stopAthens() error { | ||
cmd := exec.Command("pkill", "athens-proxy") | ||
err := cmd.Run() |
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'd either just return cmd.Run()
or properly populate stdout/stderr
e2etests/run_athens.go
Outdated
cmd := exec.Command(athensBin) | ||
cmd.Env = env | ||
|
||
go func() { |
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 not just go cmd.Run()
?
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.
and if you are trying to run the command in the background, it is more appropriate to use cmd.Start(): https://golang.org/pkg/os/exec/#Cmd.Start
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.
and if you are trying to run the command in the background, it is more appropriate to use cmd.Start(): https://golang.org/pkg/os/exec/#Cmd.Start
Ah, nice!
e2etests/run_athens.go
Outdated
}() | ||
|
||
ticker := time.NewTicker(time.Second) | ||
timeout := time.After(2 * time.Minute) |
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.
two minutes seems a lil crazy to wait for athens to start 😄 -- let's make it 20 seconds?
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.
Sorry, I am getting deviated to k8s timescales
return target, err | ||
} | ||
|
||
func stopAthens() 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.
I think a better way to "stopAthens" is to have the runAthensAndWait take a context that you can cancel whenever you want to stop athens and just pass that context into https://golang.org/pkg/os/exec/#CommandContext
which should render this whole function unnecessary.
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.
Did not know about it, thanks!
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.
Well, yes and no, as I am using stopAthens also to remove any dangling instance before running the real tests. So it's ok for the teardown phase, but I'll keep this around as well.
e2etests/all_test.go
Outdated
if err != nil { | ||
m.Fail("Failed to stop athens", err) | ||
} | ||
chmodR(m.tmpDir, 0777) |
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 a cleaner way to do this is to just call clean modcache -- I think we should probably do it on the go_get_fetcher as well. But that's another topic :)
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 do agree to clear the cache instead of brutally erasing in SetupTest
, as there we care only about the cache to be empty.
In TearDown
though, I'd like to remove any additional folder that was created by the test suite, and I am afraid clearing the cache is not enough.
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.
@fedepaol right you can still remove the folder, but there won't be a need to chmod
anything :)
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.
Yes I left it there as I did not remember why I added originally. I'll try to remove it and see if it works :-)
e2etests/all_test.go
Outdated
m.Fail("Failed to make temp dir", err) | ||
} | ||
|
||
m.goModCache = path.Join(m.tmpDir, "pkg", "mod") |
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 would probably make two temp directories to maintain a nicer separation: one for GOPATH and one outside of GOPATH for happy-path. This way you don't to actually care about the "pkg/mod" part here, and cleaning the cache only needs to take the GOPATH env var and nothing else
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.
Done
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.
@fedepaol sorry I got sidetracked and didn't review this. It looks great 🎉 🚀 ! @marwan-at-work can we address your comments in a follow-up PR? I can submit it if @fedepaol. I would love to get this into master so that I can expand on the tests...
@arschles I think I addressed all the comments in my latest push of yesterday. |
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.
e2etests/all_test.go
Outdated
suite.Suite | ||
goBinaryPath string | ||
env []string | ||
tmpDir string |
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'd call it goPath
or GOPATH
to know what the tmpDir is for :)
// ignoring error as if no athens is running it fails. | ||
|
||
ctx := context.Background() | ||
ctx, m.stopAthens = context.WithCancel(ctx) |
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.
Form the context package docs:
Do not store Contexts inside a struct type; instead, pass a Context explicitly to each function that needs it. The Context should be the first parameter.
I realize storing the context is necessary here because of testify/suite, but I'd rather we followed best practices instead of having the framework steer us away form that.
That said, we can definitely do it in a follow up PR because it means removing the test suite from the e2e tests :)
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.
Ah right. That would make things less easy. Not even sure if it's worth reverting to the previous stopAthens
, as even if we remove testify having a propagated context will bloat the code a bit.
We want e2e tests to be skipped while running normal unit tests.
@marwan-at-work I applied the change suggested in #1514 (comment) . |
@fedepaol IMHO the best way is to just use the standard library because the std lib wouldn't get in your way the same way this test suite does :) That said, we can keep things the way they are because it works, then remove them and use regular table tests a follow up pr |
Ok, we can discuss those details later then. Thanks again for your review! |
So this can be merged right? |
@fedepaol thank you * 💯 for your hard work on this PR! |
Heads up this did break the
|
@mplachter would it help if I go ahead and fix |
What is the problem I am trying to address?
Right now the e2e tests are performed by a non trivial bash script, difficult to extend with new tests.
This pr replace it with a go - baked e2e test suite, right now adding the same tests we have in the bash script plus one using a wrong
GOPROXY
variable.This should be easier to maintain / extend.
How is the fix applied?
By implementing a new test suite that builds athens and interacts directly with go.
Mention the issue number it fixes or add the details of the changes if it doesn't have a specific issue.
Fixes #1474