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

Function TestConnectionWrite

connection_test.go:58–88  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

56}
57
58func TestConnectionWrite(t *testing.T) {
59 cycle, caps := 10000, 256
60 msg, buf := make([]byte, caps), make([]byte, caps)
61 var wg sync.WaitGroup
62 wg.Add(1)
63 var count int32
64 expect := int32(cycle * caps)
65 opts := &options{}
66 opts.onRequest = func(ctx context.Context, connection Connection) error {
67 n, err := connection.Read(buf)
68 MustNil(t, err)
69 if atomic.AddInt32(&count, int32(n)) >= expect {
70 wg.Done()
71 }
72 return nil
73 }
74
75 r, w := GetSysFdPairs()
76 rconn, wconn := &connection{}, &connection{}
77 rconn.init(&netFD{fd: r}, opts)
78 wconn.init(&netFD{fd: w}, opts)
79
80 for i := 0; i < cycle; i++ {
81 n, err := wconn.Write(msg)
82 MustNil(t, err)
83 Equal(t, n, len(msg))
84 }
85 wg.Wait()
86 Equal(t, atomic.LoadInt32(&count), expect)
87 rconn.Close()
88}
89
90func TestConnectionLargeWrite(t *testing.T) {
91 // ci machine don't have 4GB memory, so skip test

Callers

nothing calls this directly

Calls 9

initMethod · 0.95
WriteMethod · 0.95
CloseMethod · 0.95
GetSysFdPairsFunction · 0.85
AddMethod · 0.80
WaitMethod · 0.65
MustNilFunction · 0.50
EqualFunction · 0.50
ReadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…