File: set_up_server.go

package info (click to toggle)
golang-github-onsi-ginkgo-v2 2.15.0-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 4,112 kB
  • sloc: javascript: 59; sh: 14; makefile: 7
file content (35 lines) | stat: -rw-r--r-- 903 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
package test_helpers

import (
	. "github.com/onsi/ginkgo/v2"
	"github.com/onsi/ginkgo/v2/internal/parallel_support"
	"github.com/onsi/ginkgo/v2/reporters"
	. "github.com/onsi/gomega"
)

func SetUpServerAndClient(numNodes int) (parallel_support.Server, parallel_support.Client, map[int]chan interface{}) {
	server, err := parallel_support.NewServer(numNodes, reporters.NoopReporter{})
	Ω(err).ShouldNot(HaveOccurred())
	server.Start()
	client := parallel_support.NewClient(server.Address())
	Eventually(client.Connect).Should(BeTrue())

	exitChannels := map[int]chan interface{}{}
	for node := 1; node <= numNodes; node++ {
		c := make(chan interface{})
		exitChannels[node] = c
		server.RegisterAlive(node, func() bool {
			select {
			case <-c:
				return false
			default:
				return true
			}
		})
	}

	DeferCleanup(server.Close)
	DeferCleanup(client.Close)

	return server, client, exitChannels
}