File tree 1 file changed +23
-2
lines changed 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change 4
4
"bytes"
5
5
"context"
6
6
"io"
7
+ "sync"
7
8
"time"
8
9
9
10
"golang.org/x/xerrors"
@@ -65,7 +66,7 @@ type TestRun struct {
65
66
id string
66
67
runner Runnable
67
68
68
- logs * bytes. Buffer
69
+ logs * syncBuffer
69
70
done chan struct {}
70
71
started time.Time
71
72
duration time.Duration
@@ -87,7 +88,10 @@ func (r *TestRun) FullID() string {
87
88
// Run executes the Run function with a self-managed log writer, panic handler,
88
89
// error recording and duration recording. The test error is returned.
89
90
func (r * TestRun ) Run (ctx context.Context ) (err error ) {
90
- r .logs = new (bytes.Buffer )
91
+ r .logs = & syncBuffer {
92
+ buf : new (bytes.Buffer ),
93
+ mut : new (sync.Mutex ),
94
+ }
91
95
r .done = make (chan struct {})
92
96
defer close (r .done )
93
97
@@ -132,3 +136,20 @@ func (r *TestRun) Cleanup(ctx context.Context) (err error) {
132
136
//nolint:revive // we use named returns because we mutate it in a defer
133
137
return
134
138
}
139
+
140
+ type syncBuffer struct {
141
+ buf * bytes.Buffer
142
+ mut * sync.Mutex
143
+ }
144
+
145
+ func (sb * syncBuffer ) Write (p []byte ) (n int , err error ) {
146
+ sb .mut .Lock ()
147
+ defer sb .mut .Unlock ()
148
+ return sb .buf .Write (p )
149
+ }
150
+
151
+ func (sb * syncBuffer ) String () string {
152
+ sb .mut .Lock ()
153
+ defer sb .mut .Unlock ()
154
+ return sb .buf .String ()
155
+ }
You can’t perform that action at this time.
0 commit comments