(t *testing.T)
| 86 | } |
| 87 | |
| 88 | func TestConcurrentFetch(t *testing.T) { |
| 89 | t.Parallel() |
| 90 | |
| 91 | fileID := uuid.New() |
| 92 | |
| 93 | // Only allow one call, which should succeed |
| 94 | dbM := dbmock.NewMockStore(gomock.NewController(t)) |
| 95 | dbM.EXPECT().GetFileByID(gomock.Any(), gomock.Any()).DoAndReturn(func(mTx context.Context, fileID uuid.UUID) (database.File, error) { |
| 96 | return database.File{ID: fileID}, nil |
| 97 | }) |
| 98 | |
| 99 | cache := files.New(prometheus.NewRegistry(), &coderdtest.FakeAuthorizer{}) |
| 100 | ctx := dbauthz.AsFileReader(testutil.Context(t, testutil.WaitShort)) |
| 101 | |
| 102 | // Expect 2 calls to Acquire before we continue the test |
| 103 | var wg sync.WaitGroup |
| 104 | |
| 105 | wg.Add(2) |
| 106 | for range 2 { |
| 107 | // TODO: wg.Go in Go 1.25 |
| 108 | go func() { |
| 109 | defer wg.Done() |
| 110 | _, err := cache.Acquire(ctx, dbM, fileID) |
| 111 | assert.NoError(t, err) |
| 112 | }() |
| 113 | } |
| 114 | |
| 115 | // Wait for both go routines to assert their errors and finish. |
| 116 | wg.Wait() |
| 117 | require.Equal(t, 1, cache.Count()) |
| 118 | } |
| 119 | |
| 120 | // nolint:paralleltest,tparallel // Serially testing is easier |
| 121 | func TestCacheRBAC(t *testing.T) { |
nothing calls this directly
no test coverage detected