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

Function TestSimpleRoutedPing

integration/basic_test.go:83–143  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

81}
82
83func TestSimpleRoutedPing(t *testing.T) {
84 defer goleak.VerifyNone(t)
85 tunables := state.DefaultRouterTunables()
86 tunables.ProbeDelay /= 3 // 3x faster
87 tunables.RouteUpdateDelay /= 3
88
89 vh := &VirtualHarness{}
90 vh.Tunables = &tunables
91 a1 := "192.168.1.1:1234"
92 vh.NewNode("a", "10.0.0.1/32")
93 b1 := "192.168.1.2:1234"
94 vh.NewNode("b", "10.0.0.2/32")
95 c1 := "192.168.1.3:1234"
96 vh.NewNode("c", "10.0.0.3/32")
97 vh.Central.Graph = []string{
98 "a, b",
99 "b, c",
100 }
101 vh.Endpoints = map[string]state.NodeId{
102 a1: "a",
103 b1: "b",
104 c1: "c",
105 }
106 vh.AddLink(a1, b1)
107 vh.AddLink(b1, a1)
108 vh.AddLink(b1, c1)
109 vh.AddLink(c1, b1)
110
111 errs := vh.Start()
112
113 vn := vh.Net
114 cc := make(chan bool, 100)
115
116 vn.SelfHandler = func(node state.NodeId, src, dst netip.Addr, data []byte) bool {
117 if node == "c" && src.String() == "10.0.0.1" && dst.String() == "10.0.0.3" && data[0] == 222 {
118 cc <- true
119 }
120 return true
121 }
122
123 go func() {
124 for {
125 select {
126 case <-vh.Context.Done():
127 return
128 case <-time.After(100 * time.Millisecond):
129 vn.Send("a", "10.0.0.1", "10.0.0.3", []byte{222}, 64)
130 }
131 }
132 }()
133
134 select {
135 case <-cc:
136 t.Log("Got ping!")
137 case <-time.After(100 * time.Second):
138 t.Error("Timed out waiting for ping")
139 case err := <-errs:
140 t.Error(err)

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected