TestRunEchoes verifies bytes flow in both directions and both sides see each other's EOF.
(t *testing.T)
| 62 | // TestRunEchoes verifies bytes flow in both directions and both sides see |
| 63 | // each other's EOF. |
| 64 | func TestRunEchoes(t *testing.T) { |
| 65 | srvAddr, stopSrv := echoServer(t) |
| 66 | defer stopSrv() |
| 67 | |
| 68 | driverSide, clientRelaySide := tcpPair(t) |
| 69 | remote, err := net.Dial("tcp", srvAddr) |
| 70 | if err != nil { |
| 71 | t.Fatal(err) |
| 72 | } |
| 73 | |
| 74 | payload := make([]byte, 64*1024) |
| 75 | _, _ = rand.Read(payload) |
| 76 | |
| 77 | var ( |
| 78 | runErr error |
| 79 | wg sync.WaitGroup |
| 80 | ) |
| 81 | wg.Add(1) |
| 82 | go func() { |
| 83 | defer wg.Done() |
| 84 | runErr = Run(context.Background(), clientRelaySide, remote, Options{}) |
| 85 | }() |
| 86 | |
| 87 | if _, err := driverSide.Write(payload); err != nil { |
| 88 | t.Fatal(err) |
| 89 | } |
| 90 | _ = driverSide.(*net.TCPConn).CloseWrite() |
| 91 | |
| 92 | got, err := io.ReadAll(driverSide) |
| 93 | if err != nil { |
| 94 | t.Fatal(err) |
| 95 | } |
| 96 | if !bytes.Equal(got, payload) { |
| 97 | t.Fatalf("echo mismatch: got %d bytes want %d", len(got), len(payload)) |
| 98 | } |
| 99 | |
| 100 | wg.Wait() |
| 101 | if runErr != nil { |
| 102 | t.Fatalf("Run returned err: %v", runErr) |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // TestRunOnBytesNoDataRace exercises the OnBytes callback, which reads |
| 107 | // the peer direction's byte counter. Intended to catch regressions where |
nothing calls this directly
no test coverage detected