fix(tests): clear the SQLite pool before deleting the secrets path-guard temp dir — Windows sharing violation

This commit is contained in:
Joseph Doherty
2026-08-15 20:04:59 -04:00
parent a756e47682
commit 25f07f89dd
2 changed files with 24 additions and 7 deletions
@@ -100,7 +100,24 @@ public sealed class SecretsStorePathGuardTests
finally
{
Environment.SetEnvironmentVariable(SqlitePathVariable, original);
Directory.Delete(directory, recursive: true);
// The store runs in WAL mode with connection pooling, so a pooled handle can outlive the
// migration and keep secrets.db (plus its -wal/-shm sidecars) open. Windows refuses to
// delete a directory holding open files where Unix does not, so clear the pool first;
// the catch is belt-and-braces for a sidecar whose handle outlasts even that.
Microsoft.Data.Sqlite.SqliteConnection.ClearAllPools();
try
{
Directory.Delete(directory, recursive: true);
}
catch (IOException)
{
// Best-effort cleanup of the temp store; a locked file must not fail the test.
}
catch (UnauthorizedAccessException)
{
// Best-effort cleanup of the temp store; a locked file must not fail the test.
}
}
}