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

Function TestModule_hotReload

otkafka/integration_test.go:291–379  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

289}
290
291func TestModule_hotReload(t *testing.T) {
292 if os.Getenv("KAFKA_ADDR") == "" {
293 t.Skip("set KAFKA_ADDR to run TestModule_ProvideRunGroup")
294 return
295 }
296 addrs := strings.Split(os.Getenv("KAFKA_ADDR"), ",")
297 t.Parallel()
298
299 ctx, cancel := context.WithCancel(context.Background())
300 defer cancel()
301 cw := &channelWatcher{}
302 cw.ch = make(chan struct{})
303 cw.afterReload = make(chan struct{})
304
305 conf := map[string]interface{}{
306 "http": map[string]bool{
307 "disable": true,
308 },
309 "grpc": map[string]bool{
310 "disable": true,
311 },
312 "cron": map[string]bool{
313 "disable": true,
314 },
315 "kafka": map[string]interface{}{
316 "reader": map[string]interface{}{
317 "default": map[string]interface{}{
318 "brokers": addrs,
319 "topic": "foo",
320 },
321 },
322 "writer": map[string]interface{}{
323 "default": map[string]interface{}{
324 "brokers": addrs,
325 "topic": "foo",
326 },
327 },
328 },
329 }
330 path := createFile(conf)
331 c := core.Default(core.WithConfigStack(file.Provider(path), knoaf_json.Parser()), core.WithConfigWatcher(cw))
332 c.Provide(Providers(WithReaderReload(true), WithWriterReload(true)))
333 c.AddModuleFunc(config.New)
334
335 var group run.Group
336 for _, m := range c.Modules() {
337 if p, ok := m.(core.RunProvider); ok {
338 p.ProvideRunGroup(&group)
339 }
340 }
341 group.Add(func() error {
342 <-ctx.Done()
343 return ctx.Err()
344 }, func(err error) {
345 cancel()
346 })
347 go group.Run()
348

Callers

nothing calls this directly

Calls 15

DefaultFunction · 0.92
WithConfigStackFunction · 0.92
WithConfigWatcherFunction · 0.92
createFileFunction · 0.85
WithReaderReloadFunction · 0.85
WithWriterReloadFunction · 0.85
overwriteFileFunction · 0.85
ProvideMethod · 0.80
AddModuleFuncMethod · 0.80
DoneMethod · 0.80
InvokeMethod · 0.80
ProvidersFunction · 0.70

Tested by

no test coverage detected