Merge branch 'master' into 10979-cancelled-job-nodes
[arvados.git] / sdk / go / dispatch / throttle_test.go
1 package dispatch
2
3 import (
4         "testing"
5         "time"
6
7         check "gopkg.in/check.v1"
8 )
9
10 // Gocheck boilerplate
11 func Test(t *testing.T) {
12         check.TestingT(t)
13 }
14
15 var _ = check.Suite(&ThrottleTestSuite{})
16
17 type ThrottleTestSuite struct{}
18
19 func (*ThrottleTestSuite) TestThrottle(c *check.C) {
20         uuid := "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
21
22         t := throttle{}
23         c.Check(t.Check(uuid), check.Equals, true)
24         c.Check(t.Check(uuid), check.Equals, true)
25
26         t = throttle{hold: time.Nanosecond}
27         c.Check(t.Check(uuid), check.Equals, true)
28         time.Sleep(time.Microsecond)
29         c.Check(t.Check(uuid), check.Equals, true)
30
31         t = throttle{hold: time.Minute}
32         c.Check(t.Check(uuid), check.Equals, true)
33         c.Check(t.Check(uuid), check.Equals, false)
34         c.Check(t.Check(uuid), check.Equals, false)
35         t.seen[uuid].last = time.Now().Add(-time.Hour)
36         c.Check(t.Check(uuid), check.Equals, true)
37         c.Check(t.Check(uuid), check.Equals, false)
38 }