MCPcopy
hub / github.com/docker/docker-agent / TestSourceLoader_SuccessThenError

Function TestSourceLoader_SuccessThenError

pkg/server/source_loader_test.go:185–213  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

183}
184
185func TestSourceLoader_SuccessThenError(t *testing.T) {
186 t.Parallel()
187 synctest.Test(t, func(t *testing.T) {
188 inner := &mockSource{
189 name: "test.yaml",
190 data: []byte("initial data"),
191 }
192 ctx := t.Context()
193 refreshInterval := 50 * time.Millisecond
194 sl := newSourceLoader(ctx, inner, refreshInterval)
195
196 // Initial read succeeds
197 data, err := sl.Read(ctx)
198 require.NoError(t, err)
199 assert.Equal(t, []byte("initial data"), data)
200
201 // Introduce error
202 inner.setErr(errors.New("refresh error"))
203
204 synctest.Wait()
205 time.Sleep(60 * time.Millisecond) //nolint:forbidigo // fake time inside a synctest bubble; returns instantly
206 synctest.Wait()
207
208 // Should still return old cached data despite refresh error
209 data, err = sl.Read(ctx)
210 require.NoError(t, err)
211 assert.Equal(t, []byte("initial data"), data)
212 })
213}

Callers

nothing calls this directly

Calls 6

setErrMethod · 0.95
newSourceLoaderFunction · 0.85
ContextMethod · 0.80
ReadMethod · 0.65
WaitMethod · 0.65
NewMethod · 0.45

Tested by

no test coverage detected