aboutsummaryrefslogtreecommitdiffstats
path: root/integrations
diff options
context:
space:
mode:
authorMura Li <typeless@users.noreply.github.com>2019-09-17 17:39:37 +0800
committerLauris BH <lauris.buksis@zzdats.lv>2019-09-17 12:39:37 +0300
commiteec997d30ab299049f775609f2dd61041144ee74 (patch)
tree3b39ba7efb275d8343cf76415fc520a503ab9496 /integrations
parenta629904b30b57c6d1441648fad274a39e5ff83f2 (diff)
downloadgitea-eec997d30ab299049f775609f2dd61041144ee74.tar.gz
gitea-eec997d30ab299049f775609f2dd61041144ee74.zip
Fix data race (#8204)
* Fix data race * Fix data race in modules/log * Make the scope of lock finner-grained * Use syc.Map * Fix missing change in the test * Do not export LoggerMap
Diffstat (limited to 'integrations')
-rw-r--r--integrations/testlogger.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/integrations/testlogger.go b/integrations/testlogger.go
index 43a1471f66..91b94ac9f3 100644
--- a/integrations/testlogger.go
+++ b/integrations/testlogger.go
@@ -10,6 +10,7 @@ import (
"os"
"runtime"
"strings"
+ "sync"
"testing"
"code.gitea.io/gitea/modules/log"
@@ -25,11 +26,21 @@ type TestLogger struct {
var writerCloser = &testLoggerWriterCloser{}
type testLoggerWriterCloser struct {
+ sync.RWMutex
t testing.TB
}
+func (w *testLoggerWriterCloser) setT(t *testing.TB) {
+ w.Lock()
+ w.t = *t
+ w.Unlock()
+}
+
func (w *testLoggerWriterCloser) Write(p []byte) (int, error) {
- if w.t != nil {
+ w.RLock()
+ t := w.t
+ w.RUnlock()
+ if t != nil {
if len(p) > 0 && p[len(p)-1] == '\n' {
p = p[:len(p)-1]
}
@@ -54,7 +65,7 @@ func (w *testLoggerWriterCloser) Write(p []byte) (int, error) {
}
}()
- w.t.Log(string(p))
+ t.Log(string(p))
return len(p), nil
}
return len(p), nil
@@ -77,7 +88,7 @@ func PrintCurrentTest(t testing.TB, skip ...int) {
} else {
fmt.Fprintf(os.Stdout, "=== %s (%s:%d)\n", t.Name(), strings.TrimPrefix(filename, prefix), line)
}
- writerCloser.t = t
+ writerCloser.setT(&t)
}
// Printf takes a format and args and prints the string to os.Stdout