make setup deterministic: complete dependency order with alphabetical one when 2 module elements are at same position

This commit is contained in:
odain
2025-03-31 08:17:00 +02:00
parent 21c4ffa9e3
commit 9f2da19da0
3 changed files with 65 additions and 16 deletions

View File

@@ -478,7 +478,7 @@ class ModuleDiscovery
}
//include all modules
$iInDegreeCounterIncludingOutsideModules = count($oModule->GetUnresolvedDependencyModuleNames());
$aCountDepsByModuleId[$sModuleId] = [$iInDegreeCounter, $iInDegreeCounterIncludingOutsideModules];
$aCountDepsByModuleId[$sModuleId] = [$iInDegreeCounter, $iInDegreeCounterIncludingOutsideModules, $sModuleId];
}
$aRes=[];
@@ -493,7 +493,13 @@ class ModuleDiscovery
}
//compare $iInDegreeCounterIncludingOutsideModules
return $aDeps1[1] - $aDeps2[1];
$res = $aDeps1[1] - $aDeps2[1];
if ($res != 0){
return $res;
}
//alphabetical order at least
return strcmp($aDeps1[2], $aDeps2[2]);
});
$bOneLoopAtLeast=false;
@@ -518,7 +524,7 @@ class ModuleDiscovery
$aDepCount = $aCountDepsByModuleId[$sModuleId2];
$iInDegreeCounter = $aDepCount[0] - 1;
$iInDegreeCounterIncludingOutsideModules = $aDepCount[1];
$aCountDepsByModuleId[$sModuleId2] = [$iInDegreeCounter, $iInDegreeCounterIncludingOutsideModules];
$aCountDepsByModuleId[$sModuleId2] = [$iInDegreeCounter, $iInDegreeCounterIncludingOutsideModules, $sModuleId2];
}
unset($aDependsOnModuleName[$oModule->GetModuleName()]);

View File

@@ -134,6 +134,10 @@ MSG;
public function testOrderModulesByDependencies_ResolveOk()
{
$aModules=[
"id0/1" => [
'dependencies' => [ 'id2/2 || id1/1'],
'label' => 'label1',
],
"id1/1" => [
'dependencies' => [ 'id2/2'],
'label' => 'label1',
@@ -159,6 +163,45 @@ MSG;
"id3/3",
"id2/2",
"id1/1",
"id0/1",
];
$this->assertEquals($aExpected, array_keys($aResult));
$this->assertEquals(1, $iLoopCount);
}
public function testOrderModulesByDependencies_ResolveNoDependendenciesOrderByAlphabeticalOrder()
{
$aModules=[
"id2/2" => [
'dependencies' => [],
'label' => 'label2',
],
"id1/1" => [
'dependencies' => [ ],
'label' => 'label1',
],
"id3/3" => [
'dependencies' => [],
'label' => 'label3',
],
"id4/4" => [
'dependencies' => [],
'label' => 'label4',
],
"id0/1" => [
'dependencies' => [],
'label' => 'label0',
],
];
$iLoopCount=0;
$aResult = ModuleDiscovery::OrderModulesByDependencies($aModules, true, null, $iLoopCount);
$aExpected = [
"id0/1",
"id1/1",
"id2/2",
"id3/3",
"id4/4",
];
$this->assertEquals($aExpected, array_keys($aResult));
$this->assertEquals(1, $iLoopCount);
@@ -211,7 +254,7 @@ MSG;
public function testSortModulesByCountOfDepencenciesDescending_NoDependencies(){
$aUnresolvedDependencyModules = [];
foreach (['a', 'b', 'c'] as $sModuleId){
foreach (['c', 'b', 'a'] as $sModuleId){
$this->AddModule($aUnresolvedDependencyModules, $sModuleId, []);
}
ModuleDiscovery::SortModulesByCountOfDepencenciesDescending($aUnresolvedDependencyModules);
@@ -229,8 +272,8 @@ MSG;
$this->assertEquals(
[
'itop-structure/2.7.1',
'itop-tickets/2.0.0',
'itop-config-mgmt/123',
'itop-tickets/2.0.0',
'itop-change-mgmt/456',
], array_keys($aUnresolvedDependencyModules));
}
@@ -244,8 +287,8 @@ MSG;
ModuleDiscovery::SortModulesByCountOfDepencenciesDescending($aUnresolvedDependencyModules);
$this->assertEquals(
[
'itop-tickets/2.0.0',
'itop-config-mgmt/123',
'itop-tickets/2.0.0',
'itop-change-mgmt/456',
],
array_keys($aUnresolvedDependencyModules));
@@ -263,8 +306,8 @@ MSG;
[
'moduleA/1',
'moduleC/1',
'moduleB/1',
'moduleA/2',
'moduleB/1',
],
array_keys($aUnresolvedDependencyModules));
}

View File

@@ -16,32 +16,32 @@
"itop-sla-computation\/3.2.1",
"itop-structure\/3.2.1",
"itop-welcome-itil\/3.2.1",
"itop-portal\/3.2.1",
"combodo-db-tools\/3.2.1",
"itop-config-mgmt\/3.2.1",
"itop-themes-compat\/3.2.1",
"itop-tickets\/3.2.1",
"itop-oauth-client\/3.2.1",
"itop-datacenter-mgmt\/3.2.1",
"itop-endusers-devices\/3.2.1",
"itop-hub-connector\/3.2.1",
"itop-knownerror-mgmt\/3.2.1",
"itop-oauth-client\/3.2.1",
"itop-portal\/3.2.1",
"itop-storage-mgmt\/3.2.1",
"itop-virtualization-mgmt\/3.2.1",
"itop-themes-compat\/3.2.1",
"itop-tickets\/3.2.1",
"itop-problem-mgmt\/3.2.1",
"itop-request-mgmt-itil\/3.2.1",
"itop-request-mgmt\/3.2.1",
"itop-service-mgmt-provider\/3.2.1",
"itop-service-mgmt\/3.2.1",
"itop-faq-light\/3.2.1",
"itop-core-update\/3.2.1",
"itop-virtualization-mgmt\/3.2.1",
"itop-bridge-cmdb-ticket\/3.2.1",
"itop-bridge-virtualization-storage\/3.2.1",
"itop-change-mgmt-itil\/3.2.1",
"itop-change-mgmt\/3.2.1",
"itop-bridge-virtualization-storage\/3.2.1",
"itop-core-update\/3.2.1",
"itop-faq-light\/3.2.1",
"itop-bridge-cmdb-services\/3.2.1",
"itop-incident-mgmt-itil\/3.2.1",
"itop-full-itil\/3.2.1",
"itop-bridge-cmdb-services\/3.2.1",
"itop-bridge-datacenter-mgmt-services\/3.2.1",
"itop-bridge-endusers-devices-services\/3.2.1",
"itop-bridge-storage-mgmt-services\/3.2.1",