1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 var _ = Suite(&SqueueSuite{})
15 type SqueueSuite struct{}
17 func (s *SqueueSuite) TestReleasePending(c *C) {
19 "zzzzz-dz642-fake0fake0fake0",
20 "zzzzz-dz642-fake1fake1fake1",
21 "zzzzz-dz642-fake2fake2fake2",
24 queue: uuids[0] + " 10000 4294000000 PENDING Resources\n" + uuids[1] + " 10000 4294000111 PENDING Resources\n" + uuids[2] + " 10000 0 PENDING BadConstraints\n",
26 sqc := &SqueueChecker{
30 sqc.startOnce.Do(sqc.start)
33 done := make(chan struct{})
35 for _, u := range uuids {
40 callUntilReady(sqc.check, done)
42 slurm.didRelease = nil
44 c.Check(slurm.didRelease, DeepEquals, []string{uuids[2]})
47 func (s *SqueueSuite) TestReniceAll(c *C) {
48 uuids := []string{"zzzzz-dz642-fake0fake0fake0", "zzzzz-dz642-fake1fake1fake1", "zzzzz-dz642-fake2fake2fake2"}
49 for _, test := range []struct {
57 squeue: uuids[0] + " 10000 4294000000 PENDING Resources\n",
58 want: map[string]int64{uuids[0]: 1},
59 expect: [][]string{{uuids[0], "0"}},
61 { // fake0 priority is too high
63 squeue: uuids[0] + " 10000 4294000777 PENDING Resources\n" + uuids[1] + " 10000 4294000444 PENDING Resources\n",
64 want: map[string]int64{uuids[0]: 1, uuids[1]: 999},
65 expect: [][]string{{uuids[1], "0"}, {uuids[0], "334"}},
69 squeue: uuids[0] + " 10000 4294000777 PENDING Resources\n" + uuids[1] + " 10000 4294000444 PENDING Resources\n",
70 want: map[string]int64{uuids[0]: 1, uuids[1]: 999},
71 expect: [][]string{{uuids[1], "0"}, {uuids[0], "433"}},
73 { // ignore fake2 because SetPriority() not called
75 squeue: uuids[0] + " 10000 4294000000 PENDING Resources\n" + uuids[1] + " 10000 4294000111 PENDING Resources\n" + uuids[2] + " 10000 4294000222 PENDING Resources\n",
76 want: map[string]int64{uuids[0]: 999, uuids[1]: 1},
77 expect: [][]string{{uuids[0], "0"}, {uuids[1], "112"}},
79 { // ignore fake2 because slurm priority=0
81 squeue: uuids[0] + " 10000 4294000000 PENDING Resources\n" + uuids[1] + " 10000 4294000111 PENDING Resources\n" + uuids[2] + " 10000 0 PENDING Resources\n",
82 want: map[string]int64{uuids[0]: 999, uuids[1]: 1, uuids[2]: 997},
83 expect: [][]string{{uuids[0], "0"}, {uuids[1], "112"}},
86 c.Logf("spread=%d squeue=%q want=%v -> expect=%v", test.spread, test.squeue, test.want, test.expect)
90 sqc := &SqueueChecker{
92 PrioritySpread: test.spread,
95 sqc.startOnce.Do(sqc.start)
97 for uuid, pri := range test.want {
98 sqc.SetPriority(uuid, pri)
101 c.Check(slurm.didRenice, DeepEquals, test.expect)
106 // If a limited nice range prevents desired priority adjustments, give
107 // up and clamp nice to 10K.
108 func (s *SqueueSuite) TestReniceInvalidNiceValue(c *C) {
109 uuids := []string{"zzzzz-dz642-fake0fake0fake0", "zzzzz-dz642-fake1fake1fake1", "zzzzz-dz642-fake2fake2fake2"}
111 queue: uuids[0] + " 0 4294000222 PENDING Resources\n" + uuids[1] + " 0 4294555222 PENDING Resources\n",
114 sqc := &SqueueChecker{
119 sqc.startOnce.Do(sqc.start)
121 sqc.SetPriority(uuids[0], 2)
122 sqc.SetPriority(uuids[1], 1)
124 // First attempt should renice to 555001, which will fail
126 c.Check(slurm.didRenice, DeepEquals, [][]string{{uuids[1], "555001"}})
128 // Next attempt should renice to 10K, which will succeed
130 c.Check(slurm.didRenice, DeepEquals, [][]string{{uuids[1], "555001"}, {uuids[1], "10000"}})
131 // ...so we'll change the squeue response to reflect the
132 // updated priority+nice, and make sure sqc sees that...
133 slurm.queue = uuids[0] + " 0 4294000222 PENDING Resources\n" + uuids[1] + " 10000 4294545222 PENDING Resources\n"
136 // Next attempt should leave nice alone because it's already
139 c.Check(slurm.didRenice, DeepEquals, [][]string{{uuids[1], "555001"}, {uuids[1], "10000"}})
141 // Back to normal if desired nice value falls below 10K
142 slurm.queue = uuids[0] + " 0 4294000222 PENDING Resources\n" + uuids[1] + " 10000 4294000111 PENDING Resources\n"
145 c.Check(slurm.didRenice, DeepEquals, [][]string{{uuids[1], "555001"}, {uuids[1], "10000"}, {uuids[1], "9890"}})
150 // If the given UUID isn't in the slurm queue yet, SetPriority()
151 // should wait for it to appear on the very next poll, then give up.
152 func (s *SqueueSuite) TestSetPriorityBeforeQueued(c *C) {
153 uuidGood := "zzzzz-dz642-fake0fake0fake0"
154 uuidBad := "zzzzz-dz642-fake1fake1fake1"
156 slurm := &slurmFake{}
157 sqc := &SqueueChecker{
161 sqc.startOnce.Do(sqc.start)
165 done := make(chan struct{})
167 sqc.SetPriority(uuidGood, 123)
168 sqc.SetPriority(uuidBad, 345)
171 c.Check(sqc.queue[uuidGood], IsNil)
172 c.Check(sqc.queue[uuidBad], IsNil)
173 timeout := time.NewTimer(time.Second)
175 tick := time.NewTicker(time.Millisecond)
180 slurm.queue = uuidGood + " 0 12345 PENDING Resources\n"
183 // Avoid immediately selecting this case again
184 // on the next iteration if check() took
185 // longer than one tick.
193 c.Assert(sqc.queue[uuidGood], NotNil)
194 c.Check(sqc.queue[uuidGood].wantPriority, Equals, int64(123))
195 c.Check(sqc.queue[uuidBad], IsNil)
201 func callUntilReady(fn func(), done <-chan struct{}) {
202 tick := time.NewTicker(time.Millisecond)