18874: Add 'services/workbench2/' from commit 'f6f88d9ca9cdeeeebfadcfe999789bfb9f69e5c6'
[arvados.git] / lib / dispatchcloud / worker / throttle_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package worker
6
7 import (
8         "errors"
9         "time"
10
11         check "gopkg.in/check.v1"
12 )
13
14 var _ = check.Suite(&ThrottleSuite{})
15
16 type ThrottleSuite struct{}
17
18 func (s *ThrottleSuite) TestRateLimitError(c *check.C) {
19         var t throttle
20         c.Check(t.Error(), check.IsNil)
21         t.ErrorUntil(errors.New("wait"), time.Now().Add(time.Second), nil)
22         c.Check(t.Error(), check.NotNil)
23         t.ErrorUntil(nil, time.Now(), nil)
24         c.Check(t.Error(), check.IsNil)
25
26         notified := false
27         t.ErrorUntil(errors.New("wait"), time.Now().Add(time.Millisecond), func() { notified = true })
28         c.Check(t.Error(), check.NotNil)
29         time.Sleep(time.Millisecond * 10)
30         c.Check(t.Error(), check.IsNil)
31         c.Check(notified, check.Equals, true)
32 }