Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/flakeguard/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard

go 1.24.3
go 1.24.0

require (
github.com/andygrunwald/go-jira v1.16.0
Expand Down
12 changes: 7 additions & 5 deletions tools/flakeguard/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io"
"os"
"time"

Expand Down Expand Up @@ -29,14 +28,17 @@ func Execute() {
}

func init() {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
zerolog.TimeFieldFormat = time.RFC3339Nano
log.Logger = log.Output(zerolog.ConsoleWriter{
Out: io.Discard,
TimeFormat: "15:04:05.00", // hh:mm:ss.ss format
})
// log.Logger = log.Output(zerolog.ConsoleWriter{
// Out: io.Discard,
// TimeFormat: "15:04:05.00", // hh:mm:ss.ss format
// })
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

log.Info().Msg("FlakeGuard tool initialized - 0.0.1")

rootCmd.AddCommand(cmd.FindTestsCmd)
rootCmd.AddCommand(cmd.RunTestsCmd)
rootCmd.AddCommand(cmd.CheckTestOwnersCmd)
Expand Down
36 changes: 19 additions & 17 deletions tools/flakeguard/runner/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -102,20 +103,20 @@ func (e *commandExecutor) RunTestPackage(cfg Config, packageName string, runInde
var stderrBuf bytes.Buffer
cmd.Stderr = &stderrBuf

stdoutBytes, err := cmd.Output()

writeErr := os.WriteFile(tempFilePath, stdoutBytes, 0644)
if writeErr != nil {
log.Error().Err(writeErr).Str("file", tempFilePath).Msg("Failed to write captured stdout to temp file")
_ = os.Remove(tempFilePath)
return "", false, fmt.Errorf("failed to write command output to %s: %w", tempFilePath, writeErr)
// Open the temp file for writing
tmpFileWriter, err := os.OpenFile(tempFilePath, os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return "", false, fmt.Errorf("failed to open temp file for writing: %w", err)
}
defer tmpFileWriter.Close()

if err != nil {
// Write to both STDOUT and the file
cmd.Stdout = io.MultiWriter(os.Stdout, tmpFileWriter)

if err := cmd.Run(); err != nil {
if stderrStr := stderrBuf.String(); stderrStr != "" {
log.Error().Str("package", packageName).Str("stderr", stderrStr).Msg("Command failed with error and stderr output")
}

var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
return tempFilePath, false, nil
Expand Down Expand Up @@ -161,16 +162,17 @@ func (e *commandExecutor) RunCmd(cfg Config, testCmd []string, runIndex int) (te
var stderrBuf bytes.Buffer
cmd.Stderr = &stderrBuf

stdoutBytes, err := cmd.Output()

writeErr := os.WriteFile(tempFilePath, stdoutBytes, 0644)
if writeErr != nil {
log.Error().Err(writeErr).Str("file", tempFilePath).Msg("Failed to write captured stdout to temp file (cmd run)")
_ = os.Remove(tempFilePath)
return "", false, fmt.Errorf("failed to write command output to %s: %w", tempFilePath, writeErr)
// Open the temp file for writing
tmpFileWriter, err := os.OpenFile(tempFilePath, os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return "", false, fmt.Errorf("failed to open temp file for writing: %w", err)
}
defer tmpFileWriter.Close()

if err != nil {
// Write to both STDOUT and the file
cmd.Stdout = io.MultiWriter(os.Stdout, tmpFileWriter)

if err := cmd.Run(); err != nil {
if stderrStr := stderrBuf.String(); stderrStr != "" {
log.Error().Str("command", strings.Join(testCmd, " ")).Str("stderr", stderrStr).Msg("Custom command failed with error and stderr output")
}
Expand Down
4 changes: 2 additions & 2 deletions tools/flakeguard/runner/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,13 @@ func (p *defaultParser) processEvent(state *testProcessingState, rawEv rawEventD
return
}

if panicStarted := startPanicRe.MatchString(event.Output); panicStarted {
if startPanicRe.MatchString(event.Output) {
state.panicDetectionMode = true
state.detectedEntries = append(state.detectedEntries, rawEv)
return
}

if raceStarted := startRaceRe.MatchString(event.Output); raceStarted {
if startRaceRe.MatchString(event.Output) {
state.raceDetectionMode = true
state.detectedEntries = append(state.detectedEntries, rawEv)
return
Expand Down
Loading