sdk: ignore panics due to stray goroutines logging after a test completes (#6632)
If there is imperfect goroutine lifespan tracking if we pipe our logs through testing.T.Logf there is a chance of a stray goroutine attempting to log after the test that spawned it completes. This results in a panic of: panic: Log in goroutine after TestLeader_SecondaryCA_Initialize has completed... This isn't great and should be fixed, but quickly runs into situations around externally cancelling blocking queries which isn't terribly possible at the moment. The concession here is to ignore these specific panics for now. This can be triggered easily when running some tests with a high `-count=YYY` value.
This commit is contained in:
parent
bec25f1eb8
commit
0425acf58c
|
@ -38,6 +38,19 @@ func (tw *testWriter) Write(p []byte) (n int, err error) {
|
||||||
if sendTestLogsToStdout || tw.t == nil {
|
if sendTestLogsToStdout || tw.t == nil {
|
||||||
fmt.Fprint(os.Stdout, strings.TrimSpace(string(p))+"\n")
|
fmt.Fprint(os.Stdout, strings.TrimSpace(string(p))+"\n")
|
||||||
} else {
|
} else {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
if sr, ok := r.(string); ok {
|
||||||
|
if strings.HasPrefix(sr, "Log in goroutine after ") {
|
||||||
|
// These sorts of panics are undesirable, but requires
|
||||||
|
// total control over goroutine lifetimes to correct.
|
||||||
|
fmt.Fprint(os.Stdout, "SUPPRESSED PANIC: "+sr+"\n")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic(r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
tw.t.Log(strings.TrimSpace(string(p)))
|
tw.t.Log(strings.TrimSpace(string(p)))
|
||||||
}
|
}
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
|
|
Loading…
Reference in a new issue