| 116 | } |
| 117 | |
| 118 | func (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. |
| 152 | func genTestPair(tb testing.TB, realSocket bool) (pair testPair) { |