Skip to content

Commit

Permalink
Merge pull request #8083 from hashicorp/test-deflake-20200531
Browse files Browse the repository at this point in the history
More Test deflaking - 2020-05-31 edition
  • Loading branch information
Mahmood Ali authored Jun 1, 2020
2 parents 06baadd + 2f1c63e commit 9ace1c8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
31 changes: 27 additions & 4 deletions api/internal/testutil/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/http"
"os"
"os/exec"
"time"

cleanhttp "github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/nomad/api/internal/testutil/discover"
Expand Down Expand Up @@ -231,13 +232,35 @@ func NewTestServer(t testing.T, cb ServerConfigCallback) *TestServer {
func (s *TestServer) Stop() {
defer os.RemoveAll(s.Config.DataDir)

if err := s.cmd.Process.Kill(); err != nil {
// wait for the process to exit to be sure that the data dir can be
// deleted on all platforms.
done := make(chan struct{})
go func() {
defer close(done)

s.cmd.Wait()
}()

// kill and wait gracefully
if err := s.cmd.Process.Signal(os.Interrupt); err != nil {
s.t.Errorf("err: %s", err)
}

// wait for the process to exit to be sure that the data dir can be
// deleted on all platforms.
s.cmd.Wait()
select {
case <-done:
return
case <-time.After(5 * time.Second):
s.t.Logf("timed out waiting for process to gracefully terminate")
}

if err := s.cmd.Process.Kill(); err != nil {
s.t.Errorf("err: %s", err)
}
select {
case <-done:
case <-time.After(5 * time.Second):
s.t.Logf("timed out waiting for process to be killed")
}
}

// waitForAPI waits for only the agent HTTP endpoint to start
Expand Down
2 changes: 1 addition & 1 deletion client/alloc_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestAllocations_Restart(t *testing.T) {
Mode: nstructs.RestartPolicyModeFail,
}
a.Job.TaskGroups[0].Tasks[0].Config = map[string]interface{}{
"run_for": "10ms",
"run_for": "10s",
}
require.Nil(client.addAlloc(a, ""))

Expand Down
4 changes: 2 additions & 2 deletions drivers/shared/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ func TestExecutor_Start_Wait_Failure_Code(pt *testing.T) {
require := require.New(t)
testExecCmd := testExecutorCommand(t)
execCmd, allocDir := testExecCmd.command, testExecCmd.allocDir
execCmd.Cmd = "/bin/date"
execCmd.Args = []string{"fail"}
execCmd.Cmd = "/bin/sh"
execCmd.Args = []string{"-c", "sleep 1; /bin/date fail"}
factory.configureExecCmd(t, execCmd)
defer allocDir.Destroy()
executor := factory.new(testlog.HCLogger(t))
Expand Down

0 comments on commit 9ace1c8

Please sign in to comment.