|
4 | 4 | package affinities |
5 | 5 |
|
6 | 6 | import ( |
7 | | - "github.com/hashicorp/nomad/e2e/framework" |
| 7 | + "slices" |
| 8 | + |
| 9 | + "github.com/shoenig/test/must" |
8 | 10 | "github.com/stretchr/testify/require" |
9 | 11 |
|
10 | 12 | "github.com/hashicorp/nomad/e2e/e2eutil" |
| 13 | + "github.com/hashicorp/nomad/e2e/framework" |
11 | 14 | "github.com/hashicorp/nomad/helper/uuid" |
12 | 15 | ) |
13 | 16 |
|
@@ -41,18 +44,30 @@ func (tc *BasicAffinityTest) TestSingleAffinities(f *framework.F) { |
41 | 44 | allocs := e2eutil.RegisterAndWaitForAllocs(f.T(), nomadClient, "affinities/input/single_affinity.nomad", jobId, "") |
42 | 45 |
|
43 | 46 | jobAllocs := nomadClient.Allocations() |
44 | | - require := require.New(f.T()) |
| 47 | + |
45 | 48 | // Verify affinity score metadata |
46 | 49 | for _, allocStub := range allocs { |
47 | 50 | 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{} |
50 | 56 | for _, sm := range alloc.Metrics.ScoreMetaData { |
51 | 57 | score, ok := sm.Scores["node-affinity"] |
| 58 | + normScores = append(normScores, sm.NormScore) |
52 | 59 | 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 | + } |
54 | 66 | } |
55 | 67 | } |
| 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)) |
56 | 71 | } |
57 | 72 |
|
58 | 73 | } |
|
0 commit comments