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

Function TestConcurrentFetch

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

Source from the content-addressed store, hash-verified

86}
87
88func 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
121func TestCacheRBAC(t *testing.T) {

Callers

nothing calls this directly

Calls 13

EXPECTMethod · 0.95
NewMockStoreFunction · 0.92
NewFunction · 0.92
AsFileReaderFunction · 0.92
ContextFunction · 0.92
CountMethod · 0.80
NewMethod · 0.65
GetFileByIDMethod · 0.65
AddMethod · 0.65
AcquireMethod · 0.65
WaitMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected