(t *testing.T)
| 715 | } |
| 716 | |
| 717 | func 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 | |
| 755 | func TestManager_GetConfigNilBeforeStarting(t *testing.T) { |
| 756 | cfg := newTestOverridesManagerConfig(t, time.Second, valueLoader) |
nothing calls this directly
no test coverage detected