Skip to content

chore: don't cache errors in file cache #18555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jul 1, 2025
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
at this point the calls are just serialized anyway
  • Loading branch information
aslilac committed Jun 25, 2025
commit aab03354ffa96e8c59e4d19f99fdae002baedaf4
34 changes: 8 additions & 26 deletions coderd/files/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package files_test

import (
"context"
"sync"
"sync/atomic"
"testing"
"time"
Expand Down Expand Up @@ -35,7 +34,6 @@ func TestCancelledFetch(t *testing.T) {
t.Parallel()

fileID := uuid.New()
rdy := make(chan struct{})
dbM := dbmock.NewMockStore(gomock.NewController(t))

// First call should fail
Expand All @@ -56,33 +54,17 @@ func TestCancelledFetch(t *testing.T) {
ctx := dbauthz.AsFileReader(testutil.Context(t, testutil.WaitShort))
cache := files.New(prometheus.NewRegistry(), &coderdtest.FakeAuthorizer{})

var wg sync.WaitGroup

// First call that will fail
wg.Add(1)
go func() {
_, err := cache.Acquire(ctx, dbM, fileID)
close(rdy)
assert.ErrorIs(t, err, context.Canceled)
wg.Done()
}()
_, err := cache.Acquire(ctx, dbM, fileID)
assert.ErrorIs(t, err, context.Canceled)

// Second call, that should succeed
wg.Add(1)
go func() {
// Wait until the first goroutine has started
<-rdy
fs, err := cache.Acquire(ctx, dbM, fileID)
assert.NoError(t, err)
if fs != nil {
fs.Close()
}
wg.Done()
}()

// We need that second Acquire call to be queued up
time.Sleep(testutil.IntervalFast)
wg.Wait()
// Wait until the first goroutine has started
fs, err := cache.Acquire(ctx, dbM, fileID)
assert.NoError(t, err)
if fs != nil {
fs.Close()
}
}

// nolint:paralleltest,tparallel // Serially testing is easier
Expand Down
Loading