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

Function TestSimplePing

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

Source from the content-addressed store, hash-verified

30}
31
32func TestSimplePing(t *testing.T) {
33 defer goleak.VerifyNone(t)
34 vh := &VirtualHarness{}
35 a1 := "192.168.1.1:1234"
36 vh.NewNode("a", "10.0.0.1/32")
37 b1 := "192.168.1.2:1234"
38 vh.NewNode("b", "10.0.0.2/32")
39 vh.Central.Graph = []string{
40 "a, b",
41 }
42 vh.Endpoints = map[string]state.NodeId{
43 a1: "a",
44 b1: "b",
45 }
46 vh.AddLink(a1, b1)
47 vh.AddLink(b1, a1)
48
49 errs := vh.Start()
50
51 vn := vh.Net
52 cc := make(chan bool, 100)
53
54 vn.SelfHandler = func(node state.NodeId, src, dst netip.Addr, data []byte) bool {
55 if node == "b" && src.String() == "10.0.0.1" && dst.String() == "10.0.0.2" && data[0] == 111 {
56 cc <- true
57 }
58 return true
59 }
60
61 go func() {
62 for {
63 select {
64 case <-vh.Context.Done():
65 return
66 case <-time.After(100 * time.Millisecond):
67 vn.Send("a", "10.0.0.1", "10.0.0.2", []byte{111}, 64)
68 }
69 }
70 }()
71
72 select {
73 case <-cc:
74 t.Log("Got ping!")
75 case <-time.After(10 * time.Second):
76 t.Error("Timed out waiting for ping")
77 case err := <-errs:
78 t.Error(err)
79 }
80 vh.Stop()
81}
82
83func TestSimpleRoutedPing(t *testing.T) {
84 defer goleak.VerifyNone(t)

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