refactor: improve secure-fs throttling configuration and add unit tests

- Enhanced the configureThrottling function to prevent changes to maxConcurrency while operations are in flight.
- Added comprehensive unit tests for secure-fs throttling and retry logic, ensuring correct behavior and configuration.
- Removed outdated secure-fs test file and replaced it with a new, updated version to improve test coverage.
This commit is contained in:
Kacper
2025-12-26 22:06:39 +01:00
parent 6d3314f980
commit ad983c6422
5 changed files with 151 additions and 116 deletions

View File

@@ -45,11 +45,18 @@ let fsLimit = pLimit(config.maxConcurrency);
* @param newConfig - Partial configuration to merge with defaults
*/
export function configureThrottling(newConfig: Partial<ThrottleConfig>): void {
config = { ...config, ...newConfig };
// Recreate the limiter if concurrency changed
if (newConfig.maxConcurrency !== undefined) {
fsLimit = pLimit(config.maxConcurrency);
const newConcurrency = newConfig.maxConcurrency;
if (newConcurrency !== undefined && newConcurrency !== config.maxConcurrency) {
if (fsLimit.activeCount > 0 || fsLimit.pendingCount > 0) {
throw new Error(
`[SecureFS] Cannot change maxConcurrency while operations are in flight. Active: ${fsLimit.activeCount}, Pending: ${fsLimit.pendingCount}`
);
}
fsLimit = pLimit(newConcurrency);
}
config = { ...config, ...newConfig };
}
/**