MCPcopy
hub / github.com/grafana/dskit / TestManager_UnchangedFileDoesntTriggerReload

Function TestManager_UnchangedFileDoesntTriggerReload

runtimeconfig/manager_test.go:717–753  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

715}
716
717func TestManager_UnchangedFileDoesntTriggerReload(t *testing.T) {
718 reloadPeriod := 100 * time.Millisecond
719
720 cfg := newTestOverridesManagerConfig(t, reloadPeriod, nil)
721
722 synctest.Test(t, func(t *testing.T) {
723 loadCounter := atomic.NewInt32(0)
724 cfg.Loader = func(reader io.Reader) (interface{}, error) {
725 loadCounter.Inc()
726 return valueLoader(reader)
727 }
728
729 overridesManager, err := New(cfg, "overrides", nil, log.NewNopLogger())
730 require.NoError(t, err)
731
732 ch := overridesManager.CreateListenerChannel(10) // must be big enough to hold all modifications.
733
734 require.NoError(t, services.StartAndAwaitRunning(context.Background(), overridesManager))
735
736 time.Sleep(reloadPeriod + time.Millisecond)
737 synctest.Wait()
738 require.Equal(t, int32(1), loadCounter.Load())
739
740 // Let's make some modifications to the config
741 const mods = 3
742 for i := 0; i < mods; i++ {
743 writeValueToFile(t, cfg.LoadPath[0], value{Value: i})
744 time.Sleep(reloadPeriod + time.Millisecond)
745 synctest.Wait()
746 }
747
748 require.NoError(t, services.StopAndAwaitTerminated(context.Background(), overridesManager))
749
750 assert.Equal(t, mods+1, int(loadCounter.Load())) // + 1 for initial load, before modifications
751 assert.Equal(t, mods+1, len(ch)) // Loaded values
752 })
753}
754
755func TestManager_GetConfigNilBeforeStarting(t *testing.T) {
756 cfg := newTestOverridesManagerConfig(t, time.Second, valueLoader)

Callers

nothing calls this directly

Calls 10

StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
valueLoaderFunction · 0.85
writeValueToFileFunction · 0.85
CreateListenerChannelMethod · 0.80
NewFunction · 0.70
SleepMethod · 0.65
WaitMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected