aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-06-08 19:38:22 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-06-08 19:38:22 +0800
commitd31eab94fdf959c90512cf3d097dd7e3dcf11115 (patch)
tree44fcd74ed498fc9ed152ad6e1b1ebd3b911c4d72
parent553f08b81954b9ac13ce2f43cad9da5868cb0ce7 (diff)
parent32258af87be39994baca95aa92cb5565ee69571a (diff)
downloadgo-tangerine-d31eab94fdf959c90512cf3d097dd7e3dcf11115.tar
go-tangerine-d31eab94fdf959c90512cf3d097dd7e3dcf11115.tar.gz
go-tangerine-d31eab94fdf959c90512cf3d097dd7e3dcf11115.tar.bz2
go-tangerine-d31eab94fdf959c90512cf3d097dd7e3dcf11115.tar.lz
go-tangerine-d31eab94fdf959c90512cf3d097dd7e3dcf11115.tar.xz
go-tangerine-d31eab94fdf959c90512cf3d097dd7e3dcf11115.tar.zst
go-tangerine-d31eab94fdf959c90512cf3d097dd7e3dcf11115.zip
Merge pull request #2671 from karalabe/randomize-console-tests
cmd/geth: truly randomize console test RPC endpoints
-rw-r--r--cmd/geth/consolecmd_test.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/cmd/geth/consolecmd_test.go b/cmd/geth/consolecmd_test.go
index e59fe1415..e0e549e12 100644
--- a/cmd/geth/consolecmd_test.go
+++ b/cmd/geth/consolecmd_test.go
@@ -17,7 +17,8 @@
package main
import (
- "math/rand"
+ "crypto/rand"
+ "math/big"
"os"
"path/filepath"
"runtime"
@@ -73,7 +74,7 @@ func TestIPCAttachWelcome(t *testing.T) {
coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
var ipc string
if runtime.GOOS == "windows" {
- ipc = `\\.\pipe\geth` + strconv.Itoa(rand.Int())
+ ipc = `\\.\pipe\geth` + strconv.Itoa(trulyRandInt(100000, 999999))
} else {
ws := tmpdir(t)
defer os.RemoveAll(ws)
@@ -94,7 +95,7 @@ func TestIPCAttachWelcome(t *testing.T) {
func TestHTTPAttachWelcome(t *testing.T) {
coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
- port := strconv.Itoa(rand.Intn(65535-1024) + 1024) // Yeah, sometimes this will fail, sorry :P
+ port := strconv.Itoa(trulyRandInt(1024, 65536)) // Yeah, sometimes this will fail, sorry :P
geth := runGeth(t,
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
"--etherbase", coinbase, "--rpc", "--rpcport", port)
@@ -108,7 +109,7 @@ func TestHTTPAttachWelcome(t *testing.T) {
func TestWSAttachWelcome(t *testing.T) {
coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
- port := strconv.Itoa(rand.Intn(65535-1024) + 1024) // Yeah, sometimes this will fail, sorry :P
+ port := strconv.Itoa(trulyRandInt(1024, 65536)) // Yeah, sometimes this will fail, sorry :P
geth := runGeth(t,
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
@@ -160,3 +161,10 @@ at block: 0 ({{niltime}}){{if ipc}}
`)
attach.expectExit()
}
+
+// trulyRandInt generates a crypto random integer used by the console tests to
+// not clash network ports with other tests running cocurrently.
+func trulyRandInt(lo, hi int) int {
+ num, _ := rand.Int(rand.Reader, big.NewInt(int64(hi-lo)))
+ return int(num.Int64()) + lo
+}