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

Function TestFactory_Watch

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

Source from the content-addressed store, hash-verified

76}
77
78func TestFactory_Watch(t *testing.T) {
79 t.Parallel()
80
81 mockConf := "foo"
82 ctx, cancel := context.WithCancel(context.Background())
83 defer cancel()
84 f := NewFactory(func(_ string) (Pair, error) {
85 return Pair{
86 Conn: mockConf,
87 Closer: func() {},
88 }, nil
89 })
90 dispatcher := events.SyncDispatcher{}
91 go func() {
92 f.SubscribeReloadEventFrom(&dispatcher)
93 }()
94
95 foo, err := f.Make("default")
96 assert.NoError(t, err)
97 assert.Equal(t, "foo", foo.(string))
98
99 mockConf = "bar"
100
101 foo, err = f.Make("default")
102 assert.NoError(t, err)
103 assert.Equal(t, "foo", foo.(string))
104
105 time.Sleep(3 * time.Second)
106 _ = dispatcher.Dispatch(ctx, events.OnReload, events.OnReloadPayload{})
107
108 time.Sleep(3 * time.Second)
109 foo, err = f.Make("default")
110 assert.NoError(t, err)
111 assert.Equal(t, "bar", foo.(string))
112}
113
114func TestFactory_SubscribeReloadEventFrom(t *testing.T) {
115 t.Parallel()

Callers

nothing calls this directly

Calls 4

MakeMethod · 0.95
DispatchMethod · 0.95
NewFactoryFunction · 0.85

Tested by

no test coverage detected