MCPcopy Create free account
hub / github.com/encodeous/nylon / TestInProcessRouting

Function TestInProcessRouting

integration/routing_test.go:14–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestInProcessRouting(t *testing.T) {
15 defer goleak.VerifyNone(t)
16 vh := &VirtualHarness{}
17 vh.UntrackedRouting = true
18 a1 := "192.168.1.1:1234"
19 vh.NewNode("a", "10.0.0.1/32")
20 b1 := "192.168.1.2:1234"
21 vh.NewNode("b", "10.0.0.2/32")
22 c1 := "192.168.1.3:1234"
23 vh.NewNode("c", "10.0.0.3/32")
24 vh.Central.Graph = []string{
25 "a, b",
26 "b, c",
27 }
28 vh.Endpoints = map[string]state.NodeId{
29 a1: "a",
30 b1: "b",
31 c1: "c",
32 }
33 vh.AddLink(a1, b1)
34 vh.AddLink(b1, a1)
35 vh.AddLink(b1, c1)
36 vh.AddLink(c1, b1)
37
38 errs := vh.Start()
39
40 vn := vh.Net
41 cc := make(chan bool, 100)
42
43 vn.SelfHandler = func(node state.NodeId, src, dst netip.Addr, data []byte) bool {
44 if node == "c" && src.String() == "10.0.0.1" && dst.String() == "10.0.0.3" && data[0] == 222 {
45 cc <- true
46 }
47 return true
48 }
49
50 go func() {
51 for {
52 select {
53 case <-vh.Context.Done():
54 return
55 case <-time.After(100 * time.Millisecond):
56 vn.Send("a", "10.0.0.1", "10.0.0.3", []byte{222}, 64)
57 }
58 }
59 }()
60
61 select {
62 case <-cc:
63 t.Log("Got ping!")
64 case <-time.After(10 * time.Second):
65 t.Error("Timed out waiting for ping")
66 case err := <-errs:
67 t.Error(err)
68 }
69 vh.Stop()
70}
71

Callers

nothing calls this directly

Calls 8

NewNodeMethod · 0.95
AddLinkMethod · 0.95
StartMethod · 0.95
StopMethod · 0.95
AfterMethod · 0.80
SendMethod · 0.65
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected