Switch to using the dep tool and update all the dependencies

This commit is contained in:
Nick Craig-Wood
2017-05-11 15:39:54 +01:00
parent 5135ff73cb
commit 98c2d2c41b
5321 changed files with 4483197 additions and 5918 deletions
+62
View File
@@ -0,0 +1,62 @@
/*
Copyright 2017 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package spanner
import (
"math"
"time"
"testing"
)
// Test if exponential backoff helper can produce correct series of
// retry delays.
func TestBackoff(t *testing.T) {
b := exponentialBackoff{minBackoff, maxBackoff}
tests := []struct {
retries int
min time.Duration
max time.Duration
}{
{
retries: 0,
min: minBackoff,
max: minBackoff,
},
{
retries: 1,
min: minBackoff,
max: time.Duration(rate * float64(minBackoff)),
},
{
retries: 3,
min: time.Duration(math.Pow(rate, 3) * (1 - jitter) * float64(minBackoff)),
max: time.Duration(math.Pow(rate, 3) * float64(minBackoff)),
},
{
retries: 1000,
min: time.Duration((1 - jitter) * float64(maxBackoff)),
max: maxBackoff,
},
}
for _, test := range tests {
got := b.delay(test.retries)
if float64(got) < float64(test.min) || float64(got) > float64(test.max) {
t.Errorf("delay(%v) = %v, want in range [%v, %v]", test.retries, got, test.min, test.max)
}
}
}