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

Function overrideNewTimer

internal/idle/idle_test.go:68–84  ·  view source on GitHub ↗

overrideNewTimer overrides the new timer creation function by ensuring that a message is pushed on the returned channel everytime the timer fires.

(t *testing.T)

Source from the content-addressed store, hash-verified

66// overrideNewTimer overrides the new timer creation function by ensuring that a
67// message is pushed on the returned channel everytime the timer fires.
68func overrideNewTimer(t *testing.T) <-chan struct{} {
69 t.Helper()
70
71 ch := make(chan struct{}, 1)
72 origTimeAfterFunc := timeAfterFunc
73 timeAfterFunc = func(d time.Duration, callback func()) *time.Timer {
74 return time.AfterFunc(d, func() {
75 select {
76 case ch <- struct{}{}:
77 default:
78 }
79 callback()
80 })
81 }
82 t.Cleanup(func() { timeAfterFunc = origTimeAfterFunc })
83 return ch
84}
85
86// TestManager_Disabled tests the case where the idleness manager is
87// disabled by passing an idle_timeout of 0. Verifies the following things:

Calls

no outgoing calls

Tested by

no test coverage detected