MCPcopy Create free account
hub / github.com/cloudwego/netpoll / TestConnectionLargeMemory

Function TestConnectionLargeMemory

connection_test.go:522–554  ·  view source on GitHub ↗

TestConnectionLargeMemory is used to verify the memory usage in the large package scenario.

(t *testing.T)

Source from the content-addressed store, hash-verified

520
521// TestConnectionLargeMemory is used to verify the memory usage in the large package scenario.
522func TestConnectionLargeMemory(t *testing.T) {
523 var start, end runtime.MemStats
524 runtime.GC()
525 runtime.ReadMemStats(&start)
526
527 r, w := GetSysFdPairs()
528 rconn := &connection{}
529 rconn.init(&netFD{fd: r}, nil)
530
531 var wg sync.WaitGroup
532 rn, wn := 1024, 1*1024*1024
533
534 wg.Add(1)
535 go func() {
536 defer wg.Done()
537 _, err := rconn.Reader().Next(wn)
538 MustNil(t, err)
539 }()
540
541 msg := make([]byte, rn)
542 for i := 0; i < wn/rn; i++ {
543 n, err := syscall.Write(w, msg)
544 if err != nil {
545 MustNil(t, err)
546 }
547 Equal(t, n, rn)
548 }
549
550 runtime.ReadMemStats(&end)
551 alloc := end.TotalAlloc - start.TotalAlloc
552 limit := uint64(4 * 1024 * 1024)
553 Assert(t, alloc <= limit, fmt.Sprintf("alloc[%d] out of memory %d", alloc, limit))
554}
555
556// TestSetTCPNoDelay is used to verify the connection initialization set the TCP_NODELAY correctly
557func TestSetTCPNoDelay(t *testing.T) {

Callers

nothing calls this directly

Calls 9

initMethod · 0.95
ReaderMethod · 0.95
GetSysFdPairsFunction · 0.85
AddMethod · 0.80
NextMethod · 0.65
MustNilFunction · 0.50
EqualFunction · 0.50
AssertFunction · 0.50
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…