|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2016-2021 ArangoDB GmbH, Cologne, Germany |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | +// |
| 20 | + |
| 21 | +package v1 |
| 22 | + |
| 23 | +import ( |
| 24 | + "testing" |
| 25 | + "time" |
| 26 | + |
| 27 | + "github.com/stretchr/testify/assert" |
| 28 | + |
| 29 | + "github.com/arangodb/kube-arangodb/pkg/util" |
| 30 | +) |
| 31 | + |
| 32 | +func TestArangoBackupSpecBackOff_Backoff(t *testing.T) { |
| 33 | + t.Run("Default", func(t *testing.T) { |
| 34 | + var b *ArangoBackupSpecBackOff |
| 35 | + |
| 36 | + assert.Equal(t, 30*time.Second, b.Backoff(0)) |
| 37 | + assert.Equal(t, 144*time.Second, b.Backoff(1)) |
| 38 | + assert.Equal(t, 258*time.Second, b.Backoff(2)) |
| 39 | + assert.Equal(t, 372*time.Second, b.Backoff(3)) |
| 40 | + assert.Equal(t, 486*time.Second, b.Backoff(4)) |
| 41 | + assert.Equal(t, 600*time.Second, b.Backoff(5)) |
| 42 | + assert.Equal(t, 600*time.Second, b.Backoff(6)) |
| 43 | + }) |
| 44 | + t.Run("Custom", func(t *testing.T) { |
| 45 | + b := &ArangoBackupSpecBackOff{ |
| 46 | + MinDelay: util.NewInt(20), |
| 47 | + MaxDelay: util.NewInt(120), |
| 48 | + Iterations: util.NewInt(10), |
| 49 | + } |
| 50 | + |
| 51 | + assert.Equal(t, 20*time.Second, b.Backoff(0)) |
| 52 | + assert.Equal(t, 30*time.Second, b.Backoff(1)) |
| 53 | + assert.Equal(t, 40*time.Second, b.Backoff(2)) |
| 54 | + assert.Equal(t, 50*time.Second, b.Backoff(3)) |
| 55 | + assert.Equal(t, 60*time.Second, b.Backoff(4)) |
| 56 | + assert.Equal(t, 70*time.Second, b.Backoff(5)) |
| 57 | + assert.Equal(t, 80*time.Second, b.Backoff(6)) |
| 58 | + assert.Equal(t, 90*time.Second, b.Backoff(7)) |
| 59 | + assert.Equal(t, 100*time.Second, b.Backoff(8)) |
| 60 | + assert.Equal(t, 110*time.Second, b.Backoff(9)) |
| 61 | + assert.Equal(t, 120*time.Second, b.Backoff(10)) |
| 62 | + assert.Equal(t, 120*time.Second, b.Backoff(11)) |
| 63 | + }) |
| 64 | + |
| 65 | + t.Run("Invalid", func(t *testing.T) { |
| 66 | + b := &ArangoBackupSpecBackOff{ |
| 67 | + MinDelay: util.NewInt(-1), |
| 68 | + MaxDelay: util.NewInt(-1), |
| 69 | + Iterations: util.NewInt(0), |
| 70 | + } |
| 71 | + |
| 72 | + assert.Equal(t, 0, b.GetMinDelay()) |
| 73 | + assert.Equal(t, 0, b.GetMaxDelay()) |
| 74 | + assert.Equal(t, 1, b.GetIterations()) |
| 75 | + |
| 76 | + assert.Equal(t, 0*time.Second, b.Backoff(12345)) |
| 77 | + }) |
| 78 | + |
| 79 | + t.Run("Max < Min", func(t *testing.T) { |
| 80 | + b := &ArangoBackupSpecBackOff{ |
| 81 | + MinDelay: util.NewInt(50), |
| 82 | + MaxDelay: util.NewInt(20), |
| 83 | + } |
| 84 | + |
| 85 | + assert.Equal(t, 20, b.GetMinDelay()) |
| 86 | + assert.Equal(t, 20, b.GetMaxDelay()) |
| 87 | + assert.Equal(t, 5, b.GetIterations()) |
| 88 | + }) |
| 89 | +} |
0 commit comments