File tree 1 file changed +22
-2
lines changed
1 file changed +22
-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,9 @@ 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
+ }
91
94
r .done = make (chan struct {})
92
95
defer close (r .done )
93
96
@@ -132,3 +135,20 @@ func (r *TestRun) Cleanup(ctx context.Context) (err error) {
132
135
//nolint:revive // we use named returns because we mutate it in a defer
133
136
return
134
137
}
138
+
139
+ type syncBuffer struct {
140
+ buf * bytes.Buffer
141
+ mut sync.Mutex
142
+ }
143
+
144
+ func (sb * syncBuffer ) Write (p []byte ) (n int , err error ) {
145
+ sb .mut .Lock ()
146
+ defer sb .mut .Unlock ()
147
+ return sb .buf .Write (p )
148
+ }
149
+
150
+ func (sb * syncBuffer ) String () string {
151
+ sb .mut .Lock ()
152
+ defer sb .mut .Unlock ()
153
+ return sb .buf .String ()
154
+ }
You can’t perform that action at this time.
0 commit comments