-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexponential_backoff_test.go
60 lines (49 loc) · 1.58 KB
/
exponential_backoff_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
package seatsio
import (
"github.com/seatsio/seatsio-go/v9/shared"
"github.com/seatsio/seatsio-go/v9/test_util"
"github.com/stretchr/testify/require"
"testing"
"time"
)
func TestMain(m *testing.M) {
_, _ = shared.ApiClient("aSecretKey", "https://httpbin.seatsio.net").R().Get("/status/200")
m.Run()
}
func TestAbortsEventuallyIfServerKeepsReturning429(t *testing.T) {
t.Parallel()
start := time.Now()
response, _ := shared.ApiClient("aSecretKey", "https://httpbin.seatsio.net").
R().
Get("/status/429")
elapsed := time.Now().Sub(start)
require.Greater(t, int(elapsed.Seconds()), 10)
require.Less(t, int(elapsed.Seconds()), 25)
require.Equal(t, 429, response.StatusCode)
}
func TestAbortsDirectlyIfServerReturnsOtherErrorThan429(t *testing.T) {
t.Parallel()
start := time.Now()
response, _ := shared.ApiClient("aSecretKey", "https://httpbin.seatsio.net").
R().
Get("/status/400")
elapsed := time.Now().Sub(start)
require.Less(t, int(elapsed.Seconds()), 5)
require.Equal(t, 400, response.StatusCode)
}
func TestReturnsSuccessfullyWhenServerSends429FirstAndThenSuccess(t *testing.T) {
t.Parallel()
for i := 0; i < 20; i++ {
response, _ := shared.ApiClient("aSecretKey", "https://httpbin.seatsio.net").
R().
Get("/status/429:0.25,204:0.75")
require.Equal(t, 204, response.StatusCode)
}
}
func TestMaxRecountMustNotBeNegative(t *testing.T) {
t.Parallel()
company := test_util.CreateTestCompany(t)
client := NewSeatsioClient(test_util.BaseUrl, company.Admin.SecretKey)
err := client.SetMaxRetries(-1)
require.Equal(t, "retry count must not be negative", err.Error())
}