cmd/geth: make tests run quicker + use less memory and disk (#21919)
This commit is contained in:
committed by
GitHub
parent
566cb4c5f0
commit
aba0c234c2
@ -35,16 +35,25 @@ const (
|
||||
httpAPIs = "eth:1.0 net:1.0 rpc:1.0 web3:1.0"
|
||||
)
|
||||
|
||||
// spawns geth with the given command line args, using a set of flags to minimise
|
||||
// memory and disk IO. If the args don't set --datadir, the
|
||||
// child g gets a temporary data directory.
|
||||
func runMinimalGeth(t *testing.T, args ...string) *testgeth {
|
||||
// --ropsten to make the 'writing genesis to disk' faster (no accounts)
|
||||
// --networkid=1337 to avoid cache bump
|
||||
// --syncmode=full to avoid allocating fast sync bloom
|
||||
allArgs := []string{"--ropsten", "--nousb", "--networkid", "1337", "--syncmode=full", "--port", "0",
|
||||
"--nat", "none", "--nodiscover", "--maxpeers", "0", "--cache", "64"}
|
||||
return runGeth(t, append(allArgs, args...)...)
|
||||
}
|
||||
|
||||
// Tests that a node embedded within a console can be started up properly and
|
||||
// then terminated by closing the input stream.
|
||||
func TestConsoleWelcome(t *testing.T) {
|
||||
coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
|
||||
|
||||
// Start a geth console, make sure it's cleaned up and terminate the console
|
||||
geth := runGeth(t,
|
||||
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
|
||||
"--etherbase", coinbase,
|
||||
"console")
|
||||
geth := runMinimalGeth(t, "--etherbase", coinbase, "console")
|
||||
|
||||
// Gather all the infos the welcome message needs to contain
|
||||
geth.SetTemplateFunc("goos", func() string { return runtime.GOOS })
|
||||
@ -73,10 +82,13 @@ To exit, press ctrl-d
|
||||
}
|
||||
|
||||
// Tests that a console can be attached to a running node via various means.
|
||||
func TestIPCAttachWelcome(t *testing.T) {
|
||||
func TestAttachWelcome(t *testing.T) {
|
||||
var (
|
||||
ipc string
|
||||
httpPort string
|
||||
wsPort string
|
||||
)
|
||||
// Configure the instance for IPC attachment
|
||||
coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
|
||||
var ipc string
|
||||
if runtime.GOOS == "windows" {
|
||||
ipc = `\\.\pipe\geth` + strconv.Itoa(trulyRandInt(100000, 999999))
|
||||
} else {
|
||||
@ -84,51 +96,28 @@ func TestIPCAttachWelcome(t *testing.T) {
|
||||
defer os.RemoveAll(ws)
|
||||
ipc = filepath.Join(ws, "geth.ipc")
|
||||
}
|
||||
geth := runGeth(t,
|
||||
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
|
||||
"--etherbase", coinbase, "--ipcpath", ipc)
|
||||
|
||||
defer func() {
|
||||
geth.Interrupt()
|
||||
geth.ExpectExit()
|
||||
}()
|
||||
|
||||
waitForEndpoint(t, ipc, 3*time.Second)
|
||||
testAttachWelcome(t, geth, "ipc:"+ipc, ipcAPIs)
|
||||
|
||||
}
|
||||
|
||||
func TestHTTPAttachWelcome(t *testing.T) {
|
||||
coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
|
||||
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, "--http", "--http.port", port)
|
||||
defer func() {
|
||||
geth.Interrupt()
|
||||
geth.ExpectExit()
|
||||
}()
|
||||
|
||||
endpoint := "http://127.0.0.1:" + port
|
||||
waitForEndpoint(t, endpoint, 3*time.Second)
|
||||
testAttachWelcome(t, geth, endpoint, httpAPIs)
|
||||
}
|
||||
|
||||
func TestWSAttachWelcome(t *testing.T) {
|
||||
coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
|
||||
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, "--ws", "--ws.port", port)
|
||||
defer func() {
|
||||
geth.Interrupt()
|
||||
geth.ExpectExit()
|
||||
}()
|
||||
|
||||
endpoint := "ws://127.0.0.1:" + port
|
||||
waitForEndpoint(t, endpoint, 3*time.Second)
|
||||
testAttachWelcome(t, geth, endpoint, httpAPIs)
|
||||
// And HTTP + WS attachment
|
||||
p := trulyRandInt(1024, 65533) // Yeah, sometimes this will fail, sorry :P
|
||||
httpPort = strconv.Itoa(p)
|
||||
wsPort = strconv.Itoa(p + 1)
|
||||
geth := runMinimalGeth(t, "--etherbase", "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182",
|
||||
"--ipcpath", ipc,
|
||||
"--http", "--http.port", httpPort,
|
||||
"--ws", "--ws.port", wsPort)
|
||||
t.Run("ipc", func(t *testing.T) {
|
||||
waitForEndpoint(t, ipc, 3*time.Second)
|
||||
testAttachWelcome(t, geth, "ipc:"+ipc, ipcAPIs)
|
||||
})
|
||||
t.Run("http", func(t *testing.T) {
|
||||
endpoint := "http://127.0.0.1:" + httpPort
|
||||
waitForEndpoint(t, endpoint, 3*time.Second)
|
||||
testAttachWelcome(t, geth, endpoint, httpAPIs)
|
||||
})
|
||||
t.Run("ws", func(t *testing.T) {
|
||||
endpoint := "ws://127.0.0.1:" + wsPort
|
||||
waitForEndpoint(t, endpoint, 3*time.Second)
|
||||
testAttachWelcome(t, geth, endpoint, httpAPIs)
|
||||
})
|
||||
}
|
||||
|
||||
func testAttachWelcome(t *testing.T, geth *testgeth, endpoint, apis string) {
|
||||
|
Reference in New Issue
Block a user