Skip to content

Commit

Permalink
CR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy committed Jun 22, 2023
1 parent 827570a commit 8c15531
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tools/network/dnssec/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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])
Expand Down

0 comments on commit 8c15531

Please sign in to comment.