1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
11 check "gopkg.in/check.v1"
14 // Gocheck boilerplate
15 func Test(t *testing.T) {
19 var _ = check.Suite(&ThrottleTestSuite{})
21 type ThrottleTestSuite struct{}
23 func (*ThrottleTestSuite) TestThrottle(c *check.C) {
24 uuid := "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
26 c.Check(t0.Check(uuid), check.Equals, true)
27 c.Check(t0.Check(uuid), check.Equals, true)
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)
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)