@@ -106,17 +106,9 @@ func executeRunTestsV2Step(ctx context.Context, f RunFunc, r *api.StartStepReque
106
106
107
107
exited , err := f (ctx , step , out , r .LogDrone , false )
108
108
timeTakenMs := time .Since (start ).Milliseconds ()
109
-
110
- if r .RunTestsV2 .IntelligenceMode {
111
- collectionErr := collectTestReportsAndCg (ctx , log , r , start , step .Name , tiConfig , telemetryData , r .Envs )
112
- if err == nil {
113
- err = collectionErr
114
- }
115
- } else {
116
- _ , collectReportsErr := collectTestReports (ctx , log , r , step .Name , tiConfig , telemetryData )
117
- if err == nil {
118
- err = collectReportsErr
119
- }
109
+ collectionErr := collectTestReportsAndCg (ctx , log , r , start , step .Name , tiConfig , telemetryData , r .Envs )
110
+ if err == nil {
111
+ err = collectionErr
120
112
}
121
113
122
114
if tiConfig .GetParseSavings () {
@@ -199,57 +191,57 @@ func SetupRunTestV2(
199
191
tmpFilePath := filepath .Join (tiConfig .GetDataDir (), instrumentation .GetUniqueHash (uniqueStepID , tiConfig ))
200
192
201
193
var preCmd , filterfilePath string
194
+ if config .IntelligenceMode {
195
+ // This variable should use to pick up the qa version of the agents - this will allow a staging like option for
196
+ // the agents, and would also help in diagnosing issues when needed. The value we look for is specific not a
197
+ // simple "true" to have something that is more unique and hard to guess.
198
+ qaEnvValue , ok := envs ["HARNESS_TI_QA_ENV" ]
199
+ useQAEnv := ok && qaEnvValue == "QA_ENV_ENABLED"
200
+
201
+ links , err := instrumentation .GetV2AgentDownloadLinks (ctx , tiConfig , useQAEnv )
202
+ if err != nil {
203
+ return preCmd , fmt .Errorf ("failed to get AgentV2 URL from TI" )
204
+ }
205
+ if len (links ) < agentV2LinkLength {
206
+ return preCmd , fmt .Errorf ("error: Could not get agent V2 links from TI" )
207
+ }
208
+ client := tiConfig .GetClient ()
209
+ err = downloadJavaAgent (ctx , tmpFilePath , links [0 ].URL , fs , log , client )
210
+ if err != nil {
211
+ return preCmd , fmt .Errorf ("failed to download Java agent" )
212
+ }
202
213
203
- // This variable should use to pick up the qa version of the agents - this will allow a staging like option for
204
- // the agents, and would also help in diagnosing issues when needed. The value we look for is specific not a
205
- // simple "true" to have something that is more unique and hard to guess.
206
- qaEnvValue , ok := envs ["HARNESS_TI_QA_ENV" ]
207
- useQAEnv := ok && qaEnvValue == "QA_ENV_ENABLED"
208
-
209
- links , err := instrumentation .GetV2AgentDownloadLinks (ctx , tiConfig , useQAEnv )
210
- if err != nil {
211
- return preCmd , fmt .Errorf ("failed to get AgentV2 URL from TI" )
212
- }
213
- if len (links ) < agentV2LinkLength {
214
- return preCmd , fmt .Errorf ("error: Could not get agent V2 links from TI" )
215
- }
216
- client := tiConfig .GetClient ()
217
- err = downloadJavaAgent (ctx , tmpFilePath , links [0 ].URL , fs , log , client )
218
- if err != nil {
219
- return preCmd , fmt .Errorf ("failed to download Java agent" )
220
- }
221
-
222
- rubyArtifactDir , err := downloadRubyAgent (ctx , tmpFilePath , links [2 ].URL , fs , log , client )
223
- if err != nil || rubyArtifactDir == "" {
224
- return preCmd , fmt .Errorf ("failed to download Ruby agent" )
225
- }
226
- agentPaths ["ruby" ] = rubyArtifactDir
214
+ rubyArtifactDir , err := downloadRubyAgent (ctx , tmpFilePath , links [2 ].URL , fs , log , client )
215
+ if err != nil || rubyArtifactDir == "" {
216
+ return preCmd , fmt .Errorf ("failed to download Ruby agent" )
217
+ }
218
+ agentPaths ["ruby" ] = rubyArtifactDir
227
219
228
- pythonArtifactDir , err := downloadPythonAgent (ctx , tmpFilePath , links [1 ].URL , fs , log , client )
229
- if err != nil {
230
- return preCmd , fmt .Errorf ("failed to download Python agent" )
231
- }
232
- agentPaths ["python" ] = pythonArtifactDir
220
+ pythonArtifactDir , err := downloadPythonAgent (ctx , tmpFilePath , links [1 ].URL , fs , log , client )
221
+ if err != nil {
222
+ return preCmd , fmt .Errorf ("failed to download Python agent" )
223
+ }
224
+ agentPaths ["python" ] = pythonArtifactDir
233
225
234
- if len (links ) > dotNetAgentLinkIndex {
235
- var dotNetArtifactDir string
236
- dotNetArtifactDir , err = downloadDotNetAgent (ctx , tmpFilePath , links [dotNetAgentLinkIndex ].URL , fs , log , client )
237
- if err == nil {
238
- agentPaths ["dotnet" ] = dotNetArtifactDir
239
- } else {
240
- log .Warningln (".net agent installation failed. Continuing without .net support." )
226
+ if len (links ) > dotNetAgentLinkIndex {
227
+ var dotNetArtifactDir string
228
+ dotNetArtifactDir , err = downloadDotNetAgent (ctx , tmpFilePath , links [dotNetAgentLinkIndex ].URL , fs , log , client )
229
+ if err == nil {
230
+ agentPaths ["dotnet" ] = dotNetArtifactDir
231
+ } else {
232
+ log .Warningln (".net agent installation failed. Continuing without .net support." )
233
+ }
234
+ }
235
+ isPsh := IsPowershell (config .Entrypoint )
236
+ preCmd , filterfilePath , err = getPreCmd (workspace , tmpFilePath , fs , log , envs , agentPaths , isPsh , tiConfig )
237
+ if err != nil || pythonArtifactDir == "" {
238
+ return preCmd , fmt .Errorf ("failed to set config file or env variable to inject agent, %s" , err )
239
+ }
240
+ err = createSelectedTestFile (ctx , fs , stepID , workspace , log , tiConfig , tmpFilePath , envs , config , filterfilePath , testMetadata )
241
+ if err != nil {
242
+ return preCmd , fmt .Errorf ("error while creating filter file %s" , err )
241
243
}
242
244
}
243
- isPsh := IsPowershell (config .Entrypoint )
244
- preCmd , filterfilePath , err = getPreCmd (workspace , tmpFilePath , fs , log , envs , agentPaths , isPsh , tiConfig )
245
- if err != nil || pythonArtifactDir == "" {
246
- return preCmd , fmt .Errorf ("failed to set config file or env variable to inject agent, %s" , err )
247
- }
248
- err = createSelectedTestFile (ctx , fs , stepID , workspace , log , tiConfig , tmpFilePath , envs , config , filterfilePath , testMetadata )
249
- if err != nil {
250
- return preCmd , fmt .Errorf ("error while creating filter file %s" , err )
251
- }
252
-
253
245
return preCmd , nil
254
246
}
255
247
@@ -258,34 +250,15 @@ func SetupRunTestV2(
258
250
func getTestsSelection (ctx context.Context , fs filesystem.FileSystem , stepID , workspace string , log * logrus.Logger ,
259
251
isManual bool , tiConfig * tiCfg.Cfg , envs map [string ]string , runV2Config * api.RunTestsV2Config ) (types.SelectTestsResp , bool ) {
260
252
selection := types.SelectTestsResp {}
261
- runOnlySelectedTests := false
262
- testGlobs := sanitizeTestGlobsV2 (runV2Config .TestGlobs )
263
-
264
- if runV2Config .IntelligenceMode {
265
- if isManual {
266
- log .Infoln ("Manual execution has been detected. Running all the tests" )
267
- runOnlySelectedTests = false
268
- } else {
269
- selection , runOnlySelectedTests = getTestsSelectionWithTiModeEnabled (ctx , fs , stepID , workspace , log , isManual , tiConfig , envs , runV2Config , testGlobs )
270
- }
253
+ if isManual {
254
+ log .Infoln ("Manual execution has been detected. Running all the tests" )
255
+ return selection , false
271
256
}
272
-
273
- // Test splitting: only when parallelism is enabled
274
- if instrumentation .IsParallelismEnabled (envs ) {
275
- log .Debugln ("Parallelism is enabled!" )
276
- runOnlySelectedTests = instrumentation .ComputeSelectedTestsV2 (ctx , runV2Config , log , & selection , stepID , workspace , envs , testGlobs , tiConfig , runOnlySelectedTests , fs )
277
- }
278
-
279
- return selection , runOnlySelectedTests
280
- }
281
-
282
- func getTestsSelectionWithTiModeEnabled (ctx context.Context , fs filesystem.FileSystem , stepID , workspace string , log * logrus.Logger ,
283
- isManual bool , tiConfig * tiCfg.Cfg , envs map [string ]string , runV2Config * api.RunTestsV2Config , testGlobs []string ) (types.SelectTestsResp , bool ) { //nolint:unparam
284
- selection := types.SelectTestsResp {}
285
257
// Question : Here i can see feature state is being defined in Runtest but here we don't have runOnlySelected tests so should we always defined as optimized state
286
258
var files []types.File
287
259
var err error
288
260
runOnlySelectedTests := true
261
+
289
262
if instrumentation .IsPushTriggerExecution (tiConfig ) {
290
263
lastSuccessfulCommitID , commitErr := instrumentation .GetCommitInfo (ctx , stepID , tiConfig )
291
264
if commitErr != nil {
@@ -311,8 +284,8 @@ func getTestsSelectionWithTiModeEnabled(ctx context.Context, fs filesystem.FileS
311
284
return selection , false // TI selected all the tests to be run
312
285
}
313
286
}
314
-
315
287
filesWithpkg := java .ReadPkgs (log , fs , workspace , files )
288
+ testGlobs := sanitizeTestGlobsV2 (runV2Config .TestGlobs )
316
289
selection , err = instrumentation .SelectTests (ctx , workspace , filesWithpkg , runOnlySelectedTests , stepID , testGlobs , fs , tiConfig )
317
290
if err != nil {
318
291
log .WithError (err ).Errorln ("An unexpected error occurred during test selection. Running all tests." )
@@ -324,6 +297,12 @@ func getTestsSelectionWithTiModeEnabled(ctx context.Context, fs filesystem.FileS
324
297
log .Infoln (fmt .Sprintf ("Running tests selected by Test Intelligence: %s" , selection .Tests ))
325
298
runOnlySelectedTests = true
326
299
}
300
+
301
+ // Test splitting: only when parallelism is enabled
302
+ if instrumentation .IsParallelismEnabled (envs ) {
303
+ runOnlySelectedTests = instrumentation .ComputeSelectedTestsV2 (ctx , runV2Config , log , & selection , stepID , workspace , envs , testGlobs , tiConfig , runOnlySelectedTests , fs )
304
+ }
305
+
327
306
return selection , runOnlySelectedTests
328
307
}
329
308
@@ -664,15 +643,13 @@ func createSelectedTestFile(ctx context.Context, fs filesystem.FileSystem, stepI
664
643
tiConfig * tiCfg.Cfg , tmpFilepath string , envs map [string ]string , runV2Config * api.RunTestsV2Config , filterFilePath string , testMetadata * types.TestIntelligenceMetaData ) error {
665
644
isManualExecution := instrumentation .IsManualExecution (tiConfig )
666
645
resp , isFilterFilePresent := getTestsSelection (ctx , fs , stepID , workspace , log , isManualExecution , tiConfig , envs , runV2Config )
667
- if runV2Config .IntelligenceMode {
668
- if tiConfig .GetParseSavings () {
669
- if isFilterFilePresent {
670
- // TI selected subset of tests
671
- tiConfig .WriteFeatureState (stepID , types .TI , types .OPTIMIZED )
672
- } else {
673
- // TI selected all tests or returned an error which resulted in full run
674
- tiConfig .WriteFeatureState (stepID , types .TI , types .FULL_RUN )
675
- }
646
+ if tiConfig .GetParseSavings () {
647
+ if isFilterFilePresent {
648
+ // TI selected subset of tests
649
+ tiConfig .WriteFeatureState (stepID , types .TI , types .OPTIMIZED )
650
+ } else {
651
+ // TI selected all tests or returned an error which resulted in full run
652
+ tiConfig .WriteFeatureState (stepID , types .TI , types .FULL_RUN )
676
653
}
677
654
}
678
655
@@ -737,14 +714,18 @@ func writetoBazelrcFile(log *logrus.Logger, fs filesystem.FileSystem) error {
737
714
return nil
738
715
}
739
716
740
- func collectTestReports (
717
+ func collectTestReportsAndCg (
741
718
ctx context.Context ,
742
719
log * logrus.Logger ,
743
720
r * api.StartStepRequest ,
721
+ start time.Time ,
744
722
stepName string ,
745
723
tiConfig * tiCfg.Cfg ,
746
724
telemetryData * types.TelemetryData ,
747
- ) ([]* types.TestCase , error ) {
725
+ envs map [string ]string ,
726
+ ) error {
727
+ cgStart := time .Now ()
728
+
748
729
if len (r .TestReport .Junit .Paths ) == 0 {
749
730
// If there are no paths specified, set Paths[0] to include all XML files and all TRX files
750
731
r .TestReport .Junit .Paths = []string {"**/*.xml" , "**/*.trx" }
@@ -756,23 +737,6 @@ func collectTestReports(
756
737
log .WithField ("error" , crErr ).Errorln (fmt .Sprintf ("Failed to upload report. Time taken: %s" , time .Since (reportStart )))
757
738
}
758
739
759
- return tests , crErr
760
- }
761
-
762
- func collectTestReportsAndCg (
763
- ctx context.Context ,
764
- log * logrus.Logger ,
765
- r * api.StartStepRequest ,
766
- start time.Time ,
767
- stepName string ,
768
- tiConfig * tiCfg.Cfg ,
769
- telemetryData * types.TelemetryData ,
770
- envs map [string ]string ,
771
- ) error {
772
- cgStart := time .Now ()
773
-
774
- tests , _ := collectTestReports (ctx , log , r , stepName , tiConfig , telemetryData )
775
-
776
740
testFailed := false
777
741
778
742
if envValue , ok := envs ["DISABLE_CG_UPLOAD_ON_FAILURE_FF" ]; ok {
0 commit comments