@@ -13,6 +13,7 @@ import (
13
13
"bufio"
14
14
"context"
15
15
"encoding/json"
16
+ "fmt"
16
17
"io"
17
18
"os/exec"
18
19
"strings"
@@ -32,6 +33,7 @@ type Runner struct {
32
33
StderrChan chan string
33
34
readChan chan string
34
35
doneChan chan struct {}
36
+ errChan chan error
35
37
36
38
InitMsg InitMsg
37
39
t * testing.T
@@ -42,7 +44,7 @@ type Runner struct {
42
44
readCursor int
43
45
}
44
46
45
- func runStreamChannel (t * testing. T , sender chan string , buffer * bufio.Scanner ) {
47
+ func runStreamChannel (sender chan string , errChan chan error , buffer * bufio.Scanner ) {
46
48
buf := make ([]byte , 0 , 64 * 1024 )
47
49
buffer .Buffer (buf , 1024 * 1024 )
48
50
go func () {
@@ -55,8 +57,11 @@ func runStreamChannel(t *testing.T, sender chan string, buffer *bufio.Scanner) {
55
57
56
58
}
57
59
}
60
+ // the go testing libraries don't like it when you call
61
+ // t.Fail() in a child thread; so we have to trickle down the failure
58
62
if err := buffer .Err (); err != nil {
59
- t .Logf ("scanner error: %s" , err )
63
+ errChan <- fmt .Errorf ("error in buffer: %w" , err )
64
+ return
60
65
}
61
66
62
67
}
@@ -96,8 +101,8 @@ func (runner *Runner) Start() {
96
101
stderrStream := bufio .NewScanner (runner .Stderr )
97
102
stdoutStream := bufio .NewScanner (runner .Stdout )
98
103
99
- runStreamChannel (runner .t , runner .StdoutChan , stdoutStream )
100
- runStreamChannel (runner .t , runner .StderrChan , stderrStream )
104
+ runStreamChannel (runner .StdoutChan , runner .errChan , stdoutStream )
105
+ runStreamChannel (runner .StderrChan , runner .errChan , stderrStream )
101
106
102
107
go func () {
103
108
runner .runIORead ()
@@ -125,6 +130,8 @@ func (runner *Runner) GetNextEventOut(types ...string) string {
125
130
select {
126
131
case <- ctx .Done ():
127
132
runner .t .Fatalf ("timed out waiting for %v events" , types )
133
+ case err := <- runner .errChan :
134
+ require .NoError (runner .t , err , "error reading from stdout/stderr in buffer" )
128
135
case line := <- runner .readChan :
129
136
var resp baseEvent
130
137
err := json .Unmarshal ([]byte (line ), & resp )
@@ -171,6 +178,7 @@ func NewEbpfRunner(ctx context.Context, t *testing.T, args ...string) *Runner {
171
178
StderrChan : make (chan string , 1024 ),
172
179
readChan : make (chan string , 1024 ),
173
180
doneChan : make (chan struct {}),
181
+ errChan : make (chan error , 1 ),
174
182
t : t ,
175
183
}
176
184
args = append (args , "--print-features-on-init" , "--unbuffer-stdout" , "--libbpf-verbose" )
0 commit comments