From bb451e197116c77d7ad3e0f4cd1a760b54f0e408 Mon Sep 17 00:00:00 2001 From: Victor Elias Date: Fri, 24 Dec 2021 20:23:54 -0300 Subject: [PATCH] record-tester: Accumulate errors from finite testers --- internal/testers/streamer2.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/internal/testers/streamer2.go b/internal/testers/streamer2.go index 2cb88e42..f58a1d40 100644 --- a/internal/testers/streamer2.go +++ b/internal/testers/streamer2.go @@ -2,7 +2,9 @@ package testers import ( "context" + "errors" "fmt" + "strings" "time" "github.com/golang/glog" @@ -94,16 +96,31 @@ func (sr *streamer2) StartStreaming(sourceFileName string, rtmpIngestURL, mediaU tests = append(tests, startFunc(sr.ctx, mediaURL, waitForTarget, sr.Streamer2Options)) } go func() { - testsDone := onAnyDone(sr.ctx, tests) + var ( + ctx, cancel = context.WithCancel(sr.ctx) + testsDone = onAnyDone(ctx, tests) + errs = []string{} + ) + defer cancel() for { select { - case <-sr.ctx.Done(): - return case test := <-testsDone: if err := test.GlobalErr(); err != nil { - sr.fatalEnd(err) - return + if sr.globalError == nil { + sr.globalError = err + time.AfterFunc(10*time.Second, cancel) + } + errs = append(errs, err.Error()) + } + case <-ctx.Done(): + if len(errs) > 0 { + msg := errs[0] + if len(errs) > 1 { + msg = "Multiple errors: " + strings.Join(errs, "; ") + } + sr.fatalEnd(errors.New(msg)) } + return } } }()