MCPcopy
hub / github.com/keploy/keploy / TestTeeDropOnMemoryGuard

Function TestTeeDropOnMemoryGuard

pkg/agent/proxy/relay/relay_test.go:220–251  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

218}
219
220func TestTeeDropOnMemoryGuard(t *testing.T) {
221 t.Parallel()
222 var pressure atomic.Bool
223 pressure.Store(true)
224 drops := newDropSink()
225
226 h := newHarness(t, Config{
227 MemoryGuardCheck: pressure.Load,
228 OnMarkMockIncomplete: drops.record,
229 })
230
231 // Forward traffic under memory pressure. Real traffic still flows.
232 go h.writeClient([]byte("visible"))
233 got := h.readDest(len("visible"))
234 if string(got) != "visible" {
235 t.Fatalf("dest got %q, want %q", got, "visible")
236 }
237
238 // But the FakeConn does not receive the chunk.
239 _ = h.r.ClientStream().SetReadDeadline(time.Now().Add(100 * time.Millisecond))
240 _, err := h.r.ClientStream().ReadChunk()
241 if err == nil {
242 t.Fatalf("ClientStream should have timed out, got chunk")
243 }
244 if !errors.Is(err, fakeconn.ErrDeadlineExceeded) && err.(net.Error).Timeout() != true {
245 t.Fatalf("expected deadline error, got %v", err)
246 }
247
248 if drops.count(DropMemoryPressure) == 0 {
249 t.Fatalf("expected memory_pressure drop reason, got %v", drops.snapshot())
250 }
251}
252
253func TestTeeDropOnPerConnCap(t *testing.T) {
254 t.Parallel()

Callers

nothing calls this directly

Calls 12

newDropSinkFunction · 0.85
newHarnessFunction · 0.85
writeClientMethod · 0.80
readDestMethod · 0.80
ClientStreamMethod · 0.80
AddMethod · 0.80
ReadChunkMethod · 0.80
TimeoutMethod · 0.65
StoreMethod · 0.45
SetReadDeadlineMethod · 0.45
countMethod · 0.45
snapshotMethod · 0.45

Tested by

no test coverage detected