MCPcopy Create free account
hub / github.com/pace/bricks / TestForget

Method TestForget

pkg/cache/testsuite/cache.go:194–242  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

192}
193
194func (suite *CacheTestSuite) TestForget() {
195 c := suite.Cache
196 ctx := log.WithContext(context.Background())
197
198 _ = c.Forget(ctx, "foo") // make sure it doesn't exist
199 suite.Run("works", func() {
200 _ = c.Put(ctx, "foo", []byte("bar"), 0)
201 _ = c.Forget(ctx, "foo")
202 _, _, err := c.Get(ctx, "foo")
203 suite.True(errors.Is(err, cache.ErrNotFound))
204 })
205 _ = c.Forget(ctx, "foo") // clean up
206
207 suite.Run("does not error when repeated", func() {
208 _ = c.Forget(ctx, "foo")
209 err := c.Forget(ctx, "foo")
210 suite.NoError(err)
211 })
212 _ = c.Forget(ctx, "foo") // clean up
213
214 _ = c.Forget(ctx, "中文پنجابی🥰🥸") // make sure it doesn't exist
215 suite.Run("supports unicode", func() {
216 err := c.Forget(ctx, "中文پنجابی🥰🥸")
217 suite.NoError(err)
218 })
219 _ = c.Forget(ctx, "中文پنجابی🥰🥸") // clean up
220
221 for i := 0; i <= 5; i++ { // make sure it doesn't exist
222 _ = c.Forget(ctx, fmt.Sprintf("foo%d", i))
223 }
224 suite.Run("does not error on simultaneous use", func() {
225 for i := 0; i <= 5; i++ {
226 _ = c.Put(ctx, fmt.Sprintf("foo%d", i), []byte("bar"), 0)
227 }
228 var wg sync.WaitGroup
229 for i := 0; i <= 5; i++ {
230 wg.Add(1)
231 go func() {
232 err := c.Forget(ctx, fmt.Sprintf("foo%d", i))
233 suite.NoError(err)
234 wg.Done()
235 }()
236 wg.Wait()
237 }
238 })
239 for i := 0; i <= 5; i++ { // clean up
240 _ = c.Forget(ctx, fmt.Sprintf("foo%d", i))
241 }
242}

Callers

nothing calls this directly

Calls 7

WithContextFunction · 0.92
WaitMethod · 0.80
ForgetMethod · 0.65
PutMethod · 0.65
GetMethod · 0.65
AddMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected