66 "fmt"
77 "os"
88 "os/exec"
9- "path/filepath"
109
1110 "github.com/rs/zerolog/log"
1211 "github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/reports"
@@ -62,13 +61,6 @@ var RunTestsCmd = &cobra.Command{
6261 os .Exit (ErrorExitCode )
6362 }
6463
65- outputDir := filepath .Dir (outputPath )
66- initialDirSize , err := getDirSize (outputDir )
67- if err != nil {
68- log .Error ().Err (err ).Str ("path" , outputDir ).Msg ("Error getting initial directory size" )
69- // intentionally don't exit here, as we can still proceed with the run
70- }
71-
7264 // Check if project dependencies are correctly set up
7365 if err := checkDependencies (projectPath ); err != nil {
7466 log .Error ().Err (err ).Msg ("Error checking project dependencies" )
@@ -112,26 +104,27 @@ var RunTestsCmd = &cobra.Command{
112104
113105 // Run the tests
114106 var (
115- testReport * reports.TestReport
107+ firstReport * reports.TestReport
116108 )
117109
110+ var err error
118111 if len (testCmdStrings ) > 0 {
119- testReport , err = testRunner .RunTestCmd (testCmdStrings )
112+ firstReport , err = testRunner .RunTestCmd (testCmdStrings )
120113 if err != nil {
121114 log .Fatal ().Err (err ).Msg ("Error running custom test command" )
122115 os .Exit (ErrorExitCode )
123116 }
124117 } else {
125- testReport , err = testRunner .RunTestPackages (testPackages )
118+ firstReport , err = testRunner .RunTestPackages (testPackages )
126119 if err != nil {
127120 log .Fatal ().Err (err ).Msg ("Error running test packages" )
128121 os .Exit (ErrorExitCode )
129122 }
130123 }
131124
132125 // Save the test results in JSON format
133- if outputPath != "" && len (testReport .Results ) > 0 {
134- jsonData , err := json .MarshalIndent (testReport , "" , " " )
126+ if outputPath != "" && len (firstReport .Results ) > 0 {
127+ jsonData , err := json .MarshalIndent (firstReport , "" , " " )
135128 if err != nil {
136129 log .Error ().Err (err ).Msg ("Error marshaling test results to JSON" )
137130 os .Exit (ErrorExitCode )
@@ -143,14 +136,17 @@ var RunTestsCmd = &cobra.Command{
143136 log .Info ().Str ("path" , outputPath ).Msg ("Test results saved" )
144137 }
145138
146- if len (testReport .Results ) == 0 {
139+ if len (firstReport .Results ) == 0 {
147140 log .Warn ().Msg ("No tests were run for the specified packages" )
148141 return
149142 }
150143
144+ fmt .Printf ("\n Flakeguard Initial Summary:\n " )
145+ reports .RenderResults (os .Stdout , firstReport , false , false )
146+
151147 // Rerun failed tests
152148 if rerunFailed > 0 {
153- rerunReport , err := testRunner .RerunFailedTests (testReport .Results )
149+ rerunReport , err := testRunner .RerunFailedTests (firstReport .Results )
154150 if err != nil {
155151 log .Fatal ().Err (err ).Msg ("Error rerunning failed tests" )
156152 os .Exit (ErrorExitCode )
@@ -160,59 +156,37 @@ var RunTestsCmd = &cobra.Command{
160156 failedAfterRerun := reports .FilterTests (rerunReport .Results , func (tr reports.TestResult ) bool {
161157 return ! tr .Skipped && tr .Successes == 0
162158 })
159+ fmt .Printf ("\n Flakeguard Rerun Summary:\n " )
160+ reports .RenderResults (os .Stdout , rerunReport , false , false )
161+
163162 if len (failedAfterRerun ) > 0 {
164163 log .Error ().
165164 Int ("tests" , len (failedAfterRerun )).
166165 Int ("reruns" , rerunFailed ).
167166 Msg ("Tests still failing after reruns with 0 successes" )
168167 os .Exit (ErrorExitCode )
168+ } else {
169+ log .Info ().Msg ("Failed tests passed at least once after reruns" )
170+ os .Exit (0 )
169171 }
170172
171173 // TODO: save rerun test report to JSON file
172174 }
173175
174176 // Filter flaky tests using FilterTests
175- flakyTests := reports .FilterTests (testReport .Results , func (tr reports.TestResult ) bool {
177+ flakyTests := reports .FilterTests (firstReport .Results , func (tr reports.TestResult ) bool {
176178 return ! tr .Skipped && tr .PassRatio < passRatioThreshold
177179 })
178180
179- finalDirSize , err := getDirSize (outputDir )
180- if err != nil {
181- log .Error ().Err (err ).Str ("path" , outputDir ).Msg ("Error getting final directory size" )
182- // intentionally don't exit here, as we can still proceed with the run
183- }
184- diskSpaceUsed := byteCountSI (finalDirSize - initialDirSize )
185-
186- // Report with more detailed information about reruns
187- if rerunFailed > 0 {
188- log .Info ().
189- Int ("initial runs" , runCount ).
190- Int ("reruns for failed tests" , rerunFailed ).
191- Str ("disk space used" , diskSpaceUsed ).
192- Msg ("Test execution completed" )
193- } else {
194- log .Info ().
195- Int ("runs" , runCount ).
196- Str ("disk space used" , diskSpaceUsed ).
197- Msg ("Test execution completed" )
198- }
199-
200181 if len (flakyTests ) > 0 {
201182 log .Info ().
202183 Int ("count" , len (flakyTests )).
203184 Str ("stability threshold" , fmt .Sprintf ("%.0f%%" , passRatioThreshold * 100 )).
204185 Msg ("Found flaky tests" )
186+ os .Exit (FlakyTestsExitCode )
205187 } else {
206188 log .Info ().Msg ("All tests passed stability requirements" )
207189 }
208-
209- fmt .Printf ("\n Flakeguard Summary\n " )
210- reports .RenderResults (os .Stdout , testReport , false , false )
211-
212- if len (flakyTests ) > 0 {
213- // Exit with error code if there are flaky tests
214- os .Exit (FlakyTestsExitCode )
215- }
216190 },
217191}
218192
0 commit comments