mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 22:26:42 +00:00
rpc: add some IPC socket bind trashing test
This commit is contained in:
parent
b8f4a48ada
commit
d2c710b63b
2 changed files with 55 additions and 0 deletions
|
|
@ -37,6 +37,7 @@ func testNodeConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
PrivateKey: testNodeKey,
|
PrivateKey: testNodeKey,
|
||||||
Name: "test node",
|
Name: "test node",
|
||||||
|
IPCPath: "node.ipc",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
54
rpc/ipc_test.go
Normal file
54
rpc/ipc_test.go
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
// Copyright 2015 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package rpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Tests that continuously binding and closing an IPC socket doesn't fail.
|
||||||
|
func TestIPCBindTrashing(t *testing.T) {
|
||||||
|
// Create an OS dependent IPC path to trash
|
||||||
|
var endpoint = ""
|
||||||
|
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "windows":
|
||||||
|
endpoint = `\\.\pipe\socket.ipc`
|
||||||
|
|
||||||
|
default:
|
||||||
|
path, _ := ioutil.TempDir("", "")
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
endpoint = filepath.Join(path, "socket.ipc")
|
||||||
|
}
|
||||||
|
// Bind and close the socket a number of times
|
||||||
|
for i := 0; i < 100; i++ {
|
||||||
|
listener, err := CreateIPCListener(endpoint)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create IPC socket: %v", err)
|
||||||
|
}
|
||||||
|
conn, err := NewIPCClient(endpoint)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to connect IPC socket: %v", err)
|
||||||
|
}
|
||||||
|
conn.Close()
|
||||||
|
listener.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue