/usr/share/gocode/src/github.com/hashicorp/serf/command/agent/util_test.go is in golang-github-hashicorp-serf-dev 0.7.0~ds1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | package agent
import (
"fmt"
"github.com/hashicorp/serf/serf"
"github.com/hashicorp/serf/testutil"
"io"
"math/rand"
"net"
"os"
"time"
)
func init() {
// Seed the random number generator
rand.Seed(time.Now().UnixNano())
}
func drainEventCh(ch <-chan string) {
for {
select {
case <-ch:
default:
return
}
}
}
func getRPCAddr() string {
for i := 0; i < 500; i++ {
l, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", rand.Int31n(25000)+1024))
if err == nil {
l.Close()
return l.Addr().String()
}
}
panic("no listener")
}
func testAgent(logOutput io.Writer) *Agent {
return testAgentWithConfig(DefaultConfig(), serf.DefaultConfig(), logOutput)
}
func testAgentWithConfig(agentConfig *Config, serfConfig *serf.Config,
logOutput io.Writer) *Agent {
if logOutput == nil {
logOutput = os.Stderr
}
serfConfig.MemberlistConfig.ProbeInterval = 100 * time.Millisecond
serfConfig.MemberlistConfig.BindAddr = testutil.GetBindAddr().String()
serfConfig.NodeName = serfConfig.MemberlistConfig.BindAddr
agent, err := Create(agentConfig, serfConfig, logOutput)
if err != nil {
panic(err)
}
return agent
}
|