(t *testing.T)
| 289 | } |
| 290 | |
| 291 | func 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 |
nothing calls this directly
no test coverage detected