nomad: method to test if outstanding evaluation

This commit is contained in:
Armon Dadgar
2015-07-23 21:58:13 -07:00
parent e10f3942e7
commit a723c591d1
2 changed files with 24 additions and 0 deletions

View File

@@ -281,6 +281,14 @@ func (b *EvalBroker) waitForSchedulers(schedulers []string, timeoutCh <-chan tim
}
}
// Outstanding checks if an EvalID has been delivered but not acknowledged
func (b *EvalBroker) Outstanding(evalID string) bool {
b.l.RLock()
defer b.l.RUnlock()
_, ok := b.unack[evalID]
return ok
}
// Ack is used to positively acknowledge handling an evaluation
func (b *EvalBroker) Ack(evalID string) error {
b.l.Lock()

View File

@@ -66,6 +66,10 @@ func TestEvalBroker_Enqueue_Dequeue_Nack_Ack(t *testing.T) {
t.Fatalf("bad : %#v", out)
}
if !b.Outstanding(out.ID) {
t.Fatalf("should be outstanding")
}
// Check the stats
stats = b.Stats()
if stats.TotalReady != 0 {
@@ -87,6 +91,10 @@ func TestEvalBroker_Enqueue_Dequeue_Nack_Ack(t *testing.T) {
t.Fatalf("err: %v", err)
}
if b.Outstanding(out.ID) {
t.Fatalf("should not be outstanding")
}
// Check the stats
stats = b.Stats()
if stats.TotalReady != 1 {
@@ -111,12 +119,20 @@ func TestEvalBroker_Enqueue_Dequeue_Nack_Ack(t *testing.T) {
t.Fatalf("bad : %#v", out2)
}
if !b.Outstanding(out.ID) {
t.Fatalf("should be outstanding")
}
// Ack finally
err = b.Ack(eval.ID)
if err != nil {
t.Fatalf("err: %v", err)
}
if b.Outstanding(out.ID) {
t.Fatalf("should not be outstanding")
}
// Check the stats
stats = b.Stats()
if stats.TotalReady != 0 {