forked from opensciencegrid/stashcp
-
Notifications
You must be signed in to change notification settings - Fork 6
/
errorAccum_test.go
61 lines (49 loc) · 1.67 KB
/
errorAccum_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package stashcp
import (
"errors"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
// TestErrorAccum tests simple adding and removing from the accumulator
func TestErrorAccum(t *testing.T) {
bunchOfErrors = make([]TimestampedError, 0)
defer func() {
bunchOfErrors = make([]TimestampedError, 0)
}()
// Case 1: cache with http
err := errors.New("error1")
err2 := errors.New("error2")
AddError(err)
AddError(err2)
errStr := GetErrors()
assert.Equal(t, "Attempt #2: error2 (0s elapsed, 0s since start); Attempt #1: error1 (0s since start)", errStr)
}
// TestErrorsRetryableFalse tests that errors are not retryable
func TestErrorsRetryableFalse(t *testing.T) {
bunchOfErrors = make([]TimestampedError, 0)
defer func() {
bunchOfErrors = make([]TimestampedError, 0)
}()
// Case 2: cache with http
AddError(&SlowTransferError{})
AddError(&SlowTransferError{})
assert.True(t, ErrorsRetryable(), "ErrorsRetryable should be true")
AddError(&ConnectionSetupError{})
assert.True(t, ErrorsRetryable(), "ErrorsRetryable should be true")
// Now add a non-retryable error
AddError(errors.New("Non retryable error"))
assert.False(t, ErrorsRetryable(), "ErrorsRetryable should be false")
}
// TestErrorsRetryableTrue tests that errors are retryable
func TestErrorsRetryableTrue(t *testing.T) {
bunchOfErrors = make([]TimestampedError, 0)
defer func() {
bunchOfErrors = make([]TimestampedError, 0)
}()
// Try with a retryable error nested error
AddError(&url.Error{Err: &SlowTransferError{}})
assert.True(t, ErrorsRetryable(), "ErrorsRetryable should be true")
AddError(&ConnectionSetupError{})
assert.True(t, ErrorsRetryable(), "ErrorsRetryable should be true")
}