Fix goroutine test fatalf (#6682)

Use t.Error/t.ErrorF instead if t.Fatal/t.Fatalf

Add returns to achieve same behaviour as earlier
This commit is contained in:
Pontus Leitzler 2018-10-23 18:44:20 +02:00 committed by kannappanr
parent 7b7be66fa1
commit 9631d65552
5 changed files with 26 additions and 13 deletions

View File

@ -46,7 +46,8 @@ func TestBuffConnReadTimeout(t *testing.T) {
tcpConn, terr := tcpListener.AcceptTCP() tcpConn, terr := tcpListener.AcceptTCP()
if terr != nil { if terr != nil {
t.Fatalf("failed to accept new connection. %v", terr) t.Errorf("failed to accept new connection. %v", terr)
return
} }
bufconn := newBufConn(tcpConn, 1*time.Second, 1*time.Second) bufconn := newBufConn(tcpConn, 1*time.Second, 1*time.Second)
defer bufconn.Close() defer bufconn.Close()
@ -55,11 +56,13 @@ func TestBuffConnReadTimeout(t *testing.T) {
var b = make([]byte, 12) var b = make([]byte, 12)
_, terr = bufconn.Read(b) _, terr = bufconn.Read(b)
if terr != nil { if terr != nil {
t.Fatalf("failed to read from client. %v", terr) t.Errorf("failed to read from client. %v", terr)
return
} }
received := string(b) received := string(b)
if received != "message one\n" { if received != "message one\n" {
t.Fatalf(`server: expected: "message one\n", got: %v`, received) t.Errorf(`server: expected: "message one\n", got: %v`, received)
return
} }
// Wait for more than read timeout to simulate processing. // Wait for more than read timeout to simulate processing.
@ -67,17 +70,20 @@ func TestBuffConnReadTimeout(t *testing.T) {
_, terr = bufconn.Read(b) _, terr = bufconn.Read(b)
if terr != nil { if terr != nil {
t.Fatalf("failed to read from client. %v", terr) t.Errorf("failed to read from client. %v", terr)
return
} }
received = string(b) received = string(b)
if received != "message two\n" { if received != "message two\n" {
t.Fatalf(`server: expected: "message two\n", got: %v`, received) t.Errorf(`server: expected: "message two\n", got: %v`, received)
return
} }
// Send a response. // Send a response.
_, terr = io.WriteString(bufconn, "messages received\n") _, terr = io.WriteString(bufconn, "messages received\n")
if terr != nil { if terr != nil {
t.Fatalf("failed to write to client. %v", terr) t.Errorf("failed to write to client. %v", terr)
return
} }
// Removes all deadlines if any. // Removes all deadlines if any.

View File

@ -218,7 +218,8 @@ func TestNamespaceForceUnlockTest(t *testing.T) {
// Try to claim lock again. // Try to claim lock again.
anotherLock := globalNSMutex.NewNSLock("bucket", "object") anotherLock := globalNSMutex.NewNSLock("bucket", "object")
if anotherLock.GetLock(newDynamicTimeout(60*time.Second, time.Second)) != nil { if anotherLock.GetLock(newDynamicTimeout(60*time.Second, time.Second)) != nil {
t.Fatalf("Failed to get lock") t.Errorf("Failed to get lock")
return
} }
// And signal success. // And signal success.
ch <- struct{}{} ch <- struct{}{}

View File

@ -2378,14 +2378,16 @@ func testAPINewMultipartHandlerParallel(obj ObjectLayer, instanceType, bucketNam
req, err := newTestSignedRequestV4("POST", getNewMultipartURL("", bucketName, objectName), 0, nil, credentials.AccessKey, credentials.SecretKey, nil) req, err := newTestSignedRequestV4("POST", getNewMultipartURL("", bucketName, objectName), 0, nil, credentials.AccessKey, credentials.SecretKey, nil)
if err != nil { if err != nil {
t.Fatalf("Failed to create HTTP request for NewMultipart request: <ERROR> %v", err) t.Errorf("Failed to create HTTP request for NewMultipart request: <ERROR> %v", err)
return
} }
// Since `apiRouter` satisfies `http.Handler` it has a ServeHTTP to execute the logic of the handler. // Since `apiRouter` satisfies `http.Handler` it has a ServeHTTP to execute the logic of the handler.
// Call the ServeHTTP to executes the registered handler. // Call the ServeHTTP to executes the registered handler.
apiRouter.ServeHTTP(rec, req) apiRouter.ServeHTTP(rec, req)
// Assert the response code with the expected status. // Assert the response code with the expected status.
if rec.Code != http.StatusOK { if rec.Code != http.StatusOK {
t.Fatalf("Minio %s: Expected the response status to be `%d`, but instead found `%d`", instanceType, http.StatusOK, rec.Code) t.Errorf("Minio %s: Expected the response status to be `%d`, but instead found `%d`", instanceType, http.StatusOK, rec.Code)
return
} }
// decode the response body. // decode the response body.
decoder := xml.NewDecoder(rec.Body) decoder := xml.NewDecoder(rec.Body)
@ -2393,7 +2395,8 @@ func testAPINewMultipartHandlerParallel(obj ObjectLayer, instanceType, bucketNam
err = decoder.Decode(multipartResponse) err = decoder.Decode(multipartResponse)
if err != nil { if err != nil {
t.Fatalf("Minio %s: Error decoding the recorded response Body", instanceType) t.Errorf("Minio %s: Error decoding the recorded response Body", instanceType)
return
} }
// push the obtained upload ID from the response into the array. // push the obtained upload ID from the response into the array.
testUploads.Lock() testUploads.Lock()

View File

@ -1046,7 +1046,8 @@ func (s *TestSuiteCommon) TestPutBucket(c *check) {
client := http.Client{Transport: s.transport} client := http.Client{Transport: s.transport}
response, err := client.Do(request) response, err := client.Do(request)
if err != nil { if err != nil {
c.Fatalf("Put bucket Failed: <ERROR> %s", err) c.Errorf("Put bucket Failed: <ERROR> %s", err)
return
} }
defer response.Body.Close() defer response.Body.Close()
}() }()

View File

@ -161,11 +161,13 @@ func TestLockAndUnlock(t *testing.T) {
go func() { go func() {
bl, blerr := LockedOpenFile(f.Name(), os.O_WRONLY, 0600) bl, blerr := LockedOpenFile(f.Name(), os.O_WRONLY, 0600)
if blerr != nil { if blerr != nil {
t.Fatal(blerr) t.Error(blerr)
return
} }
locked <- struct{}{} locked <- struct{}{}
if blerr = bl.Close(); blerr != nil { if blerr = bl.Close(); blerr != nil {
t.Fatal(blerr) t.Error(blerr)
return
} }
}() }()