Skip to content

Commit c02c6a1

Browse files
zeripathlunny
authored andcommitted
Fix race in integration testlogger (#6556)
* Fix race in logger * At testing end drop the reference to the last test.
1 parent 346036d commit c02c6a1

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

integrations/integration_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ func TestMain(m *testing.M) {
8181
}
8282
exitCode := m.Run()
8383

84+
writerCloser.t = nil
85+
8486
if err = os.RemoveAll(setting.Indexer.IssuePath); err != nil {
8587
fmt.Printf("os.RemoveAll: %v\n", err)
8688
os.Exit(1)

integrations/testlogger.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@ func (w *testLoggerWriterCloser) Write(p []byte) (int, error) {
3333
if len(p) > 0 && p[len(p)-1] == '\n' {
3434
p = p[:len(p)-1]
3535
}
36+
37+
defer func() {
38+
err := recover()
39+
if err == nil {
40+
return
41+
}
42+
var errString string
43+
errErr, ok := err.(error)
44+
if ok {
45+
errString = errErr.Error()
46+
} else {
47+
errString, ok = err.(string)
48+
}
49+
if !ok {
50+
panic(err)
51+
}
52+
if !strings.HasPrefix(errString, "Log in goroutine after ") {
53+
panic(err)
54+
}
55+
}()
56+
3657
w.t.Log(string(p))
3758
return len(p), nil
3859
}

0 commit comments

Comments
 (0)