Skip to content

Commit 348177d

Browse files
authored
e2e: correct TestSingleAffinities behavior (#25943)
TestSingleAffinities never expected a node with affinity score set to 0 in the set of returned nodes. However, since #25800, this can happen. What the test should be checking for instead is that the node with the highest normalized score has the right affinity.
1 parent beae92c commit 348177d

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

e2e/affinities/affinities.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
package affinities
55

66
import (
7-
"github.com/hashicorp/nomad/e2e/framework"
7+
"slices"
8+
9+
"github.com/shoenig/test/must"
810
"github.com/stretchr/testify/require"
911

1012
"github.com/hashicorp/nomad/e2e/e2eutil"
13+
"github.com/hashicorp/nomad/e2e/framework"
1114
"github.com/hashicorp/nomad/helper/uuid"
1215
)
1316

@@ -41,18 +44,30 @@ func (tc *BasicAffinityTest) TestSingleAffinities(f *framework.F) {
4144
allocs := e2eutil.RegisterAndWaitForAllocs(f.T(), nomadClient, "affinities/input/single_affinity.nomad", jobId, "")
4245

4346
jobAllocs := nomadClient.Allocations()
44-
require := require.New(f.T())
47+
4548
// Verify affinity score metadata
4649
for _, allocStub := range allocs {
4750
alloc, _, err := jobAllocs.Info(allocStub.ID, nil)
48-
require.Nil(err)
49-
require.NotEmpty(alloc.Metrics.ScoreMetaData)
51+
must.Nil(f.T(), err)
52+
must.SliceNotEmpty(f.T(), alloc.Metrics.ScoreMetaData)
53+
54+
pickedNodeNormScore := 0.0
55+
normScores := []float64{}
5056
for _, sm := range alloc.Metrics.ScoreMetaData {
5157
score, ok := sm.Scores["node-affinity"]
58+
normScores = append(normScores, sm.NormScore)
5259
if ok {
53-
require.Equal(1.0, score)
60+
// if there's a node-affinity score, check if this node is the node the
61+
// allocation was placed on
62+
if sm.NodeID == allocStub.NodeID {
63+
must.Eq(f.T(), score, 1.0)
64+
pickedNodeNormScore = sm.NormScore
65+
}
5466
}
5567
}
68+
// additionally, make sure that this node had the highest normalized score out
69+
// of all nodes we got
70+
must.Eq(f.T(), pickedNodeNormScore, slices.Max(normScores))
5671
}
5772

5873
}

0 commit comments

Comments
 (0)