Skip to content

Commit

Permalink
nomad: debug ci test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
schmichael committed Apr 11, 2022
1 parent bdfcb5a commit 0d62199
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions dependency/dependency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,19 @@ func initTestNomad(errCh chan<- error) {
}

// Wait for it start
var allocs []*nomadapi.AllocationListStub
for e := time.Now().Add(30 * time.Second); time.Now().Before(e); {
var allocs []*nomadapi.AllocationListStub
allocs, _, err := client.Jobs().Allocations(*job.ID, true, nil)
allocs, _, err = client.Jobs().Allocations(*job.ID, true, nil)
if err != nil {
time.Sleep(100 * time.Millisecond)
continue
}
if n := len(allocs); n > 1 {
errCh <- fmt.Errorf("expected 1 nomad alloc but found: %d", n)
errCh <- fmt.Errorf("expected 1 nomad alloc but found: %d\n%s\n%s",
n,
compileTaskStates(allocs[0]),
compileTaskStates(allocs[1]),
)
return
} else if n == 0 {
err = fmt.Errorf("expected 1 nomad alloc but found none")
Expand All @@ -257,7 +261,9 @@ func initTestNomad(errCh chan<- error) {
}

if s := allocs[0].ClientStatus; s != "running" {
err = fmt.Errorf("expected nomad alloc running but found %q", s)
err = fmt.Errorf("expected nomad alloc running but found %q\n%s",
s, compileTaskStates(allocs[0]),
)
time.Sleep(100 * time.Millisecond)
continue
}
Expand All @@ -267,6 +273,22 @@ func initTestNomad(errCh chan<- error) {
errCh <- fmt.Errorf("failed to start nomad job: %w", err)
return
}
fmt.Printf("Nomad started: %s\n", compileTaskStates(allocs[0]))
}

func compileTaskStates(a *nomadapi.AllocationListStub) string {
out := ""
for name, state := range a.TaskStates {
out += fmt.Sprintf("%s: [", name)
for i, e := range state.Events {
out += e.Type
if i != len(state.Events)-1 {
out += ", "
}
}
out += "] "
}
return out
}

type nomadServer struct {
Expand All @@ -275,9 +297,11 @@ type nomadServer struct {

func (n *nomadServer) Stop() error {
if n == nil || n.cmd == nil || n.cmd.Process == nil {
fmt.Println("No Nomad process to stop")
return nil
}

fmt.Println("Signalling Nomad")
n.cmd.Process.Signal(os.Interrupt)
return n.cmd.Wait()
}
Expand Down

0 comments on commit 0d62199

Please sign in to comment.