Skip to content

Commit abe5b74

Browse files
avijeetsmbot-harness
authored andcommitted
fix:[CI-18679]: Revert "feat+ci~14385+Enable test splitting even when intelligence mode is off (#365)" (#390)
* 40da78 Revert "feat: [ci-14385]: Enable test splitting even when intelligence mode is off (#365)"
1 parent dfa0cb7 commit abe5b74

File tree

1 file changed

+73
-109
lines changed

1 file changed

+73
-109
lines changed

pipeline/runtime/runtestsV2.go

Lines changed: 73 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,9 @@ func executeRunTestsV2Step(ctx context.Context, f RunFunc, r *api.StartStepReque
106106

107107
exited, err := f(ctx, step, out, r.LogDrone, false)
108108
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
120112
}
121113

122114
if tiConfig.GetParseSavings() {
@@ -199,57 +191,57 @@ func SetupRunTestV2(
199191
tmpFilePath := filepath.Join(tiConfig.GetDataDir(), instrumentation.GetUniqueHash(uniqueStepID, tiConfig))
200192

201193
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+
}
202213

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
227219

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
233225

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)
241243
}
242244
}
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-
253245
return preCmd, nil
254246
}
255247

@@ -258,34 +250,15 @@ func SetupRunTestV2(
258250
func getTestsSelection(ctx context.Context, fs filesystem.FileSystem, stepID, workspace string, log *logrus.Logger,
259251
isManual bool, tiConfig *tiCfg.Cfg, envs map[string]string, runV2Config *api.RunTestsV2Config) (types.SelectTestsResp, bool) {
260252
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
271256
}
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{}
285257
// 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
286258
var files []types.File
287259
var err error
288260
runOnlySelectedTests := true
261+
289262
if instrumentation.IsPushTriggerExecution(tiConfig) {
290263
lastSuccessfulCommitID, commitErr := instrumentation.GetCommitInfo(ctx, stepID, tiConfig)
291264
if commitErr != nil {
@@ -311,8 +284,8 @@ func getTestsSelectionWithTiModeEnabled(ctx context.Context, fs filesystem.FileS
311284
return selection, false // TI selected all the tests to be run
312285
}
313286
}
314-
315287
filesWithpkg := java.ReadPkgs(log, fs, workspace, files)
288+
testGlobs := sanitizeTestGlobsV2(runV2Config.TestGlobs)
316289
selection, err = instrumentation.SelectTests(ctx, workspace, filesWithpkg, runOnlySelectedTests, stepID, testGlobs, fs, tiConfig)
317290
if err != nil {
318291
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
324297
log.Infoln(fmt.Sprintf("Running tests selected by Test Intelligence: %s", selection.Tests))
325298
runOnlySelectedTests = true
326299
}
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+
327306
return selection, runOnlySelectedTests
328307
}
329308

@@ -664,15 +643,13 @@ func createSelectedTestFile(ctx context.Context, fs filesystem.FileSystem, stepI
664643
tiConfig *tiCfg.Cfg, tmpFilepath string, envs map[string]string, runV2Config *api.RunTestsV2Config, filterFilePath string, testMetadata *types.TestIntelligenceMetaData) error {
665644
isManualExecution := instrumentation.IsManualExecution(tiConfig)
666645
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)
676653
}
677654
}
678655

@@ -737,14 +714,18 @@ func writetoBazelrcFile(log *logrus.Logger, fs filesystem.FileSystem) error {
737714
return nil
738715
}
739716

740-
func collectTestReports(
717+
func collectTestReportsAndCg(
741718
ctx context.Context,
742719
log *logrus.Logger,
743720
r *api.StartStepRequest,
721+
start time.Time,
744722
stepName string,
745723
tiConfig *tiCfg.Cfg,
746724
telemetryData *types.TelemetryData,
747-
) ([]*types.TestCase, error) {
725+
envs map[string]string,
726+
) error {
727+
cgStart := time.Now()
728+
748729
if len(r.TestReport.Junit.Paths) == 0 {
749730
// If there are no paths specified, set Paths[0] to include all XML files and all TRX files
750731
r.TestReport.Junit.Paths = []string{"**/*.xml", "**/*.trx"}
@@ -756,23 +737,6 @@ func collectTestReports(
756737
log.WithField("error", crErr).Errorln(fmt.Sprintf("Failed to upload report. Time taken: %s", time.Since(reportStart)))
757738
}
758739

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-
776740
testFailed := false
777741

778742
if envValue, ok := envs["DISABLE_CG_UPLOAD_ON_FAILURE_FF"]; ok {

0 commit comments

Comments
 (0)