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) TestReniceAll(c *C) {
18 uuids := []string{"zzzzz-dz642-fake0fake0fake0", "zzzzz-dz642-fake1fake1fake1", "zzzzz-dz642-fake2fake2fake2"}
19 for _, test := range []struct {
27 squeue: uuids[0] + " 10000 4294000000\n",
28 want: map[string]int64{uuids[0]: 1},
29 expect: [][]string{{uuids[0], "0"}},
31 { // fake0 priority is too high
33 squeue: uuids[0] + " 10000 4294000777\n" + uuids[1] + " 10000 4294000444\n",
34 want: map[string]int64{uuids[0]: 1, uuids[1]: 999},
35 expect: [][]string{{uuids[1], "0"}, {uuids[0], "334"}},
39 squeue: uuids[0] + " 10000 4294000777\n" + uuids[1] + " 10000 4294000444\n",
40 want: map[string]int64{uuids[0]: 1, uuids[1]: 999},
41 expect: [][]string{{uuids[1], "0"}, {uuids[0], "433"}},
43 { // ignore fake2 because SetPriority() not called
45 squeue: uuids[0] + " 10000 4294000000\n" + uuids[1] + " 10000 4294000111\n" + uuids[2] + " 10000 4294000222\n",
46 want: map[string]int64{uuids[0]: 999, uuids[1]: 1},
47 expect: [][]string{{uuids[0], "0"}, {uuids[1], "112"}},
50 c.Logf("spread=%d squeue=%q want=%v -> expect=%v", test.spread, test.squeue, test.want, test.expect)
54 sqc := &SqueueChecker{
56 PrioritySpread: test.spread,
59 sqc.startOnce.Do(sqc.start)
61 for uuid, pri := range test.want {
62 sqc.SetPriority(uuid, pri)
65 c.Check(slurm.didRenice, DeepEquals, test.expect)
70 // If the given UUID isn't in the slurm queue yet, SetPriority()
71 // should wait for it to appear on the very next poll, then give up.
72 func (s *SqueueSuite) TestSetPriorityBeforeQueued(c *C) {
73 uuidGood := "zzzzz-dz642-fake0fake0fake0"
74 uuidBad := "zzzzz-dz642-fake1fake1fake1"
77 sqc := &SqueueChecker{
81 sqc.startOnce.Do(sqc.start)
85 done := make(chan struct{})
87 sqc.SetPriority(uuidGood, 123)
88 sqc.SetPriority(uuidBad, 345)
91 c.Check(sqc.queue[uuidGood], IsNil)
92 c.Check(sqc.queue[uuidBad], IsNil)
93 timeout := time.NewTimer(time.Second)
95 tick := time.NewTicker(time.Millisecond)
100 slurm.queue = uuidGood + " 0 12345\n"
103 // Avoid immediately selecting this case again
104 // on the next iteration if check() took
105 // longer than one tick.
113 c.Assert(sqc.queue[uuidGood], NotNil)
114 c.Check(sqc.queue[uuidGood].wantPriority, Equals, int64(123))
115 c.Check(sqc.queue[uuidBad], IsNil)