From 96c059d1a0f7f632ae87f448990852a1dbaf670a Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 8 Jun 2022 15:52:38 +0200 Subject: [PATCH] TT#139455 instances-info: Make output reproducible We need to specify what to sort on, otherwise we are sorting based on the references and not the actual keys. Add specific code blocks to sort on the hash keys we are interested in. This makes the output reproducible which makes the tests always pass, instead of randomly failing depending on the ordering used randomly by perl. Fixes: commit 83003649e3a5b3bde2ddebaf9db7f1b9b72da9ea Change-Id: I3dfc031a6c76db5153b7d05f6058e88d4b101599 (cherry picked from commit e48864fc337a5b690ab7bb6ab74e53f6686b7bdc) --- helper/instances-info | 6 +++--- t/fixtures/output/instances_info_args | 6 +++--- t/fixtures/output/instances_info_args_longer | 2 +- t/fixtures/output/instances_info_args_same | 2 +- t/fixtures/output/instances_info_noargs | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/helper/instances-info b/helper/instances-info index 3e082d32..a5bf88e5 100755 --- a/helper/instances-info +++ b/helper/instances-info @@ -92,7 +92,7 @@ sub show_match { $path = $bpath; } - foreach my $info (sort @{$dirs->{$path}}) { + foreach my $info (sort { $a->{name} cmp $b->{name} } @{$dirs->{$path}}) { my $dest; if(defined $spath && defined $suffix) { $dest = $info->{dest}."/${suffix}"; @@ -106,11 +106,11 @@ sub show_match { sub prepare_info { return 0 unless defined $yaml->{instances}; - foreach my $instance ( sort @{ $yaml->{instances} } ) { + foreach my $instance (sort { $a->{name} cmp $b->{name} } @{$yaml->{instances}}) { $instances->{ $instance->{label} } //= (); push @{ $instances->{ $instance->{label} } }, $instance->{name}; } - foreach my $def ( sort @{ $templ->{sources} } ) { + foreach my $def (sort { $a->{orig} cmp $b->{orig} } @{$templ->{sources}}) { my $inst = $instances->{ $def->{label} }; next unless $inst; my $orig = prefix_root $def->{orig}; diff --git a/t/fixtures/output/instances_info_args b/t/fixtures/output/instances_info_args index 1b98f2ec..de0b9c42 100644 --- a/t/fixtures/output/instances_info_args +++ b/t/fixtures/output/instances_info_args @@ -1,6 +1,6 @@ -/etc/kamailio/lb:/etc/kamailio/lb_B:B /etc/kamailio/lb:/etc/kamailio/lb_A:A -/etc/momo:/etc/momo_B:B +/etc/kamailio/lb:/etc/kamailio/lb_B:B /etc/momo:/etc/momo_A:A -/etc/other/lb:/etc/other/lb_B:B +/etc/momo:/etc/momo_B:B /etc/other/lb:/etc/other/lb_A:A +/etc/other/lb:/etc/other/lb_B:B diff --git a/t/fixtures/output/instances_info_args_longer b/t/fixtures/output/instances_info_args_longer index b9a5c45c..66656faa 100644 --- a/t/fixtures/output/instances_info_args_longer +++ b/t/fixtures/output/instances_info_args_longer @@ -1,2 +1,2 @@ -/etc/kamailio/lb/db:/etc/kamailio/lb_B/db:B /etc/kamailio/lb/db:/etc/kamailio/lb_A/db:A +/etc/kamailio/lb/db:/etc/kamailio/lb_B/db:B diff --git a/t/fixtures/output/instances_info_args_same b/t/fixtures/output/instances_info_args_same index 87919098..9e43a1c1 100644 --- a/t/fixtures/output/instances_info_args_same +++ b/t/fixtures/output/instances_info_args_same @@ -1,2 +1,2 @@ -/etc/kamailio/lb:/etc/kamailio/lb_B:B /etc/kamailio/lb:/etc/kamailio/lb_A:A +/etc/kamailio/lb:/etc/kamailio/lb_B:B diff --git a/t/fixtures/output/instances_info_noargs b/t/fixtures/output/instances_info_noargs index 1b98f2ec..de0b9c42 100644 --- a/t/fixtures/output/instances_info_noargs +++ b/t/fixtures/output/instances_info_noargs @@ -1,6 +1,6 @@ -/etc/kamailio/lb:/etc/kamailio/lb_B:B /etc/kamailio/lb:/etc/kamailio/lb_A:A -/etc/momo:/etc/momo_B:B +/etc/kamailio/lb:/etc/kamailio/lb_B:B /etc/momo:/etc/momo_A:A -/etc/other/lb:/etc/other/lb_B:B +/etc/momo:/etc/momo_B:B /etc/other/lb:/etc/other/lb_A:A +/etc/other/lb:/etc/other/lb_B:B