MCPcopy
hub / github.com/cloudflare/cloudflared / quicServer

Function quicServer

quic/safe_stream_test.go:98–134  ·  view source on GitHub ↗
(t *testing.T, serverReady *sync.WaitGroup, conn net.PacketConn)

Source from the content-addressed store, hash-verified

96}
97
98func quicServer(t *testing.T, serverReady *sync.WaitGroup, conn net.PacketConn) {
99 ctx, cancel := context.WithCancel(context.Background())
100 defer cancel()
101
102 earlyListener, err := quic.Listen(conn, testTLSServerConfig, testQUICConfig)
103 require.NoError(t, err)
104
105 serverReady.Done()
106 session, err := earlyListener.Accept(ctx)
107 require.NoError(t, err)
108
109 var wg sync.WaitGroup
110 for exchange := 0; exchange < exchanges; exchange++ {
111 quicStream, err := session.OpenStreamSync(context.Background())
112 require.NoError(t, err)
113 wg.Add(1)
114
115 go func(iter int) {
116 defer wg.Done()
117
118 log := zerolog.Nop()
119 stream := NewSafeStreamCloser(quicStream, 30*time.Second, &log)
120 defer stream.Close()
121
122 // Do a bunch of round trips over this stream that should work.
123 for msg := 0; msg < msgsPerExchange; msg++ {
124 serverRoundTrip(t, stream, true)
125 }
126 // And one that won't work necessarily, but shouldn't break other streams in the session.
127 if iter%2 == 1 {
128 serverRoundTrip(t, stream, false)
129 }
130 }(exchange)
131 }
132
133 wg.Wait()
134}
135
136func clientRoundTrip(t *testing.T, stream io.ReadWriteCloser, mustWork bool) {
137 response := make([]byte, len(testMsg))

Callers 1

TestSafeStreamCloseFunction · 0.70

Calls 7

CloseMethod · 0.95
NewSafeStreamCloserFunction · 0.85
serverRoundTripFunction · 0.85
WaitMethod · 0.80
ListenMethod · 0.65
OpenStreamSyncMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected