[arvados] updated: 2.7.0-6020-g439877fdcd
git repository hosting
git at public.arvados.org
Fri Feb 16 15:53:52 UTC 2024
Summary of changes:
sdk/go/keepclient/keepclient_test.go | 103 +++++++++++++++++++----------------
1 file changed, 57 insertions(+), 46 deletions(-)
via 439877fdcd308943991d21379ac7946abb41daea (commit)
from bffc439a72f03126359d468329b8d25febc7bc9e (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 439877fdcd308943991d21379ac7946abb41daea
Author: Tom Clegg <tom at curii.com>
Date: Fri Feb 16 10:52:51 2024 -0500
21023: Clean up tests.
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>
diff --git a/sdk/go/keepclient/keepclient_test.go b/sdk/go/keepclient/keepclient_test.go
index 4cfe1a0896..531db31b25 100644
--- a/sdk/go/keepclient/keepclient_test.go
+++ b/sdk/go/keepclient/keepclient_test.go
@@ -40,7 +40,10 @@ var _ = Suite(&StandaloneSuite{})
type ServerRequiredSuite struct{}
// Standalone tests
-type StandaloneSuite struct{}
+type StandaloneSuite struct {
+ origDefaultRetryDelay time.Duration
+ origMinimumRetryDelay time.Duration
+}
var origHOME = os.Getenv("HOME")
@@ -48,10 +51,14 @@ func (s *StandaloneSuite) SetUpTest(c *C) {
RefreshServiceDiscovery()
// Prevent cache state from leaking between test cases
os.Setenv("HOME", c.MkDir())
+ s.origDefaultRetryDelay = DefaultRetryDelay
+ s.origMinimumRetryDelay = MinimumRetryDelay
}
func (s *StandaloneSuite) TearDownTest(c *C) {
os.Setenv("HOME", origHOME)
+ DefaultRetryDelay = s.origDefaultRetryDelay
+ MinimumRetryDelay = s.origMinimumRetryDelay
}
func pythonDir() string {
@@ -1506,10 +1513,6 @@ func (s *StandaloneSuite) TestGetIndexWithNoSuchPrefix(c *C) {
}
func (s *StandaloneSuite) TestPutBRetry(c *C) {
- defer func(origDefault, origMinimum time.Duration) {
- DefaultRetryDelay = origDefault
- MinimumRetryDelay = origMinimum
- }(DefaultRetryDelay, MinimumRetryDelay)
DefaultRetryDelay = time.Second / 8
MinimumRetryDelay = time.Millisecond
@@ -1567,8 +1570,7 @@ func (s *StandaloneSuite) TestPutBRetry(c *C) {
min := MinimumRetryDelay * 3
max := expect + expect*2 + expect*2*2
max += nonsleeptime
- c.Check(elapsed >= min, Equals, true, Commentf("elapsed %v / expect min %v", elapsed, min))
- c.Check(elapsed <= max, Equals, true, Commentf("elapsed %v / expect max %v", elapsed, max))
+ checkInterval(c, elapsed, min, max)
}
}
@@ -1618,50 +1620,59 @@ func (s *ServerRequiredSuite) TestMakeKeepClientWithNonDiskTypeService(c *C) {
c.Assert(kc.httpClient().(*http.Client).Timeout, Equals, 300*time.Second)
}
-func (s *StandaloneSuite) TestDelayCalculator(c *C) {
- defer func(origDefault, origMinimum time.Duration) {
- DefaultRetryDelay = origDefault
- MinimumRetryDelay = origMinimum
- }(DefaultRetryDelay, MinimumRetryDelay)
+func (s *StandaloneSuite) TestDelayCalculator_Default(c *C) {
+ MinimumRetryDelay = time.Second / 2
+ DefaultRetryDelay = time.Second
- checkInterval := func(d, min, max time.Duration) {
- c.Check(d >= min, Equals, true)
- c.Check(d <= max, Equals, true)
- }
+ dc := delayCalculator{InitialMaxDelay: 0}
+ checkInterval(c, dc.Next(), time.Second/2, time.Second)
+ checkInterval(c, dc.Next(), time.Second/2, time.Second*2)
+ checkInterval(c, dc.Next(), time.Second/2, time.Second*4)
+ checkInterval(c, dc.Next(), time.Second/2, time.Second*8)
+ checkInterval(c, dc.Next(), time.Second/2, time.Second*10)
+ checkInterval(c, dc.Next(), time.Second/2, time.Second*10)
+}
+func (s *StandaloneSuite) TestDelayCalculator_SetInitial(c *C) {
MinimumRetryDelay = time.Second / 2
DefaultRetryDelay = time.Second
- dc := delayCalculator{InitialMaxDelay: 0}
- checkInterval(dc.Next(), time.Second/2, time.Second)
- checkInterval(dc.Next(), time.Second/2, time.Second*2)
- checkInterval(dc.Next(), time.Second/2, time.Second*4)
- checkInterval(dc.Next(), time.Second/2, time.Second*8)
- checkInterval(dc.Next(), time.Second/2, time.Second*10)
- checkInterval(dc.Next(), time.Second/2, time.Second*10)
-
- // Enforce non-zero InitialMaxDelay
- dc = delayCalculator{InitialMaxDelay: time.Second}
- checkInterval(dc.Next(), time.Second/2, time.Second*2)
- checkInterval(dc.Next(), time.Second/2, time.Second*4)
- checkInterval(dc.Next(), time.Second/2, time.Second*8)
- checkInterval(dc.Next(), time.Second/2, time.Second*16)
- checkInterval(dc.Next(), time.Second/2, time.Second*20)
- checkInterval(dc.Next(), time.Second/2, time.Second*20)
-
- // Enforce MinimumRetryDelay
- dc = delayCalculator{InitialMaxDelay: time.Millisecond}
- checkInterval(dc.Next(), time.Second/2, time.Second/2)
- checkInterval(dc.Next(), time.Second/2, time.Second)
- checkInterval(dc.Next(), time.Second/2, time.Second*2)
- checkInterval(dc.Next(), time.Second/2, time.Second*4)
- checkInterval(dc.Next(), time.Second/2, time.Second*8)
- checkInterval(dc.Next(), time.Second/2, time.Second*10)
- checkInterval(dc.Next(), time.Second/2, time.Second*10)
-
- // If InitialMaxDelay is less than MinimumRetryDelay/10, then
- // delay is always MinimumRetryDelay.
- dc = delayCalculator{InitialMaxDelay: time.Millisecond}
+
+ dc := delayCalculator{InitialMaxDelay: time.Second * 2}
+ checkInterval(c, dc.Next(), time.Second/2, time.Second*2)
+ checkInterval(c, dc.Next(), time.Second/2, time.Second*4)
+ checkInterval(c, dc.Next(), time.Second/2, time.Second*8)
+ checkInterval(c, dc.Next(), time.Second/2, time.Second*16)
+ checkInterval(c, dc.Next(), time.Second/2, time.Second*20)
+ checkInterval(c, dc.Next(), time.Second/2, time.Second*20)
+ checkInterval(c, dc.Next(), time.Second/2, time.Second*20)
+}
+
+func (s *StandaloneSuite) TestDelayCalculator_EnsureSomeLongDelays(c *C) {
+ dc := delayCalculator{InitialMaxDelay: time.Second * 5}
+ var d time.Duration
+ n := 4000
+ for i := 0; i < n; i++ {
+ if i < 20 || i%10 == 0 {
+ c.Logf("i=%d, delay=%v", i, d)
+ }
+ if d = dc.Next(); d > dc.InitialMaxDelay*9 {
+ return
+ }
+ }
+ c.Errorf("after %d trials, never got a delay more than 90%% of expected max %d; last was %v", n, dc.InitialMaxDelay*10, d)
+}
+
+// If InitialMaxDelay is less than MinimumRetryDelay/10, then delay is
+// always MinimumRetryDelay.
+func (s *StandaloneSuite) TestDelayCalculator_InitialLessThanMinimum(c *C) {
+ MinimumRetryDelay = time.Second / 2
+ dc := delayCalculator{InitialMaxDelay: time.Millisecond}
for i := 0; i < 20; i++ {
c.Check(dc.Next(), Equals, time.Second/2)
}
}
+
+func checkInterval(c *C, t, min, max time.Duration) {
+ c.Check(t >= min, Equals, true, Commentf("got %v which is below expected min %v", t, min))
+ c.Check(t <= max, Equals, true, Commentf("got %v which is above expected max %v", t, max))
+}
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list