Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 54d2152

Browse files
committed
fix: fix http cache dir creation order in coderdtest
1 parent 43b1a03 commit 54d2152

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

coderd/coderdtest/coderdtest.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
405405
workspacestats.TrackerWithTickFlush(options.WorkspaceUsageTrackerTick, options.WorkspaceUsageTrackerFlush),
406406
)
407407

408+
// create the TempDir for the HTTP file cache BEFORE we start the server and set a t.Cleanup to close it. TempDir()
409+
// registers a Cleanup function that deletes the directory, and Cleanup functions are called in reverse order. If
410+
// we don't do this, then we could try to delete the directory before the HTTP server is done with all files in it,
411+
// which on Windows will fail (can't delete files until all programs have closed handles to them).
412+
cacheDir := t.TempDir()
413+
408414
var mutex sync.RWMutex
409415
var handler http.Handler
410416
srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -515,7 +521,7 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
515521
AppHostname: options.AppHostname,
516522
AppHostnameRegex: appHostnameRegex,
517523
Logger: *options.Logger,
518-
CacheDir: t.TempDir(),
524+
CacheDir: cacheDir,
519525
RuntimeConfig: runtimeManager,
520526
Database: options.Database,
521527
Pubsub: options.Pubsub,

0 commit comments

Comments
 (0)