TestConnectionLargeMemory is used to verify the memory usage in the large package scenario.
(t *testing.T)
| 520 | |
| 521 | // TestConnectionLargeMemory is used to verify the memory usage in the large package scenario. |
| 522 | func 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 |
| 557 | func TestSetTCPNoDelay(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…