Fix panic in test case (overwriting a locked sync.Mutex with an unlocked one).
[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         t0 := throttle{}
22         c.Check(t0.Check(uuid), check.Equals, true)
23         c.Check(t0.Check(uuid), check.Equals, true)
24
25         tNs := throttle{hold: time.Nanosecond}
26         c.Check(tNs.Check(uuid), check.Equals, true)
27         time.Sleep(time.Microsecond)
28         c.Check(tNs.Check(uuid), check.Equals, true)
29
30         tMin := throttle{hold: time.Minute}
31         c.Check(tMin.Check(uuid), check.Equals, true)
32         c.Check(tMin.Check(uuid), check.Equals, false)
33         c.Check(tMin.Check(uuid), check.Equals, false)
34         tMin.seen[uuid].last = time.Now().Add(-time.Hour)
35         c.Check(tMin.Check(uuid), check.Equals, true)
36         c.Check(tMin.Check(uuid), check.Equals, false)
37 }