Skip to content

Commit c41f5df

Browse files
authored
[skip-changelog] Removed race condition in CI tests (#2963)
1 parent 846216e commit c41f5df

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

internal/integrationtest/arduino-cli.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,17 +354,15 @@ func (cli *ArduinoCLI) RunWithCustomInput(in io.Reader, args ...string) ([]byte,
354354
return stdoutBuf.Bytes(), errBuf, err
355355
}
356356

357-
func (cli *ArduinoCLI) run(ctx context.Context, stdoutBuff, stderrBuff io.Writer, stdinBuff io.Reader, env map[string]string, args ...string) error {
357+
func (cli *ArduinoCLI) run(ctx context.Context, stdoutBuff, stderrBuff io.Writer, stdinBuff io.Reader, env map[string]string, args ...string) (_err error) {
358358
if cli.cliConfigPath != nil {
359359
args = append([]string{"--config-file", cli.cliConfigPath.String()}, args...)
360360
}
361361

362362
// Accumulate all output to terminal and spit-out all at once at the end of the test
363363
// This allows to correctly group test output when running t.Parallel() tests.
364364
terminalOut := new(bytes.Buffer)
365-
defer func() {
366-
fmt.Print(terminalOut.String())
367-
}()
365+
terminalErr := new(bytes.Buffer)
368366

369367
// Github-actions workflow tags to fold log lines
370368
if os.Getenv("GITHUB_ACTIONS") != "" {
@@ -373,6 +371,12 @@ func (cli *ArduinoCLI) run(ctx context.Context, stdoutBuff, stderrBuff io.Writer
373371
}
374372

375373
fmt.Fprintln(terminalOut, color.HiBlackString(">>> Running: ")+color.HiYellowString("%s %s %s", cli.path, strings.Join(args, " "), env))
374+
defer func() {
375+
fmt.Print(terminalOut.String())
376+
fmt.Print(terminalErr.String())
377+
fmt.Println(color.HiBlackString("<<< Run completed (err = %v)", _err))
378+
}()
379+
376380
cliProc, err := paths.NewProcessFromPath(cli.convertEnvForExecutils(env), cli.path, args...)
377381
cli.t.NoError(err)
378382
stdout, err := cliProc.StdoutPipe()
@@ -401,20 +405,19 @@ func (cli *ArduinoCLI) run(ctx context.Context, stdoutBuff, stderrBuff io.Writer
401405
if stderrBuff == nil {
402406
stderrBuff = io.Discard
403407
}
404-
if _, err := io.Copy(stderrBuff, io.TeeReader(stderr, terminalOut)); err != nil {
405-
fmt.Fprintln(terminalOut, color.HiBlackString("<<< stderr copy error:"), err)
408+
if _, err := io.Copy(stderrBuff, io.TeeReader(stderr, terminalErr)); err != nil {
409+
fmt.Fprintln(terminalErr, color.HiBlackString("<<< stderr copy error:"), err)
406410
}
407411
}()
408412
if stdinBuff != nil {
409413
go func() {
410414
if _, err := io.Copy(stdin, stdinBuff); err != nil {
411-
fmt.Fprintln(terminalOut, color.HiBlackString("<<< stdin copy error:"), err)
415+
fmt.Fprintln(terminalErr, color.HiBlackString("<<< stdin copy error:"), err)
412416
}
413417
}()
414418
}
415419
cliErr := cliProc.WaitWithinContext(ctx)
416420
wg.Wait()
417-
fmt.Fprintln(terminalOut, color.HiBlackString("<<< Run completed (err = %v)", cliErr))
418421

419422
return cliErr
420423
}

0 commit comments

Comments
 (0)