Merge pull request #9868 from hashicorp/e2e-tests-20200121

Deflake some e2e tests
This commit is contained in:
Mahmood Ali 2021-01-21 12:02:52 -05:00 committed by GitHub
commit 1c6f4549ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 36 deletions

View file

@ -208,7 +208,7 @@ func AllocExec(allocID, taskID, execCmd, ns string, wc *WaitConfig) (string, err
got, err = Command(cmd[0], cmd[1:]...) got, err = Command(cmd[0], cmd[1:]...)
return err == nil, err return err == nil, err
}, func(e error) { }, func(e error) {
err = fmt.Errorf("exec failed: '%s'", strings.Join(cmd, " ")) err = fmt.Errorf("exec failed: '%s': %v", strings.Join(cmd, " "), e)
}) })
return got, err return got, err
} }

View file

@ -10,8 +10,12 @@ import (
// Command sends a command line argument to Nomad and returns the unbuffered // Command sends a command line argument to Nomad and returns the unbuffered
// stdout as a string (or, if there's an error, the stderr) // stdout as a string (or, if there's an error, the stderr)
func Command(cmd string, args ...string) (string, error) { func Command(cmd string, args ...string) (string, error) {
out, err := exec.Command(cmd, args...).CombinedOutput() bytes, err := exec.Command(cmd, args...).CombinedOutput()
return string(out), err out := string(bytes)
if err != nil {
return out, fmt.Errorf("command %v %v failed: %v\nOutput: %v", cmd, args, err, out)
}
return out, err
} }
// GetField returns the value of an output field (ex. the "Submit Date" field // GetField returns the value of an output field (ex. the "Submit Date" field

View file

@ -218,7 +218,10 @@ func (tc *EventsTest) TestStartIndex(f *framework.F) {
select { select {
case <-ctx.Done(): case <-ctx.Done():
return return
case event := <-streamCh: case event, ok := <-streamCh:
if !ok {
return
}
if event.IsHeartbeat() { if event.IsHeartbeat() {
continue continue
} }

View file

@ -3,6 +3,7 @@ package namespaces
import ( import (
"fmt" "fmt"
"os" "os"
"strings"
e2e "github.com/hashicorp/nomad/e2e/e2eutil" e2e "github.com/hashicorp/nomad/e2e/e2eutil"
"github.com/hashicorp/nomad/e2e/framework" "github.com/hashicorp/nomad/e2e/framework"
@ -88,61 +89,69 @@ func (tc *NamespacesE2ETest) TestNamespacesFiltering(f *framework.F) {
jobDefault := run("namespaces/input/namespace_default.nomad", "") jobDefault := run("namespaces/input/namespace_default.nomad", "")
// exercise 'nomad job status' filtering // exercise 'nomad job status' filtering
parse := func(out string) []map[string]string {
rows, err := e2e.ParseColumns(out)
f.NoError(err, "failed to parse job status output: %v", out)
result := make([]map[string]string, 0, len(rows))
for _, row := range rows {
jobID := row["Job ID"]
if jobID == "" {
jobID = row["ID"]
}
if strings.HasPrefix(jobID, "test-namespace-") {
result = append(result, row)
}
}
return result
}
out, err := e2e.Command("nomad", "job", "status", "-namespace", "NamespaceA") out, err := e2e.Command("nomad", "job", "status", "-namespace", "NamespaceA")
f.NoError(err, "'nomad job status -namespace NamespaceA' failed") f.NoError(err, "'nomad job status -namespace NamespaceA' failed")
rows, err := e2e.ParseColumns(out) rows := parse(out)
f.NoError(err, "could not parse job status output") f.Len(rows, 1)
f.Equal(1, len(rows))
f.Equal(jobA, rows[0]["ID"]) f.Equal(jobA, rows[0]["ID"])
out, err = e2e.Command("nomad", "job", "status", "-namespace", "NamespaceB") out, err = e2e.Command("nomad", "job", "status", "-namespace", "NamespaceB")
f.NoError(err, "'nomad job status -namespace NamespaceB' failed") f.NoError(err, "'nomad job status -namespace NamespaceB' failed")
rows, err = e2e.ParseColumns(out) rows = parse(out)
f.NoError(err, "could not parse job status output") f.Len(rows, 1)
f.Equal(1, len(rows))
f.Equal(jobB, rows[0]["ID"]) f.Equal(jobB, rows[0]["ID"])
out, err = e2e.Command("nomad", "job", "status", "-namespace", "*") out, err = e2e.Command("nomad", "job", "status", "-namespace", "*")
f.NoError(err, "'nomad job status -namespace *' failed") f.NoError(err, "'nomad job status -namespace *' failed")
rows, err = e2e.ParseColumns(out) rows = parse(out)
f.NoError(err, "could not parse job status output")
f.Equal(3, len(rows)) f.Equal(3, len(rows))
out, err = e2e.Command("nomad", "job", "status") out, err = e2e.Command("nomad", "job", "status")
f.NoError(err, "'nomad job status' failed") f.NoError(err, "'nomad job status' failed")
rows, err = e2e.ParseColumns(out) rows = parse(out)
f.NoError(err, "could not parse job status output") f.Len(rows, 1)
f.Equal(1, len(rows))
f.Equal(jobDefault, rows[0]["ID"]) f.Equal(jobDefault, rows[0]["ID"])
// exercise 'nomad status' filtering // exercise 'nomad status' filtering
out, err = e2e.Command("nomad", "status", "-namespace", "NamespaceA") out, err = e2e.Command("nomad", "status", "-namespace", "NamespaceA")
f.NoError(err, "'nomad job status -namespace NamespaceA' failed") f.NoError(err, "'nomad job status -namespace NamespaceA' failed")
rows, err = e2e.ParseColumns(out) rows = parse(out)
f.NoError(err, "could not parse status output") f.Len(rows, 1)
f.Equal(1, len(rows))
f.Equal(jobA, rows[0]["ID"]) f.Equal(jobA, rows[0]["ID"])
out, err = e2e.Command("nomad", "status", "-namespace", "NamespaceB") out, err = e2e.Command("nomad", "status", "-namespace", "NamespaceB")
f.NoError(err, "'nomad job status -namespace NamespaceB' failed") f.NoError(err, "'nomad job status -namespace NamespaceB' failed")
rows, err = e2e.ParseColumns(out) rows = parse(out)
f.NoError(err, "could not parse status output") f.Len(rows, 1)
f.Equal(1, len(rows))
f.Equal(jobB, rows[0]["ID"]) f.Equal(jobB, rows[0]["ID"])
out, err = e2e.Command("nomad", "status", "-namespace", "*") out, err = e2e.Command("nomad", "status", "-namespace", "*")
f.NoError(err, "'nomad job status -namespace *' failed") f.NoError(err, "'nomad job status -namespace *' failed")
rows, err = e2e.ParseColumns(out) rows = parse(out)
f.NoError(err, "could not parse status output")
f.Equal(3, len(rows)) f.Equal(3, len(rows))
out, err = e2e.Command("nomad", "status") out, err = e2e.Command("nomad", "status")
f.NoError(err, "'nomad status' failed") f.NoError(err, "'nomad status' failed")
rows, err = e2e.ParseColumns(out) rows = parse(out)
f.NoError(err, "could not parse status output") f.Len(rows, 1)
f.Equal(1, len(rows))
f.Equal(jobDefault, rows[0]["ID"]) f.Equal(jobDefault, rows[0]["ID"])
// exercise 'nomad deployment list' filtering // exercise 'nomad deployment list' filtering
@ -150,23 +159,20 @@ func (tc *NamespacesE2ETest) TestNamespacesFiltering(f *framework.F) {
out, err = e2e.Command("nomad", "deployment", "list", "-namespace", "NamespaceA") out, err = e2e.Command("nomad", "deployment", "list", "-namespace", "NamespaceA")
f.NoError(err, "'nomad job status -namespace NamespaceA' failed") f.NoError(err, "'nomad job status -namespace NamespaceA' failed")
rows, err = e2e.ParseColumns(out) rows = parse(out)
f.NoError(err, "could not parse deployment list output") f.Len(rows, 1)
f.Equal(1, len(rows))
f.Equal(jobA, rows[0]["Job ID"]) f.Equal(jobA, rows[0]["Job ID"])
out, err = e2e.Command("nomad", "deployment", "list", "-namespace", "NamespaceB") out, err = e2e.Command("nomad", "deployment", "list", "-namespace", "NamespaceB")
f.NoError(err, "'nomad job status -namespace NamespaceB' failed") f.NoError(err, "'nomad job status -namespace NamespaceB' failed")
rows, err = e2e.ParseColumns(out) rows = parse(out)
f.NoError(err, "could not parse deployment list output")
f.Equal(len(rows), 1) f.Equal(len(rows), 1)
f.Equal(jobB, rows[0]["Job ID"]) f.Equal(jobB, rows[0]["Job ID"])
out, err = e2e.Command("nomad", "deployment", "list") out, err = e2e.Command("nomad", "deployment", "list")
f.NoError(err, "'nomad deployment list' failed") f.NoError(err, "'nomad deployment list' failed")
rows, err = e2e.ParseColumns(out) rows = parse(out)
f.NoError(err, "could not parse deployment list output") f.Len(rows, 1)
f.Equal(1, len(rows))
f.Equal(jobDefault, rows[0]["Job ID"]) f.Equal(jobDefault, rows[0]["Job ID"])
out, err = e2e.Command("nomad", "job", "stop", jobA) out, err = e2e.Command("nomad", "job", "stop", jobA)

View file

@ -3,12 +3,14 @@ package volumes
import ( import (
"fmt" "fmt"
"os" "os"
"time"
"github.com/hashicorp/nomad/api" "github.com/hashicorp/nomad/api"
e2e "github.com/hashicorp/nomad/e2e/e2eutil" e2e "github.com/hashicorp/nomad/e2e/e2eutil"
"github.com/hashicorp/nomad/e2e/framework" "github.com/hashicorp/nomad/e2e/framework"
"github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/jobspec" "github.com/hashicorp/nomad/jobspec"
"github.com/hashicorp/nomad/testutil"
) )
const ns = "" const ns = ""
@ -94,8 +96,22 @@ func (tc *VolumesTest) TestVolumeMounts(f *framework.F) {
_, _, err = tc.Nomad().Jobs().Register(job, nil) _, _, err = tc.Nomad().Jobs().Register(job, nil)
f.NoError(err, "could not register updated job") f.NoError(err, "could not register updated job")
allocs, err = e2e.AllocsForJob(jobID, ns) testutil.WaitForResultRetries(5000, func() (bool, error) {
f.NoError(err, "could not get allocs for job") time.Sleep(time.Millisecond * 100)
allocs, err = e2e.AllocsForJob(jobID, ns)
if err != nil {
return false, err
}
if len(allocs) < 2 {
return false, fmt.Errorf("no new allocation for %v: %v", jobID, allocs)
}
return true, nil
}, func(e error) {
f.NoError(e, "failed to get new alloc")
})
newAllocID := allocs[0]["ID"] newAllocID := allocs[0]["ID"]
newCmdToExec := fmt.Sprintf("cat /tmp/foo/%s", newAllocID) newCmdToExec := fmt.Sprintf("cat /tmp/foo/%s", newAllocID)