20640: Add computed permissions API.
[arvados.git] / sdk / go / dispatch / throttle_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 package dispatch
6
7 import (
8         "testing"
9         "time"
10
11         check "gopkg.in/check.v1"
12 )
13
14 // Gocheck boilerplate
15 func Test(t *testing.T) {
16         check.TestingT(t)
17 }
18
19 var _ = check.Suite(&ThrottleTestSuite{})
20
21 type ThrottleTestSuite struct{}
22
23 func (*ThrottleTestSuite) TestThrottle(c *check.C) {
24         uuid := "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
25         t0 := throttle{}
26         c.Check(t0.Check(uuid), check.Equals, true)
27         c.Check(t0.Check(uuid), check.Equals, true)
28
29         tNs := throttle{hold: time.Nanosecond}
30         c.Check(tNs.Check(uuid), check.Equals, true)
31         time.Sleep(time.Microsecond)
32         c.Check(tNs.Check(uuid), check.Equals, true)
33
34         tMin := throttle{hold: time.Minute}
35         c.Check(tMin.Check(uuid), check.Equals, true)
36         c.Check(tMin.Check(uuid), check.Equals, false)
37         c.Check(tMin.Check(uuid), check.Equals, false)
38         tMin.seen[uuid].last = time.Now().Add(-time.Hour)
39         c.Check(tMin.Check(uuid), check.Equals, true)
40         c.Check(tMin.Check(uuid), check.Equals, false)
41 }