mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
fix: fix http cache dir creation order in coderdtest (#17303)
fixes coder/internal#565 Fixes the ordering of creating the HTTP cache temp dir with respect to starting the Coderd HTTP server, so that they are cleaned up in the correct (reverse) order.
This commit is contained in:
@ -405,6 +405,12 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
|
||||
workspacestats.TrackerWithTickFlush(options.WorkspaceUsageTrackerTick, options.WorkspaceUsageTrackerFlush),
|
||||
)
|
||||
|
||||
// create the TempDir for the HTTP file cache BEFORE we start the server and set a t.Cleanup to close it. TempDir()
|
||||
// registers a Cleanup function that deletes the directory, and Cleanup functions are called in reverse order. If
|
||||
// we don't do this, then we could try to delete the directory before the HTTP server is done with all files in it,
|
||||
// which on Windows will fail (can't delete files until all programs have closed handles to them).
|
||||
cacheDir := t.TempDir()
|
||||
|
||||
var mutex sync.RWMutex
|
||||
var handler http.Handler
|
||||
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
|
||||
AppHostname: options.AppHostname,
|
||||
AppHostnameRegex: appHostnameRegex,
|
||||
Logger: *options.Logger,
|
||||
CacheDir: t.TempDir(),
|
||||
CacheDir: cacheDir,
|
||||
RuntimeConfig: runtimeManager,
|
||||
Database: options.Database,
|
||||
Pubsub: options.Pubsub,
|
||||
|
Reference in New Issue
Block a user