MCPcopy Create free account
hub / github.com/DoNewsCode/core / TestFactory_SubscribeReloadEventFrom

Function TestFactory_SubscribeReloadEventFrom

di/factory_test.go:114–137  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

112}
113
114func TestFactory_SubscribeReloadEventFrom(t *testing.T) {
115 t.Parallel()
116
117 closed := make(chan struct{})
118 ctx, cancel := context.WithCancel(context.Background())
119 defer cancel()
120 f := NewFactory(func(_ string) (Pair, error) {
121 return Pair{
122 Conn: &struct{}{},
123 Closer: func() { close(closed) },
124 }, nil
125 })
126 dispatcher := events.SyncDispatcher{}
127 f.SubscribeReloadEventFrom(&dispatcher)
128
129 f.Make("default")
130 _ = dispatcher.Dispatch(ctx, events.OnReload, events.OnReloadPayload{})
131
132 select {
133 case <-closed:
134 case <-time.After(4 * time.Second):
135 t.Fatalf("foo should be closed by now")
136 }
137}
138
139func BenchmarkFactory_slowConn(b *testing.B) {
140 f := NewFactory(func(name string) (Pair, error) {

Callers

nothing calls this directly

Calls 4

MakeMethod · 0.95
DispatchMethod · 0.95
NewFactoryFunction · 0.85

Tested by

no test coverage detected