MCPcopy Index your code
hub / github.com/coder/coder / TestCancelledFetch

Function TestCancelledFetch

coderd/files/cache_test.go:31–52  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29)
30
31func TestCancelledFetch(t *testing.T) {
32 t.Parallel()
33
34 fileID := uuid.New()
35 dbM := dbmock.NewMockStore(gomock.NewController(t))
36
37 // The file fetch should succeed.
38 dbM.EXPECT().GetFileByID(gomock.Any(), gomock.Any()).DoAndReturn(func(mTx context.Context, fileID uuid.UUID) (database.File, error) {
39 return database.File{
40 ID: fileID,
41 Data: make([]byte, 100),
42 }, nil
43 })
44
45 cache := files.New(prometheus.NewRegistry(), &coderdtest.FakeAuthorizer{})
46
47 // Cancel the context for the first call; should fail.
48 ctx, cancel := context.WithCancel(dbauthz.AsFileReader(testutil.Context(t, testutil.WaitShort)))
49 cancel()
50 _, err := cache.Acquire(ctx, dbM, fileID)
51 assert.ErrorIs(t, err, context.Canceled)
52}
53
54// TestCancelledConcurrentFetch runs 2 Acquire calls. The first has a canceled
55// context and will get a ctx.Canceled error. The second call should get a warmfirst error and try to fetch the file

Callers

nothing calls this directly

Calls 8

EXPECTMethod · 0.95
NewMockStoreFunction · 0.92
NewFunction · 0.92
AsFileReaderFunction · 0.92
ContextFunction · 0.92
NewMethod · 0.65
GetFileByIDMethod · 0.65
AcquireMethod · 0.65

Tested by

no test coverage detected