From 8c155318314b42e6eb40b24906644cc10534c6b2 Mon Sep 17 00:00:00 2001 From: Pavel Zbitskiy Date: Thu, 22 Jun 2023 11:46:26 -0400 Subject: [PATCH] CR fixes --- tools/network/dnssec/sort_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/network/dnssec/sort_test.go b/tools/network/dnssec/sort_test.go index e60cf9e95c..ebdec99c56 100644 --- a/tools/network/dnssec/sort_test.go +++ b/tools/network/dnssec/sort_test.go @@ -32,7 +32,7 @@ func TestSrvSort(t *testing.T) { arr := make([]*net.SRV, 0, 7) arr = append(arr, &net.SRV{Priority: 4, Weight: 1}) arr = append(arr, &net.SRV{Priority: 3, Weight: 1}) - arr = append(arr, &net.SRV{Priority: 1, Weight: 200}) + arr = append(arr, &net.SRV{Priority: 1, Weight: 0xFFFF}) // max possible value to increase the ordering probability arr = append(arr, &net.SRV{Priority: 1, Weight: 1}) arr = append(arr, &net.SRV{Priority: 1, Weight: 1}) arr = append(arr, &net.SRV{Priority: 1, Weight: 1}) @@ -41,17 +41,17 @@ func TestSrvSort(t *testing.T) { retryCounter := 0 retry: srvRecArray(arr).sortAndRand() - if (*arr[0] != net.SRV{Priority: 1, Weight: 200}) { - // there is a small change that random number from 0 to 204 would 0 or 1 - // so the first element would be with weight of 1 and not 200 - // if this happens, we will try again - if retryCounter > 3 { - a.Fail("randomization failed") + if (*arr[0] != net.SRV{Priority: 1, Weight: 0xFFFF}) { + // there is a small change that a random number from 0 to max uint15 would be 0 or 1 + // in this case the first element of the resulting sequence would be with weight of 1 and not the highest possible. + // if this happens, we will try again since it is expected time to time. + if retryCounter > 1 { + a.Fail("The first element of the resulting sequence should be with the highest possible weight at least in one of 3 attempts") } retryCounter++ goto retry } - a.Equal(net.SRV{Priority: 1, Weight: 200}, *arr[0]) + a.Equal(net.SRV{Priority: 1, Weight: 0xFFFF}, *arr[0]) a.Equal(net.SRV{Priority: 1, Weight: 1}, *arr[1]) a.Equal(net.SRV{Priority: 1, Weight: 1}, *arr[2]) a.Equal(net.SRV{Priority: 1, Weight: 1}, *arr[3])