Skip to content

Commit

Permalink
core: test duplicated blocked eval stats
Browse files Browse the repository at this point in the history
In the original test, the eval generator would use a random value for
the job ID, resulting in an unxercised code path for duplicate blocked
evals.
  • Loading branch information
lgfa29 committed May 24, 2022
1 parent e8eaf83 commit d796127
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion nomad/blocked_evals_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,14 @@ func (t testBlockedEvalsRandomBlockedEval) Generate(rand *rand.Rand, _ int) refl

// Get how many task groups, datacenters and node classes to generate.
// Add 1 to avoid 0.
jobCount := rand.Intn(3) + 1
tgCount := rand.Intn(10) + 1
dcCount := rand.Intn(3) + 1
nodeClassCount := rand.Intn(3) + 1

failedTGAllocs := map[string]*structs.AllocMetric{}

e.JobID = fmt.Sprintf("job-%d", jobCount)
for tg := 1; tg <= tgCount; tg++ {
tgName := fmt.Sprintf("group-%d", tg)

Expand Down Expand Up @@ -403,11 +405,24 @@ func TestBlockedEvalsStats_BlockedResources(t *testing.T) {
manualCount := func(testEval testBlockedEvalsRandomBlockedEval, block bool, unblockIdx uint16) *BlockedResourcesStats {
if block || len(evalHistory) == 0 {
evalHistory = append(evalHistory, testEval.eval)

// Find and unblock evals for the same job.
for _, e := range evalHistory {
if e.Namespace == testEval.eval.Namespace && e.JobID == testEval.eval.JobID {
blockedEvals[e.ID] = false
}
}
blockedEvals[testEval.eval.ID] = true
} else {
i := int(unblockIdx) % len(evalHistory)
eval := evalHistory[i]
blockedEvals[eval.ID] = false

// Find and unlock all evals for this job.
for _, e := range evalHistory {
if e.Namespace == eval.Namespace && e.JobID == eval.JobID {
blockedEvals[e.ID] = false
}
}
}

result := NewBlockedResourcesStats()
Expand Down

0 comments on commit d796127

Please sign in to comment.