diff options
author | Alexey Sharov <www.pismeco@gmail.com> | 2018-11-14 16:21:14 +0800 |
---|---|---|
committer | Viktor Trón <viktor.tron@gmail.com> | 2018-11-14 16:21:14 +0800 |
commit | eb8fa3cc89ae3a3247c649486839b1c250554d2d (patch) | |
tree | c61b8ebebc739db0e5413cd214fdd0d3da2fe61e /swarm/network_test.go | |
parent | cff97119a713a6f790893aaf1c172a397a48bf33 (diff) | |
download | go-tangerine-eb8fa3cc89ae3a3247c649486839b1c250554d2d.tar go-tangerine-eb8fa3cc89ae3a3247c649486839b1c250554d2d.tar.gz go-tangerine-eb8fa3cc89ae3a3247c649486839b1c250554d2d.tar.bz2 go-tangerine-eb8fa3cc89ae3a3247c649486839b1c250554d2d.tar.lz go-tangerine-eb8fa3cc89ae3a3247c649486839b1c250554d2d.tar.xz go-tangerine-eb8fa3cc89ae3a3247c649486839b1c250554d2d.tar.zst go-tangerine-eb8fa3cc89ae3a3247c649486839b1c250554d2d.zip |
cmd/swarm, swarm/api/http, swarm/bmt, swarm/fuse, swarm/network/stream, swarm/storage, swarm/storage/encryption, swarm/testutil: use pseudo-random instead of crypto-random for test files content generation (#18083)
- Replace "crypto/rand" to "math/rand" for files content generation
- Remove swarm/network_test.go.Shuffle and swarm/btm/btm_test.go.Shuffle - because go1.9 support dropped (see https://github.com/ethereum/go-ethereum/pull/17807 and comments to swarm/network_test.go.Shuffle)
Diffstat (limited to 'swarm/network_test.go')
-rw-r--r-- | swarm/network_test.go | 33 |
1 files changed, 2 insertions, 31 deletions
diff --git a/swarm/network_test.go b/swarm/network_test.go index aab1c0509..d84f28147 100644 --- a/swarm/network_test.go +++ b/swarm/network_test.go @@ -335,7 +335,7 @@ func testSwarmNetwork(t *testing.T, o *testSwarmNetworkOptions, steps ...testSwa result := sim.Run(ctx, func(ctx context.Context, sim *simulation.Simulation) error { nodeIDs := sim.UpNodeIDs() - shuffle(len(nodeIDs), func(i, j int) { + rand.Shuffle(len(nodeIDs), func(i, j int) { nodeIDs[i], nodeIDs[j] = nodeIDs[j], nodeIDs[i] }) for _, id := range nodeIDs { @@ -404,7 +404,7 @@ func retrieve( nodeStatusM *sync.Map, totalFoundCount *uint64, ) (missing uint64) { - shuffle(len(files), func(i, j int) { + rand.Shuffle(len(files), func(i, j int) { files[i], files[j] = files[j], files[i] }) @@ -499,32 +499,3 @@ func retrieve( return uint64(totalCheckCount) - atomic.LoadUint64(totalFoundCount) } - -// Backported from stdlib https://golang.org/src/math/rand/rand.go?s=11175:11215#L333 -// -// Replace with rand.Shuffle from go 1.10 when go 1.9 support is dropped. -// -// shuffle pseudo-randomizes the order of elements. -// n is the number of elements. Shuffle panics if n < 0. -// swap swaps the elements with indexes i and j. -func shuffle(n int, swap func(i, j int)) { - if n < 0 { - panic("invalid argument to Shuffle") - } - - // Fisher-Yates shuffle: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle - // Shuffle really ought not be called with n that doesn't fit in 32 bits. - // Not only will it take a very long time, but with 2³¹! possible permutations, - // there's no way that any PRNG can have a big enough internal state to - // generate even a minuscule percentage of the possible permutations. - // Nevertheless, the right API signature accepts an int n, so handle it as best we can. - i := n - 1 - for ; i > 1<<31-1-1; i-- { - j := int(rand.Int63n(int64(i + 1))) - swap(i, j) - } - for ; i > 0; i-- { - j := int(rand.Int31n(int32(i + 1))) - swap(i, j) - } -} |