cmd/geth: improve les test on windows (#21860)

This commit is contained in:
Martin Holst Swende 2020-11-17 12:01:19 +01:00 committed by GitHub
parent db87223269
commit 6b9858085f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,10 @@ package main
import ( import (
"context" "context"
"os"
"path/filepath" "path/filepath"
"runtime"
"strings"
"testing" "testing"
"time" "time"
@ -95,6 +98,27 @@ func (g *gethrpc) waitSynced() {
} }
} }
// ipcEndpoint resolves an IPC endpoint based on a configured value, taking into
// account the set data folders as well as the designated platform we're currently
// running on.
func ipcEndpoint(ipcPath, datadir string) string {
// On windows we can only use plain top-level pipes
if runtime.GOOS == "windows" {
if strings.HasPrefix(ipcPath, `\\.\pipe\`) {
return ipcPath
}
return `\\.\pipe\` + ipcPath
}
// Resolve names into the data directory full paths otherwise
if filepath.Base(ipcPath) == ipcPath {
if datadir == "" {
return filepath.Join(os.TempDir(), ipcPath)
}
return filepath.Join(datadir, ipcPath)
}
return ipcPath
}
func startGethWithIpc(t *testing.T, name string, args ...string) *gethrpc { func startGethWithIpc(t *testing.T, name string, args ...string) *gethrpc {
g := &gethrpc{name: name} g := &gethrpc{name: name}
args = append([]string{"--networkid=42", "--port=0", "--nousb"}, args...) args = append([]string{"--networkid=42", "--port=0", "--nousb"}, args...)
@ -103,10 +127,10 @@ func startGethWithIpc(t *testing.T, name string, args ...string) *gethrpc {
// wait before we can attach to it. TODO: probe for it properly // wait before we can attach to it. TODO: probe for it properly
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
var err error var err error
ipcpath := filepath.Join(g.geth.Datadir, "geth.ipc") ipcpath := ipcEndpoint("geth.ipc", g.geth.Datadir)
g.rpc, err = rpc.Dial(ipcpath) g.rpc, err = rpc.Dial(ipcpath)
if err != nil { if err != nil {
t.Fatalf("%v rpc connect: %v", name, err) t.Fatalf("%v rpc connect to %v: %v", name, ipcpath, err)
} }
return g return g
} }