MCPcopy
hub / github.com/grpc/grpc-go / TestSync

Method TestSync

benchmark/latency/latency_test.go:135–156  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

133}
134
135func (s) TestSync(t *testing.T) {
136 defer restoreHooks()()
137
138 // Infinitely fast CPU: time doesn't pass unless sleep is called.
139 tn := time.Unix(123, 0)
140 now = func() time.Time { return tn }
141 sleep = func(d time.Duration) { tn = tn.Add(d) }
142
143 // Simulate a 20ms latency network, then run sync across that and expect to
144 // measure 20ms latency, or 10ms additional delay for a 30ms network.
145 slowConn, err := (&Network{Kbps: 0, Latency: 20 * time.Millisecond, MTU: 5}).Conn(bufConn{&bytes.Buffer{}})
146 if err != nil {
147 t.Fatalf("Unexpected error creating connection: %v", err)
148 }
149 c, err := (&Network{Latency: 30 * time.Millisecond}).Conn(slowConn)
150 if err != nil {
151 t.Fatalf("Unexpected error creating connection: %v", err)
152 }
153 if c.(*conn).delay != 10*time.Millisecond {
154 t.Fatalf("c.delay = %v; want 10ms", c.(*conn).delay)
155 }
156}
157
158func (s) TestSyncTooSlow(t *testing.T) {
159 defer restoreHooks()()

Callers

nothing calls this directly

Calls 4

restoreHooksFunction · 0.85
ConnMethod · 0.80
AddMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected