Skip to content

Commit

Permalink
Additional Logging for TestPlansAndSuitesMigrationContext at `FindT…
Browse files Browse the repository at this point in the history
…estPlan` (#1771)

Update to add additional logging and check for null reference when test
plan does not match. Usually only happens when test plns have the same
name!

Updates for #1770
  • Loading branch information
MrHinsh authored Dec 5, 2023
1 parent 2c5de98 commit 4e4bd7a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
14 changes: 7 additions & 7 deletions docs/Reference/Generated/MigrationTools.Host.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -624,18 +624,26 @@ private ITestSuiteBase FindSuiteEntry(IStaticTestSuite staticSuite, string title

private ITestPlan FindTestPlan(TestManagementContext tmc, string name)
{
Log.LogDebug("TestPlansAndSuitesMigrationContext::FindTestPlan");
ITestPlan testPlan = (from p in tmc.Project.TestPlans.Query("Select * From TestPlan") where p.Name == name select p).SingleOrDefault();

if (testPlan != null)
{
Log.LogDebug("TestPlansAndSuitesMigrationContext::FindTestPlan:: FOUND Test Plan with {name}", name);
//Check test plan is in fact the right one
var sourceWI = Engine.Source.WorkItems.GetWorkItem(testPlan.Id.ToString());
string expectedReflectedId = Engine.Source.WorkItems.CreateReflectedWorkItemId(sourceWI).ToString();
string workItemReflectedId = (string)sourceWI.Fields[Engine.Target.Config.AsTeamProjectConfig().ReflectedWorkItemIDFieldName].Value;
if (workItemReflectedId != expectedReflectedId)
{
Log.LogDebug("TestPlansAndSuitesMigrationContext::FindTestPlan:: Fouund test plan with name {name} does not match {workItemReflectedId} ", name, workItemReflectedId);
testPlan = null;
}
}
else
{
Log.LogDebug("TestPlansAndSuitesMigrationContext::FindTestPlan:: NOT FOUND Test Plan with {name}", name);
}
return testPlan;
}

Expand Down Expand Up @@ -914,9 +922,17 @@ private void ProcessTestPlan(ITestPlan sourcePlan)
// Load the plan again, because somehow it doesn't let me set configurations on the already loaded plan
InnerLog(sourcePlan, $"ApplyConfigurationsAndAssignTesters {targetPlan.Name}", 5); ;
ITestPlan targetPlan2 = FindTestPlan(_targetTestStore, targetPlan.Name);
ApplyConfigurationsAndAssignTesters(sourcePlan.RootSuite, targetPlan2.RootSuite);
//////////////////////////////
TagCompletedTargetPlan(targetPlan.Id);
if (targetPlan2 != null)
{
ApplyConfigurationsAndAssignTesters(sourcePlan.RootSuite, targetPlan2.RootSuite);
//////////////////////////////
TagCompletedTargetPlan(targetPlan.Id);
}
else
{
Log.LogError("Unable to ApplyConfigurationsAndAssignTesters: When loading the test plan again with the name it was found that they do not match!");
}

///////////////////////////////////////////////
metrics.Add("ElapsedMS", stopwatch.ElapsedMilliseconds);
Telemetry.TrackEvent("MigrateTestPlan", parameters, metrics);
Expand Down

0 comments on commit 4e4bd7a

Please sign in to comment.