MCPcopy
hub / github.com/WireGuard/wireguard-go / Send

Method Send

device/device_test.go:118–149  ·  view source on GitHub ↗
(tb testing.TB, ping SendDirection, done chan struct{})

Source from the content-addressed store, hash-verified

116}
117
118func (pair *testPair) Send(tb testing.TB, ping SendDirection, done chan struct{}) {
119 tb.Helper()
120 p0, p1 := pair[0], pair[1]
121 if !ping {
122 // pong is the new ping
123 p0, p1 = p1, p0
124 }
125 msg := tuntest.Ping(p0.ip, p1.ip)
126 p1.tun.Outbound <- msg
127 timer := time.NewTimer(5 * time.Second)
128 defer timer.Stop()
129 var err error
130 select {
131 case msgRecv := <-p0.tun.Inbound:
132 if !bytes.Equal(msg, msgRecv) {
133 err = fmt.Errorf("%s did not transit correctly", ping)
134 }
135 case <-timer.C:
136 err = fmt.Errorf("%s did not transit", ping)
137 case <-done:
138 }
139 if err != nil {
140 // The error may have occurred because the test is done.
141 select {
142 case <-done:
143 return
144 default:
145 }
146 // Real error.
147 tb.Error(err)
148 }
149}
150
151// genTestPair creates a testPair.
152func genTestPair(tb testing.TB, realSocket bool) (pair testPair) {

Callers

nothing calls this directly

Calls 4

PingFunction · 0.92
NewTimerMethod · 0.80
StopMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected