From d2c710b63b508338f5aa88d7ba8d2c1eaff55b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Mon, 14 Mar 2016 17:57:48 +0200 Subject: [PATCH] rpc: add some IPC socket bind trashing test --- node/node_test.go | 1 + rpc/ipc_test.go | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 rpc/ipc_test.go diff --git a/node/node_test.go b/node/node_test.go index 532115d3ca..2e1e30feb9 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -37,6 +37,7 @@ func testNodeConfig() *Config { return &Config{ PrivateKey: testNodeKey, Name: "test node", + IPCPath: "node.ipc", } } diff --git a/rpc/ipc_test.go b/rpc/ipc_test.go new file mode 100644 index 0000000000..c3157a9d70 --- /dev/null +++ b/rpc/ipc_test.go @@ -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 . + +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() + } +}