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

Function testProxySSE

proxy/proxy_test.go:258–289  ·  view source on GitHub ↗
(proxy connection.OriginProxy)

Source from the content-addressed store, hash-verified

256}
257
258func testProxySSE(proxy connection.OriginProxy) func(t *testing.T) {
259 return func(t *testing.T) {
260 var (
261 pushCount = 50
262 pushFreq = time.Millisecond * 10
263 )
264 responseWriter := newMockSSERespWriter()
265 ctx, cancel := context.WithCancel(t.Context())
266 req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("http://localhost:8080%s?freq=%s", hello.SSERoute, pushFreq), nil)
267 require.NoError(t, err)
268
269 var wg sync.WaitGroup
270 wg.Add(1)
271 go func() {
272 defer wg.Done()
273 log := zerolog.Nop()
274 err = proxy.ProxyHTTP(responseWriter, tracing.NewTracedHTTPRequest(req, 0, &log), false)
275 require.Equal(t, "context canceled", err.Error())
276
277 require.Equal(t, http.StatusOK, responseWriter.Code)
278 }()
279
280 for i := 0; i < pushCount; i++ {
281 line := responseWriter.ReadBytes()
282 expect := fmt.Sprintf("%d\n\n", i)
283 require.Equal(t, []byte(expect), line, "Expect to read %v, got %v", expect, line)
284 }
285
286 cancel()
287 wg.Wait()
288 }
289}
290
291// Regression test to guarantee that we always write the contents downstream even if EOF is reached without
292// hitting the delimiter

Callers 1

TestProxySingleOriginFunction · 0.85

Calls 9

NewTracedHTTPRequestFunction · 0.92
newMockSSERespWriterFunction · 0.85
ReadBytesMethod · 0.80
WaitMethod · 0.80
ContextMethod · 0.65
AddMethod · 0.65
ProxyHTTPMethod · 0.65
EqualMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected