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 the given UUID isn't in the slurm queue yet, SetPriority()
107 // should wait for it to appear on the very next poll, then give up.
108 func (s *SqueueSuite) TestSetPriorityBeforeQueued(c *C) {
109 uuidGood := "zzzzz-dz642-fake0fake0fake0"
110 uuidBad := "zzzzz-dz642-fake1fake1fake1"
112 slurm := &slurmFake{}
113 sqc := &SqueueChecker{
117 sqc.startOnce.Do(sqc.start)
121 done := make(chan struct{})
123 sqc.SetPriority(uuidGood, 123)
124 sqc.SetPriority(uuidBad, 345)
127 c.Check(sqc.queue[uuidGood], IsNil)
128 c.Check(sqc.queue[uuidBad], IsNil)
129 timeout := time.NewTimer(time.Second)
131 tick := time.NewTicker(time.Millisecond)
136 slurm.queue = uuidGood + " 0 12345 PENDING Resources\n"
139 // Avoid immediately selecting this case again
140 // on the next iteration if check() took
141 // longer than one tick.
149 c.Assert(sqc.queue[uuidGood], NotNil)
150 c.Check(sqc.queue[uuidGood].wantPriority, Equals, int64(123))
151 c.Check(sqc.queue[uuidBad], IsNil)
157 func callUntilReady(fn func(), done <-chan struct{}) {
158 tick := time.NewTicker(time.Millisecond)