mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-02 20:43:36 +00:00
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:
@@ -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 };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user