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

Fix tests for nomad/client/driver/spawn package to work on Windows. #442

Merged
merged 4 commits into from
Nov 20, 2015
Merged

Fix tests for nomad/client/driver/spawn package to work on Windows. #442

merged 4 commits into from
Nov 20, 2015

Conversation

ChrisHines
Copy link
Contributor

With these changes, all tests for this package pass on Windows.

Changes to improve test portability:

  • Close temp files so os.Remove works on Windows.
  • Add a TestMain that provides portable echo and sleep commands for use by tests.
  • Enabled TestSpawn_SetsLogs on Windows, as it passes now.

Other changes:

  • Moved several defer f.Close() calls after the if err != nil {...} check.
  • Added a call to t.Parallel() in tests to reduce test run time.

switch cmd := os.Args[1]; cmd {
case "echo":
fmt.Println(strings.Join(os.Args[2:], " "))
case "sleep":
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. I was trying to figure out how to do this on Windows and I found a bunch of hacks, but this one should be fairly portable in our case.

@cbednarski cbednarski added this to the v0.2.1 milestone Nov 18, 2015
}
}

func TestSpawn_SetsLogs(t *testing.T) {
// TODO: Figure out why this test fails. If the spawn-daemon directly writes
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity was the fix doing the Close?

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 am not sure. I just checked out master at a point before these changes and removed the call to t.Skip. With that code go test fails on my machine because "echo" isn't available on the path.

C:\nomadproject\src\github.com\hashicorp\nomad\client\driver\spawn>git describe
v0.1.2-615-g9db262f

C:\nomadproject\src\github.com\hashicorp\nomad\client\driver\spawn>go test -v -run SetsLogs
=== RUN   TestSpawn_SetsLogs
--- FAIL: TestSpawn_SetsLogs (0.03s)
        spawn_test.go:60: Spawn() failed: Failed to execute user command: Error starting user command: exec: "echo": executable file not found in %PATH%
FAIL
exit status 1
FAIL    github.com/hashicorp/nomad/client/driver/spawn  0.118s

So I would say the fix was adding TestMain and using the binary constructed by go test as a self packaged portable echo.

But the TODO comment seems to indicate that you had experienced a different type of failure where the echo command could be found—maybe go test was running in a Cygwin or msys shell—but couldn't write to the log file for some reason. So the problem doesn't seem to reproduce the same way for me.

@dadgar
Copy link
Contributor

dadgar commented Nov 19, 2015

Looks good. Want to see what you do to make the TestMain/appMain more general. This is a problem even for client/task_runner/alloc_runner tests.

@ChrisHines
Copy link
Contributor Author

There is a pattern for TestMain/appMain forming. I expect we can eventually factor out a DRY version of appMain to reuse across all the tests that need portable test tasks, but I'd rather make a new PR for that later, once I've got all the use cases figured out.

@dadgar
Copy link
Contributor

dadgar commented Nov 20, 2015

LGTM

dadgar added a commit that referenced this pull request Nov 20, 2015
Fix tests for nomad/client/driver/spawn package to work on Windows.
@dadgar dadgar merged commit ef013c5 into hashicorp:master Nov 20, 2015
@ChrisHines ChrisHines deleted the windows-spawn branch November 23, 2015 20:16
benbuzbee pushed a commit to benbuzbee/nomad that referenced this pull request Jul 21, 2022
@github-actions
Copy link

github-actions bot commented May 2, 2023

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants