/
router.go
63 lines (51 loc) · 1.51 KB
/
router.go
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
61
62
63
package testservers
import (
"fmt"
"os"
"os/exec"
envstruct "code.cloudfoundry.org/go-envstruct"
"code.cloudfoundry.org/loggregator-release/src/router/app"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)
func BuildRouterConfig(agentUDPPort, agentGRPCPort int) app.Config {
return app.Config{
GRPC: app.GRPC{
CertFile: LoggregatorTestCerts.Cert("doppler"),
KeyFile: LoggregatorTestCerts.Key("doppler"),
CAFile: LoggregatorTestCerts.CA(),
},
Agent: app.Agent{
GRPCAddress: fmt.Sprintf("127.0.0.1:%d", agentGRPCPort),
},
IngressBufferSize: 10000,
EgressBufferSize: 1000,
MetricBatchIntervalMilliseconds: 10,
}
}
type RouterPorts struct {
GRPC int
PProf int
}
func StartRouter(conf app.Config) (cleanup func(), rp RouterPorts) {
By("making sure router was built")
routerPath := os.Getenv("ROUTER_BUILD_PATH")
Expect(routerPath).ToNot(BeEmpty())
By("starting router")
routerCommand := exec.Command(routerPath)
routerCommand.Env = envstruct.ToEnv(&conf)
routerSession, err := gexec.Start(
routerCommand,
gexec.NewPrefixedWriter(color("o", "router", green, blue), GinkgoWriter),
gexec.NewPrefixedWriter(color("e", "router", red, blue), GinkgoWriter),
)
Expect(err).ToNot(HaveOccurred())
By("waiting for router to listen")
rp.GRPC = waitForPortBinding("grpc", routerSession.Err)
rp.PProf = waitForPortBinding("pprof", routerSession.Err)
cleanup = func() {
routerSession.Kill().Wait()
}
return cleanup, rp
}