(t *testing.T)
| 126 | } |
| 127 | |
| 128 | func TestSourceLoader_Read_DataChanges(t *testing.T) { |
| 129 | t.Parallel() |
| 130 | synctest.Test(t, func(t *testing.T) { |
| 131 | inner := &mockSource{ |
| 132 | name: "test.yaml", |
| 133 | data: []byte("initial data"), |
| 134 | } |
| 135 | ctx := t.Context() |
| 136 | refreshInterval := 50 * time.Millisecond |
| 137 | sl := newSourceLoader(ctx, inner, refreshInterval) |
| 138 | |
| 139 | // First read gets initial data |
| 140 | data, err := sl.Read(ctx) |
| 141 | require.NoError(t, err) |
| 142 | assert.Equal(t, []byte("initial data"), data) |
| 143 | |
| 144 | // Change the data in the mock |
| 145 | inner.setData([]byte("updated data")) |
| 146 | |
| 147 | // Immediate read still gets old cached data |
| 148 | data, err = sl.Read(ctx) |
| 149 | require.NoError(t, err) |
| 150 | assert.Equal(t, []byte("initial data"), data) |
| 151 | |
| 152 | synctest.Wait() |
| 153 | time.Sleep(60 * time.Millisecond) //nolint:forbidigo // fake time inside a synctest bubble; returns instantly |
| 154 | synctest.Wait() |
| 155 | |
| 156 | // Read after interval should get updated data from background refresh |
| 157 | data, err = sl.Read(ctx) |
| 158 | require.NoError(t, err) |
| 159 | assert.Equal(t, []byte("updated data"), data) |
| 160 | }) |
| 161 | } |
| 162 | |
| 163 | func TestSourceLoader_Read_ZeroRefreshInterval(t *testing.T) { |
| 164 | t.Parallel() |
nothing calls this directly
no test coverage detected