Skip to content

Commit

Permalink
This is fixing a problem in 'TestForEachRight' that appears because i…
Browse files Browse the repository at this point in the history
…t incorrectly relies on the underlying implementation of Map in Golang

The ordering is not guaranteed, but rather the slice output format is randomized strictly to disallow reliying on it. This happens at least for all Goversions >=1.7.

Check that numbers are in the output without asserting the order.

This is also the reason why unit tests on master fail every now and then, and made worse by running tests on 1.8 and 1.9!

Provoke the problem by running the test quite repeatadly until it fails:

'(set -e && for i in {1..100}; do go test; done)'
  • Loading branch information
HaraldNordgren committed Oct 8, 2017
1 parent 77849ed commit 1577793
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ func TestForEachRight(t *testing.T) {

ForEachRight(mapping, func(k int, v string) {
is.Equal(v, mapping[k])

mapKeys = append(mapKeys, k)
})

is.Equal(mapKeys, []int{2, 1})
is.Equal(len(mapKeys), 2)
is.Contains(mapKeys, 1)
is.Contains(mapKeys, 2)
}

func TestHead(t *testing.T) {
Expand Down

0 comments on commit 1577793

Please sign in to comment.