TestFastPath exercises the Read codepath that can receive multiple Noise frames at once and decode each in turn without making another syscall.
(t *testing.T)
| 80 | // Noise frames at once and decode each in turn without making another |
| 81 | // syscall. |
| 82 | func TestFastPath(t *testing.T) { |
| 83 | s1, s2 := memnet.NewConn("noise", 128000) |
| 84 | b := &bufferedWriteConn{s1, bufio.NewWriterSize(s1, 10000), false} |
| 85 | client, server := pairWithConns(t, b, s2) |
| 86 | |
| 87 | b.manualFlush = true |
| 88 | |
| 89 | sb := sinkReads(server) |
| 90 | |
| 91 | const packets = 10 |
| 92 | s := "test" |
| 93 | for range packets { |
| 94 | // Many separate writes, to force separate Noise frames that |
| 95 | // all get buffered up and then all sent as a single slice to |
| 96 | // the server. |
| 97 | if _, err := io.WriteString(client, s); err != nil { |
| 98 | t.Fatalf("client write1 failed: %v", err) |
| 99 | } |
| 100 | } |
| 101 | if err := b.w.Flush(); err != nil { |
| 102 | t.Fatalf("client flush failed: %v", err) |
| 103 | } |
| 104 | client.Close() |
| 105 | |
| 106 | want := strings.Repeat(s, packets) |
| 107 | if got := sb.String(len(want)); got != want { |
| 108 | t.Fatalf("wrong content received: got %q, want %q", got, want) |
| 109 | } |
| 110 | if err := sb.Error(); err != io.EOF { |
| 111 | t.Fatalf("client close wasn't seen by server") |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // Writes things larger than a single Noise frame, to check the |
| 116 | // chunking on the encoder and decoder. |
nothing calls this directly
no test coverage detected
searching dependent graphs…