(t *testing.T)
| 29 | ) |
| 30 | |
| 31 | func 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 |
nothing calls this directly
no test coverage detected