Skip to content

Commit c674263

Browse files
Fix race conditions in tests
1 parent 286828e commit c674263

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

client_test.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -988,14 +988,14 @@ func testPipelineClientDo(t *testing.T, c *PipelineClient) {
988988
time.Sleep(10 * time.Millisecond)
989989
continue
990990
}
991-
t.Fatalf("unexpected error on iteration %d: %s", i, err)
991+
t.Errorf("unexpected error on iteration %d: %s", i, err)
992992
}
993993
if resp.StatusCode() != StatusOK {
994-
t.Fatalf("unexpected status code: %d. Expecting %d", resp.StatusCode(), StatusOK)
994+
t.Errorf("unexpected status code: %d. Expecting %d", resp.StatusCode(), StatusOK)
995995
}
996996
body := string(resp.Body())
997997
if body != "OK" {
998-
t.Fatalf("unexpected body: %q. Expecting %q", body, "OK")
998+
t.Errorf("unexpected body: %q. Expecting %q", body, "OK")
999999
}
10001000

10011001
// sleep for a while, so the connection to the host may expire.
@@ -1705,10 +1705,10 @@ func testClientDoTimeoutError(t *testing.T, c *Client, n int) {
17051705
for i := 0; i < n; i++ {
17061706
err := c.DoTimeout(&req, &resp, time.Millisecond)
17071707
if err == nil {
1708-
t.Fatalf("expecting error")
1708+
t.Errorf("expecting error")
17091709
}
17101710
if err != ErrTimeout {
1711-
t.Fatalf("unexpected error: %s. Expecting %s", err, ErrTimeout)
1711+
t.Errorf("unexpected error: %s. Expecting %s", err, ErrTimeout)
17121712
}
17131713
}
17141714
}
@@ -1718,16 +1718,16 @@ func testClientGetTimeoutError(t *testing.T, c *Client, n int) {
17181718
for i := 0; i < n; i++ {
17191719
statusCode, body, err := c.GetTimeout(buf, "http://foobar.com/baz", time.Millisecond)
17201720
if err == nil {
1721-
t.Fatalf("expecting error")
1721+
t.Errorf("expecting error")
17221722
}
17231723
if err != ErrTimeout {
1724-
t.Fatalf("unexpected error: %s. Expecting %s", err, ErrTimeout)
1724+
t.Errorf("unexpected error: %s. Expecting %s", err, ErrTimeout)
17251725
}
17261726
if statusCode != 0 {
1727-
t.Fatalf("unexpected statusCode=%d. Expecting %d", statusCode, 0)
1727+
t.Errorf("unexpected statusCode=%d. Expecting %d", statusCode, 0)
17281728
}
17291729
if body == nil {
1730-
t.Fatalf("body must be non-nil")
1730+
t.Errorf("body must be non-nil")
17311731
}
17321732
}
17331733
}
@@ -2326,14 +2326,14 @@ func testClientGet(t *testing.T, c clientGetter, addr string, n int) {
23262326
statusCode, body, err := c.Get(buf, uri)
23272327
buf = body
23282328
if err != nil {
2329-
t.Fatalf("unexpected error when doing http request: %s", err)
2329+
t.Errorf("unexpected error when doing http request: %s", err)
23302330
}
23312331
if statusCode != StatusOK {
2332-
t.Fatalf("unexpected status code: %d. Expecting %d", statusCode, StatusOK)
2332+
t.Errorf("unexpected status code: %d. Expecting %d", statusCode, StatusOK)
23332333
}
23342334
resultURI := string(body)
23352335
if resultURI != uri {
2336-
t.Fatalf("unexpected uri %q. Expecting %q", resultURI, uri)
2336+
t.Errorf("unexpected uri %q. Expecting %q", resultURI, uri)
23372337
}
23382338
}
23392339
}
@@ -2346,17 +2346,17 @@ func testClientDoTimeoutSuccess(t *testing.T, c *Client, addr string, n int) {
23462346
uri := fmt.Sprintf("%s/foo/%d?bar=baz", addr, i)
23472347
req.SetRequestURI(uri)
23482348
if err := c.DoTimeout(&req, &resp, time.Second); err != nil {
2349-
t.Fatalf("unexpected error: %s", err)
2349+
t.Errorf("unexpected error: %s", err)
23502350
}
23512351
if resp.StatusCode() != StatusOK {
2352-
t.Fatalf("unexpected status code: %d. Expecting %d", resp.StatusCode(), StatusOK)
2352+
t.Errorf("unexpected status code: %d. Expecting %d", resp.StatusCode(), StatusOK)
23532353
}
23542354
resultURI := string(resp.Body())
23552355
if strings.HasPrefix(uri, "https") {
23562356
resultURI = uri[:5] + resultURI[4:]
23572357
}
23582358
if resultURI != uri {
2359-
t.Fatalf("unexpected uri %q. Expecting %q", resultURI, uri)
2359+
t.Errorf("unexpected uri %q. Expecting %q", resultURI, uri)
23602360
}
23612361
}
23622362
}
@@ -2368,17 +2368,17 @@ func testClientGetTimeoutSuccess(t *testing.T, c *Client, addr string, n int) {
23682368
statusCode, body, err := c.GetTimeout(buf, uri, time.Second)
23692369
buf = body
23702370
if err != nil {
2371-
t.Fatalf("unexpected error when doing http request: %s", err)
2371+
t.Errorf("unexpected error when doing http request: %s", err)
23722372
}
23732373
if statusCode != StatusOK {
2374-
t.Fatalf("unexpected status code: %d. Expecting %d", statusCode, StatusOK)
2374+
t.Errorf("unexpected status code: %d. Expecting %d", statusCode, StatusOK)
23752375
}
23762376
resultURI := string(body)
23772377
if strings.HasPrefix(uri, "https") {
23782378
resultURI = uri[:5] + resultURI[4:]
23792379
}
23802380
if resultURI != uri {
2381-
t.Fatalf("unexpected uri %q. Expecting %q", resultURI, uri)
2381+
t.Errorf("unexpected uri %q. Expecting %q", resultURI, uri)
23822382
}
23832383
}
23842384
}
@@ -2394,14 +2394,14 @@ func testClientPost(t *testing.T, c clientPoster, addr string, n int) {
23942394
statusCode, body, err := c.Post(buf, uri, &args)
23952395
buf = body
23962396
if err != nil {
2397-
t.Fatalf("unexpected error when doing http request: %s", err)
2397+
t.Errorf("unexpected error when doing http request: %s", err)
23982398
}
23992399
if statusCode != StatusOK {
2400-
t.Fatalf("unexpected status code: %d. Expecting %d", statusCode, StatusOK)
2400+
t.Errorf("unexpected status code: %d. Expecting %d", statusCode, StatusOK)
24012401
}
24022402
s := string(body)
24032403
if s != argsS {
2404-
t.Fatalf("unexpected response %q. Expecting %q", s, argsS)
2404+
t.Errorf("unexpected response %q. Expecting %q", s, argsS)
24052405
}
24062406
}
24072407
}

0 commit comments

Comments
 (0)