@@ -2,7 +2,10 @@ package main
22
33import (
44 "context"
5+ "os"
56 "path/filepath"
7+ "runtime"
8+ "strings"
69 "testing"
710 "time"
811
@@ -95,6 +98,27 @@ func (g *gethrpc) waitSynced() {
9598 }
9699}
97100
101+ // ipcEndpoint resolves an IPC endpoint based on a configured value, taking into
102+ // account the set data folders as well as the designated platform we're currently
103+ // running on.
104+ func ipcEndpoint (ipcPath , datadir string ) string {
105+ // On windows we can only use plain top-level pipes
106+ if runtime .GOOS == "windows" {
107+ if strings .HasPrefix (ipcPath , `\\.\pipe\` ) {
108+ return ipcPath
109+ }
110+ return `\\.\pipe\` + ipcPath
111+ }
112+ // Resolve names into the data directory full paths otherwise
113+ if filepath .Base (ipcPath ) == ipcPath {
114+ if datadir == "" {
115+ return filepath .Join (os .TempDir (), ipcPath )
116+ }
117+ return filepath .Join (datadir , ipcPath )
118+ }
119+ return ipcPath
120+ }
121+
98122func startGethWithIpc (t * testing.T , name string , args ... string ) * gethrpc {
99123 g := & gethrpc {name : name }
100124 args = append ([]string {"--networkid=42" , "--port=0" , "--nousb" }, args ... )
@@ -103,10 +127,10 @@ func startGethWithIpc(t *testing.T, name string, args ...string) *gethrpc {
103127 // wait before we can attach to it. TODO: probe for it properly
104128 time .Sleep (1 * time .Second )
105129 var err error
106- ipcpath := filepath . Join ( g . geth .Datadir , " geth.ipc" )
130+ ipcpath := ipcEndpoint ( " geth.ipc" , g . geth .Datadir )
107131 g .rpc , err = rpc .Dial (ipcpath )
108132 if err != nil {
109- t .Fatalf ("%v rpc connect: %v" , name , err )
133+ t .Fatalf ("%v rpc connect to %v : %v" , name , ipcpath , err )
110134 }
111135 return g
112136}
0 commit comments