diff options
author | zeripath <art27@cantab.net> | 2021-09-01 14:05:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-01 14:05:04 +0100 |
commit | 6e0e414f553279d0ee330b078637d2b163b85159 (patch) | |
tree | 217053e0c86428ff1efdf5a84a60a79191c21aa3 /integrations/testlogger.go | |
parent | de2e96e37b58eebd0cee1def7f07e6e96023c207 (diff) | |
download | gitea-6e0e414f553279d0ee330b078637d2b163b85159.tar.gz gitea-6e0e414f553279d0ee330b078637d2b163b85159.zip |
Ensure that the testlogger has its final test removal safely (#16907)
It is possible to get a data race right at the end of the TestMain
in integrations during the final removal of the test from the testlogger. This PR
uses a Reset function to remove any final tests but adds some extra
logging which will forcibly fail if there is an unclosed logger.
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'integrations/testlogger.go')
-rw-r--r-- | integrations/testlogger.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/integrations/testlogger.go b/integrations/testlogger.go index ff408b314c..69db480c15 100644 --- a/integrations/testlogger.go +++ b/integrations/testlogger.go @@ -90,6 +90,21 @@ func (w *testLoggerWriterCloser) Close() error { return nil } +func (w *testLoggerWriterCloser) Reset() { + w.Lock() + if len(w.t) > 0 { + for _, t := range w.t { + if t == nil { + continue + } + fmt.Fprintf(os.Stdout, "Unclosed logger writer in test: %s", (*t).Name()) + (*t).Errorf("Unclosed logger writer in test: %s", (*t).Name()) + } + w.t = nil + } + w.Unlock() +} + // PrintCurrentTest prints the current test to os.Stdout func PrintCurrentTest(t testing.TB, skip ...int) func() { start := time.Now() |