@@ -389,6 +389,54 @@ func TestConfigWatcher_Read(t *testing.T) {
389389 require .Equal (t , c , mainFile .Config )
390390 },
391391 },
392+ {
393+ name : "provider triggers main file and then referenced file" ,
394+ test : func (t * testing.T ) {
395+ w := NewConfigWatcher (& static.Config {})
396+ mainPath := mustParse ("foo://file.yml" )
397+ mainConfig := & dynamic.Config {Info : dynamic.ConfigInfo {Url : mainPath , Checksum : []byte {1 }}}
398+ refPath := mustParse ("foo://ref.yml" )
399+ refConfig := & dynamic.Config {Info : dynamic.ConfigInfo {Url : refPath , Checksum : []byte {1 }}}
400+
401+ var ch chan dynamic.ConfigEvent
402+ w .providers ["foo" ] = & testprovider {
403+ read : func (u * url.URL ) (* dynamic.Config , error ) {
404+ c := & dynamic.Config {Info : dynamic.ConfigInfo {Url : u }}
405+ c .Info .Checksum = []byte {1 }
406+ return c , nil
407+ },
408+ start : func (configs chan dynamic.ConfigEvent , pool * safe.Pool ) error {
409+ ch = configs
410+ return nil
411+ },
412+ }
413+ pool := safe .NewPool (context .Background ())
414+ w .Start (pool )
415+ defer pool .Stop ()
416+
417+ var events []string
418+ w .AddListener (func (e dynamic.ConfigEvent ) {
419+ events = append (events , e .Config .Info .Path ())
420+ })
421+
422+ ch <- dynamic.ConfigEvent {Name : mainPath .String (), Event : dynamic .Create , Config : mainConfig }
423+ c , err := w .Read (refPath , nil )
424+ require .NoError (t , err )
425+ require .NotNil (t , c )
426+ dynamic .AddRef (mainConfig , c )
427+
428+ ch <- dynamic.ConfigEvent {Name : refPath .String (), Event : dynamic .Create , Config : refConfig }
429+
430+ time .Sleep (5 * time .Millisecond )
431+ require .Equal (t , []string {"foo://file.yml" , "foo://ref.yml" }, events )
432+
433+ refConfig .Info .Checksum = []byte {2 }
434+ ch <- dynamic.ConfigEvent {Name : refPath .String (), Event : dynamic .Create , Config : refConfig }
435+
436+ time .Sleep (5 * time .Millisecond )
437+ require .ElementsMatch (t , []string {"foo://file.yml" , "foo://ref.yml" , "foo://file.yml" , "foo://ref.yml" }, events )
438+ },
439+ },
392440 }
393441
394442 for _ , tc := range testcases {
@@ -465,8 +513,8 @@ func TestConfigWatcher_Start(t *testing.T) {
465513 },
466514 }
467515
516+ // no parallel git provider is not thread-safe
468517 for _ , tc := range testcases {
469- tc := tc
470518 t .Run (tc .name , func (t * testing.T ) {
471519 tc .f (t )
472520 })
0 commit comments