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

Function TestSourceLoader_Read_DataChanges

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

Source from the content-addressed store, hash-verified

126}
127
128func 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
163func TestSourceLoader_Read_ZeroRefreshInterval(t *testing.T) {
164 t.Parallel()

Callers

nothing calls this directly

Calls 5

setDataMethod · 0.95
newSourceLoaderFunction · 0.85
ContextMethod · 0.80
ReadMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected