File: util_test.go

package info (click to toggle)
golang-github-hashicorp-serf 0.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 1,356 kB
  • sloc: sh: 421; python: 11; makefile: 7
file content (51 lines) | stat: -rw-r--r-- 1,163 bytes parent folder | download | duplicates (2)
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
package agent

import (
	"io"
	"math/rand"
	"net"
	"testing"
	"time"

	"github.com/hashicorp/serf/serf"
	"github.com/hashicorp/serf/testutil"
)

func init() {
	// Seed the random number generator
	rand.Seed(time.Now().UnixNano())
}

func drainEventCh(ch <-chan string) {
	for {
		select {
		case <-ch:
		default:
			return
		}
	}
}

func testAgent(t *testing.T, ip net.IP, logOutput io.Writer) *Agent {
	return testAgentWithConfig(t, ip, DefaultConfig(), serf.DefaultConfig(), logOutput)
}

func testAgentWithConfig(t *testing.T, ip net.IP, agentConfig *Config, serfConfig *serf.Config, logOutput io.Writer) *Agent {
	serfConfig.MemberlistConfig.ProbeInterval = 100 * time.Millisecond
	serfConfig.MemberlistConfig.BindAddr = ip.String()
	serfConfig.NodeName = serfConfig.MemberlistConfig.BindAddr

	// Activate the strictest version of memberlist validation to ensure
	// we properly pass node names through the serf layer.
	serfConfig.MemberlistConfig.RequireNodeNames = true

	if logOutput == nil {
		logOutput = testutil.TestWriter(t)
	}

	agent, err := Create(agentConfig, serfConfig, logOutput)
	if err != nil {
		t.Fatalf("err: %v", err)
	}
	return agent
}