nkdAgility / azure-devops-migration-tools

Azure DevOps Migration Tools allow you to migrate Teams, Backlogs, Tasks, Test Cases, and Plans & Suits from one Project to another in Azure DevOps / TFS both within the same Organisation, and between Organisations.
https://nkdagility.com/learn/azure-devops-migration-tools/
MIT License
493 stars 328 forks source link

[Bug]: Null pointer exception during migration of test plans #1681

Closed frankroghair closed 10 months ago

frankroghair commented 11 months ago

Version

Source Version

Azure DevOps Server 2020

Target Version

Azure DevOps Server 2020

Relevant configuration

"$type": "TestPlansAndSuitesMigrationConfig",
"Enabled": true,
"PrefixProjectToNodes": false,
"UseCommonNodeStructureEnricherConfig": false,
"RemoveInvalidTestSuiteLinks": true,
"RemoveAllLinks": true

Relevant log output

System.NullReferenceException: Object reference not set to an instance of an object.
   at VstsSyncMigrator.Engine.TestPlansAndSuitesMigrationContext.ProcessTestPlan(ITestPlan sourcePlan) in D:\DEV\git\azure-devops-migration-tools\src\VstsSyncMigrator.Core\Execution\MigrationContext\TestPlansAndSuitesMigrationContext.cs:line 935
   at VstsSyncMigrator.Engine.TestPlansAndSuitesMigrationContext.InternalExecute() in D:\DEV\git\azure-devops-migration-tools\src\VstsSyncMigrator.Core\Execution\MigrationContext\TestPlansAndSuitesMigrationContext.cs:line 138
   at MigrationTools._EngineV1.Processors.MigrationProcessorBase.Execute() in D:\DEV\git\azure-devops-migration-tools\src\MigrationTools\_EngineV1\Processors\MigrationProcessorBase.cs:line 46
2023-10-12 10:18:41.837 +02:00 [ERR] TestPlansAndSuitesMigrationContext The Processor MigrationEngine entered the failed state...stopping run

What happened?

I guess the issue is related to commit https://github.com/nkdAgility/azure-devops-migration-tools/commit/119e5cb4d00030678953e31449c4542a20ba4c2f

Maybe i miss something:
In the existing code the same work item is used to determine the expected and the actual reflected id. According to my understanding the condition "if (workItemReflectedId != expectedReflectedId)" in the original code will always be true. Which does results later in the program to a null pointer exception.

I have changed the code to the following:

private ITestPlan FindTestPlan(TestManagementContext tmc, string name, ITestPlan sourcePlan)
        {
            ITestPlan testPlan = (from p in tmc.Project.TestPlans.Query("Select * From TestPlan") where p.Name == name select p).SingleOrDefault();
            if (testPlan != null)
            {
                //Check test plan is in fact the right one
                var targetWI = Engine.Source.WorkItems.GetWorkItem(testPlan.Id.ToString());
                var sourceWI = Engine.Source.WorkItems.GetWorkItem(sourcePlan.Id.ToString());
                string expectedReflectedId = Engine.Source.WorkItems.CreateReflectedWorkItemId(sourceWI).ToString();
                string workItemReflectedId = (string)targetWI.Fields[Engine.Target.Config.AsTeamProjectConfig().ReflectedWorkItemIDFieldName].Value;
                if (workItemReflectedId != expectedReflectedId)
                {
                    testPlan = null;
                }
            }
            return testPlan;
        }

Debug in Visual Studio

MrHinsh commented 11 months ago

Its difficult to see what you have changed, can you provide a Pull Request?

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request