Skip to content

Commit

Permalink
Add another test for #37.
Browse files Browse the repository at this point in the history
  • Loading branch information
kurin committed Feb 17, 2018
1 parent b4c0502 commit 6ce4bea
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions b2/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,14 +735,21 @@ func TestWriteEmpty(t *testing.T) {
type rtCounter struct {
rt http.RoundTripper
trips int
api string
sync.Mutex
}

func (rt *rtCounter) RoundTrip(r *http.Request) (*http.Response, error) {
rt.Lock()
defer rt.Unlock()
rt.trips++
return rt.rt.RoundTrip(r)
resp, err := rt.rt.RoundTrip(r)
if err != nil {
return resp, err
}
if rt.api == "" || r.Header.Get("X-Blazer-Method") == rt.api {
rt.trips++
}
return resp, nil
}

func TestAttrsNoRoundtrip(t *testing.T) {
Expand Down Expand Up @@ -820,6 +827,32 @@ func TestAttrsFewRoundtrips(t *testing.T) {
}
}

func TestSmallUploadsFewRoundtrips(t *testing.T) {
rt := &rtCounter{rt: defaultTransport, api: "b2_get_upload_url"}
defaultTransport = rt
defer func() {
defaultTransport = rt.rt
}()

ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 10*time.Minute)
defer cancel()

bucket, done := startLiveTest(ctx, t)
defer done()

for i := 0; i < 10; i++ {
_, _, err := writeFile(ctx, bucket, fmt.Sprintf("%s.%d", smallFileName, i), 42, 1e8)
if err != nil {
t.Fatal(err)
}
}
if rt.trips > 3 {
// Pool is not guaranteed to be valid, so 3 calls allows some slack.
t.Errorf("too many calls to b2_get_upload_url: got %d, want < 3", rt.trips)
}
}

func TestDeleteWithoutName(t *testing.T) {
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 10*time.Minute)
Expand Down

0 comments on commit 6ce4bea

Please sign in to comment.