@daiso-tech/core 0.49.1 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cache/contracts/_module-exports.d.ts +1 -1
- package/dist/cache/contracts/_module.d.ts +1 -1
- package/dist/cache/contracts/{cache-factory.contract.d.ts → cache-resolver.contract.d.ts} +2 -2
- package/dist/cache/contracts/{cache-factory.contract.js → cache-resolver.contract.js} +1 -1
- package/dist/cache/contracts/cache-resolver.contract.js.map +1 -0
- package/dist/cache/contracts/cache.contract.d.ts +2 -2
- package/dist/cache/contracts/cache.errors.d.ts +3 -1
- package/dist/cache/contracts/cache.errors.js +5 -3
- package/dist/cache/contracts/cache.errors.js.map +1 -1
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.d.ts +1 -1
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js +1 -2
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/derivables/_module-exports.d.ts +1 -1
- package/dist/cache/implementations/derivables/_module-exports.js +1 -1
- package/dist/cache/implementations/derivables/_module-exports.js.map +1 -1
- package/dist/cache/implementations/derivables/_module.d.ts +1 -1
- package/dist/cache/implementations/derivables/_module.js +1 -1
- package/dist/cache/implementations/derivables/_module.js.map +1 -1
- package/dist/cache/implementations/derivables/{cache-factory → cache-resolver}/_module.d.ts +1 -1
- package/dist/cache/implementations/derivables/cache-resolver/_module.js +2 -0
- package/dist/cache/implementations/derivables/cache-resolver/_module.js.map +1 -0
- package/dist/cache/implementations/derivables/{cache-factory/cache-factory.d.ts → cache-resolver/cache-resolver.d.ts} +18 -18
- package/dist/cache/implementations/derivables/{cache-factory/cache-factory.js → cache-resolver/cache-resolver.js} +17 -17
- package/dist/cache/implementations/derivables/cache-resolver/cache-resolver.js.map +1 -0
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.d.ts +10 -0
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js +47 -43
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js.map +1 -1
- package/dist/cache/implementations/test-utilities/cache.test-suite.d.ts +10 -0
- package/dist/cache/implementations/test-utilities/cache.test-suite.js +34 -34
- package/dist/cache/implementations/test-utilities/cache.test-suite.js.map +1 -1
- package/dist/circuit-breaker/contracts/_module-exports.d.ts +2 -2
- package/dist/circuit-breaker/contracts/_module-exports.js +1 -1
- package/dist/circuit-breaker/contracts/_module-exports.js.map +1 -1
- package/dist/circuit-breaker/contracts/_module.d.ts +2 -2
- package/dist/circuit-breaker/contracts/_module.js +1 -1
- package/dist/circuit-breaker/contracts/_module.js.map +1 -1
- package/dist/circuit-breaker/contracts/circuit-breaker-adapter.contract.d.ts +1 -1
- package/dist/circuit-breaker/contracts/circuit-breaker-adapter.contract.js +1 -1
- package/dist/circuit-breaker/contracts/circuit-breaker-adapter.contract.js.map +1 -1
- package/dist/circuit-breaker/contracts/{circuit-breaker-provider-factory.contract.d.ts → circuit-breaker-factory-resolver.contract.d.ts} +4 -4
- package/dist/circuit-breaker/contracts/{circuit-breaker-provider-factory.contract.js → circuit-breaker-factory-resolver.contract.js} +2 -2
- package/dist/circuit-breaker/contracts/circuit-breaker-factory-resolver.contract.js.map +1 -0
- package/dist/circuit-breaker/contracts/{circuit-breaker-provider.contract.d.ts → circuit-breaker-factory.contract.d.ts} +4 -4
- package/dist/circuit-breaker/contracts/{circuit-breaker-provider.contract.js → circuit-breaker-factory.contract.js} +1 -1
- package/dist/circuit-breaker/contracts/circuit-breaker-factory.contract.js.map +1 -0
- package/dist/circuit-breaker/contracts/circuit-breaker.errors.d.ts +2 -1
- package/dist/circuit-breaker/contracts/circuit-breaker.errors.js +4 -3
- package/dist/circuit-breaker/contracts/circuit-breaker.errors.js.map +1 -1
- package/dist/circuit-breaker/implementations/adapters/memory-circuit-breaker-storage-adapter/memory-circuit-breaker-storage-adapter.d.ts +1 -1
- package/dist/circuit-breaker/implementations/adapters/memory-circuit-breaker-storage-adapter/memory-circuit-breaker-storage-adapter.js +1 -1
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-adapter/no-op-circuit-breaker-adapter.d.ts +1 -1
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-adapter/no-op-circuit-breaker-adapter.js +1 -1
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-storage-adapter/no-op-circuit-breaker-storage-adapter.d.ts +1 -1
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-storage-adapter/no-op-circuit-breaker-storage-adapter.js +1 -1
- package/dist/circuit-breaker/implementations/derivables/_module-exports.d.ts +2 -2
- package/dist/circuit-breaker/implementations/derivables/_module-exports.js +2 -2
- package/dist/circuit-breaker/implementations/derivables/_module-exports.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/_module.d.ts +2 -2
- package/dist/circuit-breaker/implementations/derivables/_module.js +2 -2
- package/dist/circuit-breaker/implementations/derivables/_module.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/{circuit-breaker-provider → circuit-breaker-factory}/_module.d.ts +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-factory/_module.js +2 -0
- package/dist/circuit-breaker/implementations/derivables/{circuit-breaker-provider → circuit-breaker-factory}/_module.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/{circuit-breaker-provider/circuit-breaker-provider.d.ts → circuit-breaker-factory/circuit-breaker-factory.d.ts} +9 -9
- package/dist/circuit-breaker/implementations/derivables/{circuit-breaker-provider/circuit-breaker-provider.js → circuit-breaker-factory/circuit-breaker-factory.js} +7 -7
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-factory/circuit-breaker-factory.js.map +1 -0
- package/dist/circuit-breaker/implementations/derivables/{circuit-breaker-provider → circuit-breaker-factory}/circuit-breaker-serde-transformer.d.ts +1 -1
- package/dist/circuit-breaker/implementations/derivables/{circuit-breaker-provider → circuit-breaker-factory}/circuit-breaker-serde-transformer.js +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-factory/circuit-breaker-serde-transformer.js.map +1 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-factory/circuit-breaker.js.map +1 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-factory-resolver/_module.d.ts +2 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-factory-resolver/_module.js +3 -0
- package/dist/circuit-breaker/implementations/derivables/{circuit-breaker-provider-factory → circuit-breaker-factory-resolver}/_module.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/{circuit-breaker-provider-factory/circuit-breaker-provider-factory.d.ts → circuit-breaker-factory-resolver/circuit-breaker-factory-resolver.d.ts} +18 -18
- package/dist/circuit-breaker/implementations/derivables/{circuit-breaker-provider-factory/circuit-breaker-provider-factory.js → circuit-breaker-factory-resolver/circuit-breaker-factory-resolver.js} +17 -17
- package/dist/circuit-breaker/implementations/derivables/{circuit-breaker-provider-factory/circuit-breaker-provider-factory.js.map → circuit-breaker-factory-resolver/circuit-breaker-factory-resolver.js.map} +1 -1
- package/dist/circuit-breaker/implementations/derivables/{circuit-breaker-provider-factory/database-circuit-breaker-provider-factory.d.ts → circuit-breaker-factory-resolver/database-circuit-breaker-factory-resolver.d.ts} +20 -20
- package/dist/circuit-breaker/implementations/derivables/{circuit-breaker-provider-factory/database-circuit-breaker-provider-factory.js → circuit-breaker-factory-resolver/database-circuit-breaker-factory-resolver.js} +19 -19
- package/dist/circuit-breaker/implementations/derivables/{circuit-breaker-provider-factory/database-circuit-breaker-provider-factory.js.map → circuit-breaker-factory-resolver/database-circuit-breaker-factory-resolver.js.map} +1 -1
- package/dist/circuit-breaker/implementations/test-utilities/consecutive-breaker.test-suite.d.ts +10 -0
- package/dist/circuit-breaker/implementations/test-utilities/consecutive-breaker.test-suite.js +12 -11
- package/dist/circuit-breaker/implementations/test-utilities/consecutive-breaker.test-suite.js.map +1 -1
- package/dist/circuit-breaker/implementations/test-utilities/count-breaker.test-suite.d.ts +10 -0
- package/dist/circuit-breaker/implementations/test-utilities/count-breaker.test-suite.js +13 -12
- package/dist/circuit-breaker/implementations/test-utilities/count-breaker.test-suite.js.map +1 -1
- package/dist/circuit-breaker/implementations/test-utilities/sampling-breaker.test-suite.d.ts +10 -0
- package/dist/circuit-breaker/implementations/test-utilities/sampling-breaker.test-suite.js +3 -2
- package/dist/circuit-breaker/implementations/test-utilities/sampling-breaker.test-suite.js.map +1 -1
- package/dist/codec/contracts/codec.errors.d.ts +2 -1
- package/dist/codec/contracts/codec.errors.js +4 -3
- package/dist/codec/contracts/codec.errors.js.map +1 -1
- package/dist/collection/contracts/collection.errors.d.ts +11 -0
- package/dist/collection/contracts/collection.errors.js +13 -0
- package/dist/collection/contracts/collection.errors.js.map +1 -1
- package/dist/event-bus/contracts/_module-exports.d.ts +1 -1
- package/dist/event-bus/contracts/_module.d.ts +1 -1
- package/dist/event-bus/contracts/{event-bus-factory.contract.d.ts → event-bus-resolver.contract.d.ts} +2 -2
- package/dist/event-bus/contracts/{event-bus-factory.contract.js → event-bus-resolver.contract.js} +1 -1
- package/dist/event-bus/contracts/event-bus-resolver.contract.js.map +1 -0
- package/dist/event-bus/contracts/event-bus.contract.d.ts +1 -1
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.d.ts +1 -1
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js +1 -1
- package/dist/event-bus/implementations/derivables/_module-exports.d.ts +1 -1
- package/dist/event-bus/implementations/derivables/_module-exports.js +1 -1
- package/dist/event-bus/implementations/derivables/_module-exports.js.map +1 -1
- package/dist/event-bus/implementations/derivables/_module.d.ts +1 -1
- package/dist/event-bus/implementations/derivables/_module.js +1 -1
- package/dist/event-bus/implementations/derivables/_module.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +0 -2
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
- package/dist/event-bus/implementations/derivables/{event-bus-factory → event-bus-resolver}/_module.d.ts +1 -1
- package/dist/event-bus/implementations/derivables/event-bus-resolver/_module.js +2 -0
- package/dist/event-bus/implementations/derivables/event-bus-resolver/_module.js.map +1 -0
- package/dist/event-bus/implementations/derivables/{event-bus-factory/event-bus-factory.d.ts → event-bus-resolver/event-bus-resolver.d.ts} +18 -16
- package/dist/event-bus/implementations/derivables/{event-bus-factory/event-bus-factory.js → event-bus-resolver/event-bus-resolver.js} +17 -15
- package/dist/event-bus/implementations/derivables/event-bus-resolver/event-bus-resolver.js.map +1 -0
- package/dist/file-storage/contracts/_module-exports.d.ts +1 -1
- package/dist/file-storage/contracts/_module.d.ts +1 -1
- package/dist/file-storage/contracts/{file-storage-factory.contract.d.ts → file-storage-resolver.contract.d.ts} +2 -2
- package/dist/file-storage/contracts/{file-storage-factory.contract.js → file-storage-resolver.contract.js} +1 -1
- package/dist/file-storage/contracts/file-storage-resolver.contract.js.map +1 -0
- package/dist/file-storage/contracts/file-storage.contract.d.ts +2 -2
- package/dist/file-storage/contracts/file.errors.d.ts +2 -1
- package/dist/file-storage/contracts/file.errors.js +4 -3
- package/dist/file-storage/contracts/file.errors.js.map +1 -1
- package/dist/file-storage/implementations/derivables/_module-exports.d.ts +2 -2
- package/dist/file-storage/implementations/derivables/_module-exports.js +2 -2
- package/dist/file-storage/implementations/derivables/_module-exports.js.map +1 -1
- package/dist/file-storage/implementations/derivables/_module.d.ts +1 -1
- package/dist/file-storage/implementations/derivables/_module.js +1 -1
- package/dist/file-storage/implementations/derivables/_module.js.map +1 -1
- package/dist/file-storage/implementations/derivables/{file-storage-factory → file-storage-resolver}/_module.d.ts +1 -1
- package/dist/file-storage/implementations/derivables/file-storage-resolver/_module.js +2 -0
- package/dist/file-storage/implementations/derivables/{file-storage-factory → file-storage-resolver}/_module.js.map +1 -1
- package/dist/file-storage/implementations/derivables/{file-storage-factory/file-storage-factory.d.ts → file-storage-resolver/file-storage-resolver.d.ts} +16 -16
- package/dist/file-storage/implementations/derivables/{file-storage-factory/file-storage-factory.js → file-storage-resolver/file-storage-resolver.js} +15 -15
- package/dist/file-storage/implementations/derivables/file-storage-resolver/file-storage-resolver.js.map +1 -0
- package/dist/file-storage/implementations/test-utilities/file-storage-adapter.test-suite.js +1 -42
- package/dist/file-storage/implementations/test-utilities/file-storage-adapter.test-suite.js.map +1 -1
- package/dist/file-storage/implementations/test-utilities/file-storage.test-suite.js +1 -59
- package/dist/file-storage/implementations/test-utilities/file-storage.test-suite.js.map +1 -1
- package/dist/lock/contracts/_module-exports.d.ts +2 -2
- package/dist/lock/contracts/_module.d.ts +2 -2
- package/dist/lock/contracts/database-lock-adapter.contract.d.ts +7 -7
- package/dist/lock/contracts/lock-adapter.contract.d.ts +1 -1
- package/dist/lock/contracts/lock-adapter.contract.js +1 -1
- package/dist/lock/contracts/lock-adapter.contract.js.map +1 -1
- package/dist/lock/contracts/{lock-provider-factory.contract.d.ts → lock-factory-resolver.contract.d.ts} +4 -4
- package/dist/lock/contracts/{lock-provider-factory.contract.js → lock-factory-resolver.contract.js} +2 -2
- package/dist/lock/contracts/lock-factory-resolver.contract.js.map +1 -0
- package/dist/lock/contracts/{lock-provider.contract.d.ts → lock-factory.contract.d.ts} +6 -6
- package/dist/lock/contracts/{lock-provider.contract.js → lock-factory.contract.js} +1 -1
- package/dist/lock/contracts/lock-factory.contract.js.map +1 -0
- package/dist/lock/contracts/lock.contract.d.ts +2 -1
- package/dist/lock/contracts/lock.contract.js +1 -0
- package/dist/lock/contracts/lock.contract.js.map +1 -1
- package/dist/lock/contracts/lock.errors.d.ts +3 -2
- package/dist/lock/contracts/lock.errors.js +5 -4
- package/dist/lock/contracts/lock.errors.js.map +1 -1
- package/dist/lock/contracts/lock.events.d.ts +2 -2
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.d.ts +1 -1
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +1 -1
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.d.ts +1 -1
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js +1 -1
- package/dist/lock/implementations/derivables/_module-exports.d.ts +2 -2
- package/dist/lock/implementations/derivables/_module-exports.js +2 -2
- package/dist/lock/implementations/derivables/_module-exports.js.map +1 -1
- package/dist/lock/implementations/derivables/_module.d.ts +2 -2
- package/dist/lock/implementations/derivables/_module.js +2 -2
- package/dist/lock/implementations/derivables/_module.js.map +1 -1
- package/dist/lock/implementations/derivables/{lock-provider → lock-factory}/_module.d.ts +2 -2
- package/dist/lock/implementations/derivables/{lock-provider → lock-factory}/_module.js +2 -2
- package/dist/lock/implementations/derivables/lock-factory/_module.js.map +1 -0
- package/dist/lock/implementations/derivables/lock-factory/database-lock-adapter.js.map +1 -0
- package/dist/lock/implementations/derivables/lock-factory/is-database-lock-adapter.js.map +1 -0
- package/dist/lock/implementations/derivables/{lock-provider/lock-provider.d.ts → lock-factory/lock-factory.d.ts} +14 -14
- package/dist/lock/implementations/derivables/{lock-provider/lock-provider.js → lock-factory/lock-factory.js} +12 -12
- package/dist/lock/implementations/derivables/lock-factory/lock-factory.js.map +1 -0
- package/dist/lock/implementations/derivables/{lock-provider → lock-factory}/lock-serde-transformer.d.ts +1 -1
- package/dist/lock/implementations/derivables/{lock-provider → lock-factory}/lock-serde-transformer.js +1 -1
- package/dist/lock/implementations/derivables/lock-factory/lock-serde-transformer.js.map +1 -0
- package/dist/lock/implementations/derivables/lock-factory/lock.js.map +1 -0
- package/dist/lock/implementations/derivables/{lock-provider → lock-factory}/resolve-lock-adapter.js +2 -2
- package/dist/lock/implementations/derivables/lock-factory/resolve-lock-adapter.js.map +1 -0
- package/dist/lock/implementations/derivables/{lock-provider-factory → lock-factory-resolver}/_module.d.ts +1 -1
- package/dist/lock/implementations/derivables/lock-factory-resolver/_module.js +2 -0
- package/dist/lock/implementations/derivables/lock-factory-resolver/_module.js.map +1 -0
- package/dist/lock/implementations/derivables/{lock-provider-factory/lock-provider-factory.d.ts → lock-factory-resolver/lock-factory-resolver.d.ts} +20 -20
- package/dist/lock/implementations/derivables/{lock-provider-factory/lock-provider-factory.js → lock-factory-resolver/lock-factory-resolver.js} +19 -19
- package/dist/lock/implementations/derivables/lock-factory-resolver/lock-factory-resolver.js.map +1 -0
- package/dist/lock/implementations/test-utilities/_module-exports.d.ts +1 -1
- package/dist/lock/implementations/test-utilities/_module-exports.js +1 -1
- package/dist/lock/implementations/test-utilities/_module-exports.js.map +1 -1
- package/dist/lock/implementations/test-utilities/_module.d.ts +1 -1
- package/dist/lock/implementations/test-utilities/_module.js +1 -1
- package/dist/lock/implementations/test-utilities/_module.js.map +1 -1
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.d.ts +10 -0
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js +147 -164
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js.map +1 -1
- package/dist/lock/implementations/test-utilities/{lock-provider.test-suite.d.ts → lock-factory.test-suite.d.ts} +37 -13
- package/dist/lock/implementations/test-utilities/{lock-provider.test-suite.js → lock-factory.test-suite.js} +488 -549
- package/dist/lock/implementations/test-utilities/lock-factory.test-suite.js.map +1 -0
- package/dist/rate-limiter/contracts/_module-exports.d.ts +2 -2
- package/dist/rate-limiter/contracts/_module.d.ts +2 -2
- package/dist/rate-limiter/contracts/rate-limiter-adapter.contract.d.ts +1 -1
- package/dist/rate-limiter/contracts/rate-limiter-adapter.contract.js +1 -1
- package/dist/rate-limiter/contracts/rate-limiter-adapter.contract.js.map +1 -1
- package/dist/rate-limiter/contracts/{rate-limiter-provider-factory.contract.d.ts → rate-limiter-factory-resolver.contract.d.ts} +4 -4
- package/dist/rate-limiter/contracts/{rate-limiter-provider-factory.contract.js → rate-limiter-factory-resolver.contract.js} +2 -2
- package/dist/rate-limiter/contracts/rate-limiter-factory-resolver.contract.js.map +1 -0
- package/dist/rate-limiter/contracts/{rate-limiter-provider.contract.d.ts → rate-limiter-factory.contract.d.ts} +4 -4
- package/dist/rate-limiter/contracts/{rate-limiter-provider.contract.js → rate-limiter-factory.contract.js} +1 -1
- package/dist/rate-limiter/contracts/rate-limiter-factory.contract.js.map +1 -0
- package/dist/rate-limiter/contracts/rate-limiter.errors.d.ts +3 -2
- package/dist/rate-limiter/contracts/rate-limiter.errors.js +6 -5
- package/dist/rate-limiter/contracts/rate-limiter.errors.js.map +1 -1
- package/dist/rate-limiter/implementations/adapters/memory-rate-limiter-storage-adapter/memory-rate-limiter-storage-adapter.d.ts +1 -1
- package/dist/rate-limiter/implementations/adapters/memory-rate-limiter-storage-adapter/memory-rate-limiter-storage-adapter.js +1 -1
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-adapter/no-op-rate-limiter-adapter.d.ts +1 -1
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-adapter/no-op-rate-limiter-adapter.js +1 -1
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-storage-adapter/no-op-rate-limiter-storage-adapter.d.ts +1 -1
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-storage-adapter/no-op-rate-limiter-storage-adapter.js +1 -1
- package/dist/rate-limiter/implementations/derivables/_module-exports.d.ts +2 -2
- package/dist/rate-limiter/implementations/derivables/_module-exports.js +2 -2
- package/dist/rate-limiter/implementations/derivables/_module-exports.js.map +1 -1
- package/dist/rate-limiter/implementations/derivables/_module.d.ts +2 -2
- package/dist/rate-limiter/implementations/derivables/_module.js +2 -2
- package/dist/rate-limiter/implementations/derivables/_module.js.map +1 -1
- package/dist/rate-limiter/implementations/derivables/{rate-limiter-provider → rate-limiter-factory}/_module.d.ts +1 -1
- package/dist/rate-limiter/implementations/derivables/rate-limiter-factory/_module.js +2 -0
- package/dist/rate-limiter/implementations/derivables/{rate-limiter-provider → rate-limiter-factory}/_module.js.map +1 -1
- package/dist/rate-limiter/implementations/derivables/{rate-limiter-provider/rate-limiter-provider.d.ts → rate-limiter-factory/rate-limiter-factory.d.ts} +8 -8
- package/dist/rate-limiter/implementations/derivables/{rate-limiter-provider/rate-limiter-provider.js → rate-limiter-factory/rate-limiter-factory.js} +6 -6
- package/dist/rate-limiter/implementations/derivables/rate-limiter-factory/rate-limiter-factory.js.map +1 -0
- package/dist/rate-limiter/implementations/derivables/{rate-limiter-provider → rate-limiter-factory}/rate-limiter-serde-transformer.d.ts +1 -1
- package/dist/rate-limiter/implementations/derivables/{rate-limiter-provider → rate-limiter-factory}/rate-limiter-serde-transformer.js +1 -1
- package/dist/rate-limiter/implementations/derivables/rate-limiter-factory/rate-limiter-serde-transformer.js.map +1 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-factory/rate-limiter.js.map +1 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-factory-resolver/_module.d.ts +2 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-factory-resolver/_module.js +3 -0
- package/dist/rate-limiter/implementations/derivables/{rate-limiter-provider-factory → rate-limiter-factory-resolver}/_module.js.map +1 -1
- package/dist/rate-limiter/implementations/derivables/{rate-limiter-provider-factory/database-rate-limiter-provider-factory.d.ts → rate-limiter-factory-resolver/database-rate-limiter-factory-resolver.d.ts} +19 -19
- package/dist/rate-limiter/implementations/derivables/{rate-limiter-provider-factory/database-rate-limiter-provider-factory.js → rate-limiter-factory-resolver/database-rate-limiter-factory-resolver.js} +18 -18
- package/dist/rate-limiter/implementations/derivables/{rate-limiter-provider-factory/database-rate-limiter-provider-factory.js.map → rate-limiter-factory-resolver/database-rate-limiter-factory-resolver.js.map} +1 -1
- package/dist/rate-limiter/implementations/derivables/{rate-limiter-provider-factory/rate-limiter-provider-factory.d.ts → rate-limiter-factory-resolver/rate-limiter-factory-resolver.d.ts} +17 -17
- package/dist/rate-limiter/implementations/derivables/{rate-limiter-provider-factory/rate-limiter-provider-factory.js → rate-limiter-factory-resolver/rate-limiter-factory-resolver.js} +16 -16
- package/dist/rate-limiter/implementations/derivables/{rate-limiter-provider-factory/rate-limiter-provider-factory.js.map → rate-limiter-factory-resolver/rate-limiter-factory-resolver.js.map} +1 -1
- package/dist/rate-limiter/implementations/test-utilities/fixed-window-limiter.test-suite.d.ts +10 -0
- package/dist/rate-limiter/implementations/test-utilities/fixed-window-limiter.test-suite.js +7 -6
- package/dist/rate-limiter/implementations/test-utilities/fixed-window-limiter.test-suite.js.map +1 -1
- package/dist/rate-limiter/implementations/test-utilities/sliding-window-limiter.test-suite.d.ts +10 -0
- package/dist/rate-limiter/implementations/test-utilities/sliding-window-limiter.test-suite.js +3 -2
- package/dist/rate-limiter/implementations/test-utilities/sliding-window-limiter.test-suite.js.map +1 -1
- package/dist/resilience/middlewares/timeout/timeout.middleware.js.map +1 -1
- package/dist/semaphore/contracts/_module-exports.d.ts +2 -2
- package/dist/semaphore/contracts/_module.d.ts +2 -2
- package/dist/semaphore/contracts/semaphore-adapter.contract.d.ts +1 -1
- package/dist/semaphore/contracts/semaphore-adapter.contract.js +1 -1
- package/dist/semaphore/contracts/semaphore-adapter.contract.js.map +1 -1
- package/dist/semaphore/contracts/{semaphore-provider-factory.contract.d.ts → semaphore-factory-resolver.contract.d.ts} +4 -4
- package/dist/semaphore/contracts/{semaphore-provider-factory.contract.js → semaphore-factory-resolver.contract.js} +2 -2
- package/dist/semaphore/contracts/semaphore-factory-resolver.contract.js.map +1 -0
- package/dist/semaphore/contracts/{semaphore-provider.contract.d.ts → semaphore-factory.contract.d.ts} +6 -6
- package/dist/semaphore/contracts/{semaphore-provider.contract.js → semaphore-factory.contract.js} +1 -1
- package/dist/semaphore/contracts/semaphore-factory.contract.js.map +1 -0
- package/dist/semaphore/contracts/semaphore.contract.d.ts +2 -1
- package/dist/semaphore/contracts/semaphore.contract.js +1 -0
- package/dist/semaphore/contracts/semaphore.contract.js.map +1 -1
- package/dist/semaphore/contracts/semaphore.errors.d.ts +3 -2
- package/dist/semaphore/contracts/semaphore.errors.js +4 -3
- package/dist/semaphore/contracts/semaphore.errors.js.map +1 -1
- package/dist/semaphore/contracts/semaphore.events.d.ts +4 -4
- package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/memory-semaphore-adapter.d.ts +1 -1
- package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/memory-semaphore-adapter.js +1 -1
- package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/no-op-semaphore-adapter.d.ts +1 -1
- package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/no-op-semaphore-adapter.js +1 -1
- package/dist/semaphore/implementations/derivables/_module-exports.d.ts +2 -2
- package/dist/semaphore/implementations/derivables/_module-exports.js +1 -1
- package/dist/semaphore/implementations/derivables/_module-exports.js.map +1 -1
- package/dist/semaphore/implementations/derivables/_module.d.ts +2 -2
- package/dist/semaphore/implementations/derivables/_module.js +1 -1
- package/dist/semaphore/implementations/derivables/_module.js.map +1 -1
- package/dist/semaphore/implementations/derivables/{semaphore-provider → semaphore-factory}/_module.d.ts +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-factory/_module.js +2 -0
- package/dist/{event-bus/implementations/derivables/event-bus-factory → semaphore/implementations/derivables/semaphore-factory}/_module.js.map +1 -1
- package/dist/semaphore/implementations/derivables/{semaphore-provider → semaphore-factory}/database-semaphore-adapter.js +8 -8
- package/dist/semaphore/implementations/derivables/semaphore-factory/database-semaphore-adapter.js.map +1 -0
- package/dist/semaphore/implementations/derivables/semaphore-factory/is-database-semaphore-adapter.js.map +1 -0
- package/dist/semaphore/implementations/derivables/{semaphore-provider → semaphore-factory}/resolve-semaphore-adapter.js +2 -2
- package/dist/semaphore/implementations/derivables/semaphore-factory/resolve-semaphore-adapter.js.map +1 -0
- package/dist/semaphore/implementations/derivables/{semaphore-provider/semaphore-provider.d.ts → semaphore-factory/semaphore-factory.d.ts} +11 -11
- package/dist/semaphore/implementations/derivables/{semaphore-provider/semaphore-provider.js → semaphore-factory/semaphore-factory.js} +9 -9
- package/dist/semaphore/implementations/derivables/semaphore-factory/semaphore-factory.js.map +1 -0
- package/dist/semaphore/implementations/derivables/{semaphore-provider → semaphore-factory}/semaphore-serde-transformer.d.ts +1 -1
- package/dist/semaphore/implementations/derivables/{semaphore-provider → semaphore-factory}/semaphore-serde-transformer.js +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-factory/semaphore-serde-transformer.js.map +1 -0
- package/dist/semaphore/implementations/derivables/{semaphore-provider → semaphore-factory}/semaphore.js +0 -1
- package/dist/semaphore/implementations/derivables/semaphore-factory/semaphore.js.map +1 -0
- package/dist/semaphore/implementations/derivables/{semaphore-provider-factory → semaphore-factory-resolver}/_module.d.ts +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-factory-resolver/_module.js.map +1 -0
- package/dist/semaphore/implementations/derivables/{semaphore-provider-factory/semaphore-provider-factory.d.ts → semaphore-factory-resolver/semaphore-factory-resolver.d.ts} +19 -19
- package/dist/semaphore/implementations/derivables/{semaphore-provider-factory/semaphore-provider-factory.js → semaphore-factory-resolver/semaphore-factory-resolver.js} +18 -18
- package/dist/semaphore/implementations/derivables/semaphore-factory-resolver/semaphore-factory-resolver.js.map +1 -0
- package/dist/semaphore/implementations/test-utilities/_module-exports.d.ts +1 -1
- package/dist/semaphore/implementations/test-utilities/_module-exports.js +1 -1
- package/dist/semaphore/implementations/test-utilities/_module-exports.js.map +1 -1
- package/dist/semaphore/implementations/test-utilities/_module.d.ts +1 -1
- package/dist/semaphore/implementations/test-utilities/_module.js +1 -1
- package/dist/semaphore/implementations/test-utilities/_module.js.map +1 -1
- package/dist/semaphore/implementations/test-utilities/semaphore-adapter.test-suite.d.ts +10 -0
- package/dist/semaphore/implementations/test-utilities/semaphore-adapter.test-suite.js +11 -42
- package/dist/semaphore/implementations/test-utilities/semaphore-adapter.test-suite.js.map +1 -1
- package/dist/semaphore/implementations/test-utilities/{semaphore-provider.test-suite.d.ts → semaphore-factory.test-suite.d.ts} +37 -13
- package/dist/semaphore/implementations/test-utilities/{semaphore-provider.test-suite.js → semaphore-factory.test-suite.js} +453 -476
- package/dist/semaphore/implementations/test-utilities/semaphore-factory.test-suite.js.map +1 -0
- package/dist/shared-lock/contracts/_module-exports.d.ts +2 -3
- package/dist/shared-lock/contracts/_module-exports.js.map +1 -1
- package/dist/shared-lock/contracts/_module.d.ts +2 -3
- package/dist/shared-lock/contracts/_module.js.map +1 -1
- package/dist/shared-lock/contracts/database-shared-lock-adapter.contract.d.ts +6 -6
- package/dist/shared-lock/contracts/shared-lock-adapter.contract.d.ts +1 -1
- package/dist/shared-lock/contracts/shared-lock-adapter.contract.js +1 -1
- package/dist/shared-lock/contracts/shared-lock-adapter.contract.js.map +1 -1
- package/dist/shared-lock/contracts/{shared-lock-provider-factory.contract.d.ts → shared-lock-factory-resolver.contract.d.ts} +4 -4
- package/dist/shared-lock/contracts/{shared-lock-provider-factory.contract.js → shared-lock-factory-resolver.contract.js} +2 -2
- package/dist/shared-lock/contracts/shared-lock-factory-resolver.contract.js.map +1 -0
- package/dist/shared-lock/contracts/{shared-lock-provider.contract.d.ts → shared-lock-factory.contract.d.ts} +6 -6
- package/dist/shared-lock/contracts/{shared-lock-provider.contract.js → shared-lock-factory.contract.js} +1 -1
- package/dist/shared-lock/contracts/shared-lock-factory.contract.js.map +1 -0
- package/dist/shared-lock/contracts/shared-lock.errors.d.ts +20 -17
- package/dist/shared-lock/contracts/shared-lock.errors.js +17 -16
- package/dist/shared-lock/contracts/shared-lock.errors.js.map +1 -1
- package/dist/shared-lock/contracts/shared-lock.events.d.ts +17 -19
- package/dist/shared-lock/contracts/shared-lock.events.js +0 -1
- package/dist/shared-lock/contracts/shared-lock.events.js.map +1 -1
- package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/memory-shared-lock-adapter.d.ts +1 -1
- package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/memory-shared-lock-adapter.js +1 -1
- package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/no-op-shared-lock-adapter.d.ts +1 -1
- package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/no-op-shared-lock-adapter.js +1 -1
- package/dist/shared-lock/implementations/derivables/_module-exports.d.ts +2 -2
- package/dist/shared-lock/implementations/derivables/_module-exports.js +2 -2
- package/dist/shared-lock/implementations/derivables/_module-exports.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/_module.d.ts +2 -2
- package/dist/shared-lock/implementations/derivables/_module.js +2 -2
- package/dist/shared-lock/implementations/derivables/_module.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/{shared-lock-provider → shared-lock-factory}/_module.d.ts +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-factory/_module.js +2 -0
- package/dist/shared-lock/implementations/derivables/{shared-lock-provider → shared-lock-factory}/_module.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/{shared-lock-provider → shared-lock-factory}/database-shared-lock-adapter.js +8 -8
- package/dist/shared-lock/implementations/derivables/shared-lock-factory/database-shared-lock-adapter.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-factory/is-database-shared-lock-adapter.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/{shared-lock-provider → shared-lock-factory}/resolve-shared-lock-adapter.js +2 -2
- package/dist/shared-lock/implementations/derivables/shared-lock-factory/resolve-shared-lock-adapter.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/{shared-lock-provider/shared-lock-provider.d.ts → shared-lock-factory/shared-lock-factory.d.ts} +14 -14
- package/dist/shared-lock/implementations/derivables/{shared-lock-provider/shared-lock-provider.js → shared-lock-factory/shared-lock-factory.js} +12 -12
- package/dist/shared-lock/implementations/derivables/shared-lock-factory/shared-lock-factory.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/{shared-lock-provider → shared-lock-factory}/shared-lock-serde-transformer.d.ts +1 -1
- package/dist/shared-lock/implementations/derivables/{shared-lock-provider → shared-lock-factory}/shared-lock-serde-transformer.js +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-factory/shared-lock-serde-transformer.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/{shared-lock-provider → shared-lock-factory}/shared-lock.js +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-factory/shared-lock.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/{shared-lock-provider-factory → shared-lock-factory-resolver}/_module.d.ts +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-factory-resolver/_module.js +2 -0
- package/dist/shared-lock/implementations/derivables/{shared-lock-provider-factory → shared-lock-factory-resolver}/_module.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/{shared-lock-provider-factory/shared-lock-provider-factory.d.ts → shared-lock-factory-resolver/shared-lock-factory-resolver.d.ts} +18 -18
- package/dist/shared-lock/implementations/derivables/{shared-lock-provider-factory/shared-lock-provider-factory.js → shared-lock-factory-resolver/shared-lock-factory-resolver.js} +17 -17
- package/dist/shared-lock/implementations/derivables/shared-lock-factory-resolver/shared-lock-factory-resolver.js.map +1 -0
- package/dist/shared-lock/implementations/test-utilities/_module-exports.d.ts +1 -1
- package/dist/shared-lock/implementations/test-utilities/_module-exports.js +1 -1
- package/dist/shared-lock/implementations/test-utilities/_module-exports.js.map +1 -1
- package/dist/shared-lock/implementations/test-utilities/_module.d.ts +1 -1
- package/dist/shared-lock/implementations/test-utilities/_module.js +1 -1
- package/dist/shared-lock/implementations/test-utilities/_module.js.map +1 -1
- package/dist/shared-lock/implementations/test-utilities/shared-lock-adapter.test-suite.d.ts +10 -0
- package/dist/shared-lock/implementations/test-utilities/shared-lock-adapter.test-suite.js +206 -276
- package/dist/shared-lock/implementations/test-utilities/shared-lock-adapter.test-suite.js.map +1 -1
- package/dist/shared-lock/implementations/test-utilities/{shared-lock-provider.test-suite.d.ts → shared-lock-factory.test-suite.d.ts} +37 -13
- package/dist/shared-lock/implementations/test-utilities/{shared-lock-provider.test-suite.js → shared-lock-factory.test-suite.js} +1642 -1318
- package/dist/shared-lock/implementations/test-utilities/shared-lock-factory.test-suite.js.map +1 -0
- package/dist/test-utilities/_module.d.ts +18 -0
- package/dist/test-utilities/_module.js +96 -0
- package/dist/test-utilities/_module.js.map +1 -0
- package/dist/utilities/types/_module.d.ts +1 -0
- package/dist/utilities/types/infer-instance.type.d.ts +9 -0
- package/dist/utilities/types/infer-instance.type.js +5 -0
- package/dist/utilities/types/infer-instance.type.js.map +1 -0
- package/package.json +2 -2
- package/dist/cache/contracts/cache-factory.contract.js.map +0 -1
- package/dist/cache/implementations/derivables/cache-factory/_module.js +0 -2
- package/dist/cache/implementations/derivables/cache-factory/_module.js.map +0 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +0 -1
- package/dist/circuit-breaker/contracts/circuit-breaker-provider-factory.contract.js.map +0 -1
- package/dist/circuit-breaker/contracts/circuit-breaker-provider.contract.js.map +0 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/_module.js +0 -2
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-provider.js.map +0 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-serde-transformer.js.map +0 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker.js.map +0 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/_module.d.ts +0 -2
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/_module.js +0 -3
- package/dist/event-bus/contracts/event-bus-factory.contract.js.map +0 -1
- package/dist/event-bus/implementations/derivables/event-bus-factory/_module.js +0 -2
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +0 -1
- package/dist/file-storage/contracts/file-storage-factory.contract.js.map +0 -1
- package/dist/file-storage/implementations/derivables/file-storage-factory/_module.js +0 -2
- package/dist/file-storage/implementations/derivables/file-storage-factory/file-storage-factory.js.map +0 -1
- package/dist/lock/contracts/lock-provider-factory.contract.js.map +0 -1
- package/dist/lock/contracts/lock-provider.contract.js.map +0 -1
- package/dist/lock/implementations/derivables/lock-provider/_module.js.map +0 -1
- package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js.map +0 -1
- package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.js.map +0 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +0 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +0 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.js.map +0 -1
- package/dist/lock/implementations/derivables/lock-provider/resolve-lock-adapter.js.map +0 -1
- package/dist/lock/implementations/derivables/lock-provider-factory/_module.js +0 -2
- package/dist/lock/implementations/derivables/lock-provider-factory/_module.js.map +0 -1
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +0 -1
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +0 -1
- package/dist/rate-limiter/contracts/rate-limiter-provider-factory.contract.js.map +0 -1
- package/dist/rate-limiter/contracts/rate-limiter-provider.contract.js.map +0 -1
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/_module.js +0 -2
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-provider.js.map +0 -1
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-serde-transformer.js.map +0 -1
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter.js.map +0 -1
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/_module.d.ts +0 -2
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/_module.js +0 -3
- package/dist/semaphore/contracts/semaphore-provider-factory.contract.js.map +0 -1
- package/dist/semaphore/contracts/semaphore-provider.contract.js.map +0 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/_module.js +0 -2
- package/dist/semaphore/implementations/derivables/semaphore-provider/_module.js.map +0 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/database-semaphore-adapter.js.map +0 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/is-database-semaphore-adapter.js.map +0 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/resolve-semaphore-adapter.js.map +0 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.js.map +0 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.js.map +0 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.js.map +0 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/_module.js.map +0 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.js.map +0 -1
- package/dist/semaphore/implementations/test-utilities/semaphore-provider.test-suite.js.map +0 -1
- package/dist/shared-lock/contracts/shared-lock-provider-factory.contract.js.map +0 -1
- package/dist/shared-lock/contracts/shared-lock-provider.contract.js.map +0 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/_module.js +0 -2
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/database-shared-lock-adapter.js.map +0 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/is-database-shared-lock-adapter.js.map +0 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/resolve-shared-lock-adapter.js.map +0 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.js.map +0 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.js.map +0 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.js.map +0 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/_module.js +0 -2
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.js.map +0 -1
- package/dist/shared-lock/implementations/test-utilities/shared-lock-provider.test-suite.js.map +0 -1
- /package/dist/circuit-breaker/implementations/derivables/{circuit-breaker-provider → circuit-breaker-factory}/circuit-breaker.d.ts +0 -0
- /package/dist/circuit-breaker/implementations/derivables/{circuit-breaker-provider → circuit-breaker-factory}/circuit-breaker.js +0 -0
- /package/dist/lock/implementations/derivables/{lock-provider → lock-factory}/database-lock-adapter.d.ts +0 -0
- /package/dist/lock/implementations/derivables/{lock-provider → lock-factory}/database-lock-adapter.js +0 -0
- /package/dist/lock/implementations/derivables/{lock-provider → lock-factory}/is-database-lock-adapter.d.ts +0 -0
- /package/dist/lock/implementations/derivables/{lock-provider → lock-factory}/is-database-lock-adapter.js +0 -0
- /package/dist/lock/implementations/derivables/{lock-provider → lock-factory}/lock.d.ts +0 -0
- /package/dist/lock/implementations/derivables/{lock-provider → lock-factory}/lock.js +0 -0
- /package/dist/lock/implementations/derivables/{lock-provider → lock-factory}/resolve-lock-adapter.d.ts +0 -0
- /package/dist/rate-limiter/implementations/derivables/{rate-limiter-provider → rate-limiter-factory}/rate-limiter.d.ts +0 -0
- /package/dist/rate-limiter/implementations/derivables/{rate-limiter-provider → rate-limiter-factory}/rate-limiter.js +0 -0
- /package/dist/semaphore/implementations/derivables/{semaphore-provider → semaphore-factory}/database-semaphore-adapter.d.ts +0 -0
- /package/dist/semaphore/implementations/derivables/{semaphore-provider → semaphore-factory}/is-database-semaphore-adapter.d.ts +0 -0
- /package/dist/semaphore/implementations/derivables/{semaphore-provider → semaphore-factory}/is-database-semaphore-adapter.js +0 -0
- /package/dist/semaphore/implementations/derivables/{semaphore-provider → semaphore-factory}/resolve-semaphore-adapter.d.ts +0 -0
- /package/dist/semaphore/implementations/derivables/{semaphore-provider → semaphore-factory}/semaphore.d.ts +0 -0
- /package/dist/semaphore/implementations/derivables/{semaphore-provider-factory → semaphore-factory-resolver}/_module.js +0 -0
- /package/dist/shared-lock/implementations/derivables/{shared-lock-provider → shared-lock-factory}/database-shared-lock-adapter.d.ts +0 -0
- /package/dist/shared-lock/implementations/derivables/{shared-lock-provider → shared-lock-factory}/is-database-shared-lock-adapter.d.ts +0 -0
- /package/dist/shared-lock/implementations/derivables/{shared-lock-provider → shared-lock-factory}/is-database-shared-lock-adapter.js +0 -0
- /package/dist/shared-lock/implementations/derivables/{shared-lock-provider → shared-lock-factory}/resolve-shared-lock-adapter.d.ts +0 -0
- /package/dist/shared-lock/implementations/derivables/{shared-lock-provider → shared-lock-factory}/shared-lock.d.ts +0 -0
|
@@ -5,11 +5,12 @@ import { vi, } from "vitest";
|
|
|
5
5
|
import { LimitReachedSemaphoreError, SEMAPHORE_EVENTS, FailedReleaseSemaphoreError, FailedRefreshSemaphoreError, SEMAPHORE_STATE, } from "../../../semaphore/contracts/_module.js";
|
|
6
6
|
import {} from "../../../serde/contracts/_module.js";
|
|
7
7
|
import { Task } from "../../../task/implementations/_module.js";
|
|
8
|
-
import {
|
|
8
|
+
import { createIsTimeSpanEqualityTester } from "../../../test-utilities/_module.js";
|
|
9
|
+
import { TO_MILLISECONDS, } from "../../../time-span/contracts/_module.js";
|
|
9
10
|
import { TimeSpan } from "../../../time-span/implementations/_module.js";
|
|
10
11
|
import {} from "../../../utilities/_module.js";
|
|
11
12
|
/**
|
|
12
|
-
* The `
|
|
13
|
+
* The `semaphoreFactoryTestSuite` function simplifies the process of testing your custom implementation of {@link ISemaphore | `ISemaphore`} with `vitest`.
|
|
13
14
|
*
|
|
14
15
|
* IMPORT_PATH: `"@daiso-tech/core/semaphore/test-utilities"`
|
|
15
16
|
* @group Utilities
|
|
@@ -17,23 +18,23 @@ import {} from "../../../utilities/_module.js";
|
|
|
17
18
|
* ```ts
|
|
18
19
|
* import { describe, expect, test, beforeEach } from "vitest";
|
|
19
20
|
* import { MemorySemaphoreAdapter } from "@daiso-tech/core/semaphore/memory-semaphore-adapter";
|
|
20
|
-
* import {
|
|
21
|
+
* import { SemaphoreFactory } from "@daiso-tech/core/semaphore";
|
|
21
22
|
* import { EventBus } from "@daiso-tech/core/event-bus";
|
|
22
23
|
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/memory-event-bus-adapter";
|
|
23
|
-
* import {
|
|
24
|
+
* import { semaphoreFactoryTestSuite } from "@daiso-tech/core/semaphore/test-utilities";
|
|
24
25
|
* import { Serde } from "@daiso-tech/core/serde";
|
|
25
26
|
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/super-json-serde-adapter";
|
|
26
27
|
* import type { ISemaphoreData } from "@daiso-tech/core/semaphore/contracts";
|
|
27
28
|
*
|
|
28
|
-
* describe("class:
|
|
29
|
-
*
|
|
30
|
-
*
|
|
29
|
+
* describe("class: SemaphoreFactory", () => {
|
|
30
|
+
* semaphoreFactoryTestSuite({
|
|
31
|
+
* createSemaphoreFactory: () => {
|
|
31
32
|
* const serde = new Serde(new SuperJsonSerdeAdapter());
|
|
32
|
-
* const
|
|
33
|
+
* const semaphoreFactory = new SemaphoreFactory({
|
|
33
34
|
* serde,
|
|
34
35
|
* adapter: new MemorySemaphoreAdapter(),
|
|
35
36
|
* });
|
|
36
|
-
* return {
|
|
37
|
+
* return { semaphoreFactory, serde };
|
|
37
38
|
* },
|
|
38
39
|
* beforeEach,
|
|
39
40
|
* describe,
|
|
@@ -44,18 +45,18 @@ import {} from "../../../utilities/_module.js";
|
|
|
44
45
|
* });
|
|
45
46
|
* ```
|
|
46
47
|
*/
|
|
47
|
-
export function
|
|
48
|
-
const { expect, test,
|
|
49
|
-
let
|
|
48
|
+
export function semaphoreFactoryTestSuite(settings) {
|
|
49
|
+
const { expect, test, createSemaphoreFactory, describe, beforeEach, includeEventTests = true, includeSerdeTests = true, retry = 0, delayBuffer = TimeSpan.fromMilliseconds(10), timeSpanEqualityBuffer = TimeSpan.fromMilliseconds(10), } = settings;
|
|
50
|
+
let semaphoreFactory;
|
|
50
51
|
let serde;
|
|
51
52
|
async function delay(time) {
|
|
52
|
-
await Task.delay(time.
|
|
53
|
+
await Task.delay(TimeSpan.fromTimeSpan(time).addTimeSpan(delayBuffer));
|
|
53
54
|
}
|
|
54
55
|
const RETURN_VALUE = "RETURN_VALUE";
|
|
55
|
-
describe("
|
|
56
|
+
describe("ISemaphoreFactory tests:", () => {
|
|
56
57
|
beforeEach(async () => {
|
|
57
|
-
const {
|
|
58
|
-
|
|
58
|
+
const { semaphoreFactory: semaphoreFactory_, serde: serde_ } = await createSemaphoreFactory();
|
|
59
|
+
semaphoreFactory = semaphoreFactory_;
|
|
59
60
|
serde = serde_;
|
|
60
61
|
});
|
|
61
62
|
describe("Api tests:", () => {
|
|
@@ -64,7 +65,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
64
65
|
const key = "a";
|
|
65
66
|
const ttl = null;
|
|
66
67
|
const limit = 1;
|
|
67
|
-
const semaphore =
|
|
68
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
68
69
|
ttl,
|
|
69
70
|
limit,
|
|
70
71
|
});
|
|
@@ -78,7 +79,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
78
79
|
const key = "a";
|
|
79
80
|
const ttl = null;
|
|
80
81
|
const limit = 1;
|
|
81
|
-
const semaphore =
|
|
82
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
82
83
|
ttl,
|
|
83
84
|
limit,
|
|
84
85
|
});
|
|
@@ -93,7 +94,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
93
94
|
const key = "a";
|
|
94
95
|
const ttl = null;
|
|
95
96
|
const limit = 1;
|
|
96
|
-
const semaphore =
|
|
97
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
97
98
|
ttl,
|
|
98
99
|
limit,
|
|
99
100
|
});
|
|
@@ -107,7 +108,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
107
108
|
const key = "a";
|
|
108
109
|
const ttl = null;
|
|
109
110
|
const limit = 1;
|
|
110
|
-
const semaphore =
|
|
111
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
111
112
|
ttl,
|
|
112
113
|
limit,
|
|
113
114
|
});
|
|
@@ -122,7 +123,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
122
123
|
const key = "a";
|
|
123
124
|
const ttl = null;
|
|
124
125
|
const limit = 1;
|
|
125
|
-
const semaphore =
|
|
126
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
126
127
|
ttl,
|
|
127
128
|
limit,
|
|
128
129
|
});
|
|
@@ -141,7 +142,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
141
142
|
const key = "a";
|
|
142
143
|
const ttl = null;
|
|
143
144
|
const limit = 1;
|
|
144
|
-
const semaphore =
|
|
145
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
145
146
|
ttl,
|
|
146
147
|
limit,
|
|
147
148
|
});
|
|
@@ -159,7 +160,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
159
160
|
const handlerFn = vi.fn(() => {
|
|
160
161
|
return Promise.resolve(RETURN_VALUE);
|
|
161
162
|
});
|
|
162
|
-
await
|
|
163
|
+
await semaphoreFactory
|
|
163
164
|
.create(key, {
|
|
164
165
|
ttl,
|
|
165
166
|
limit,
|
|
@@ -171,7 +172,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
171
172
|
const key = "a";
|
|
172
173
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
173
174
|
const limit = 1;
|
|
174
|
-
await
|
|
175
|
+
await semaphoreFactory
|
|
175
176
|
.create(key, {
|
|
176
177
|
ttl,
|
|
177
178
|
limit,
|
|
@@ -181,7 +182,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
181
182
|
const handlerFn = vi.fn(() => {
|
|
182
183
|
return Promise.resolve(RETURN_VALUE);
|
|
183
184
|
});
|
|
184
|
-
await
|
|
185
|
+
await semaphoreFactory
|
|
185
186
|
.create(key, {
|
|
186
187
|
ttl,
|
|
187
188
|
limit,
|
|
@@ -193,7 +194,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
193
194
|
const key = "a";
|
|
194
195
|
const ttl = null;
|
|
195
196
|
const limit = 1;
|
|
196
|
-
const semaphore =
|
|
197
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
197
198
|
ttl,
|
|
198
199
|
limit,
|
|
199
200
|
});
|
|
@@ -213,7 +214,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
213
214
|
const key = "a";
|
|
214
215
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
215
216
|
const limit = 1;
|
|
216
|
-
const semaphore =
|
|
217
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
217
218
|
ttl,
|
|
218
219
|
limit,
|
|
219
220
|
});
|
|
@@ -233,7 +234,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
233
234
|
const key = "a";
|
|
234
235
|
const ttl = null;
|
|
235
236
|
const limit = 1;
|
|
236
|
-
await
|
|
237
|
+
await semaphoreFactory
|
|
237
238
|
.create(key, {
|
|
238
239
|
ttl,
|
|
239
240
|
limit,
|
|
@@ -243,7 +244,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
243
244
|
return Promise.resolve(RETURN_VALUE);
|
|
244
245
|
});
|
|
245
246
|
try {
|
|
246
|
-
await
|
|
247
|
+
await semaphoreFactory
|
|
247
248
|
.create(key, {
|
|
248
249
|
ttl,
|
|
249
250
|
limit,
|
|
@@ -259,7 +260,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
259
260
|
const key = "a";
|
|
260
261
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
261
262
|
const limit = 1;
|
|
262
|
-
await
|
|
263
|
+
await semaphoreFactory
|
|
263
264
|
.create(key, {
|
|
264
265
|
ttl,
|
|
265
266
|
limit,
|
|
@@ -269,7 +270,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
269
270
|
return Promise.resolve(RETURN_VALUE);
|
|
270
271
|
});
|
|
271
272
|
try {
|
|
272
|
-
await
|
|
273
|
+
await semaphoreFactory
|
|
273
274
|
.create(key, {
|
|
274
275
|
ttl,
|
|
275
276
|
limit,
|
|
@@ -285,7 +286,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
285
286
|
const key = "a";
|
|
286
287
|
const ttl = null;
|
|
287
288
|
const limit = 1;
|
|
288
|
-
const result = await
|
|
289
|
+
const result = await semaphoreFactory
|
|
289
290
|
.create(key, {
|
|
290
291
|
ttl,
|
|
291
292
|
limit,
|
|
@@ -299,14 +300,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
299
300
|
const key = "a";
|
|
300
301
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
301
302
|
const limit = 1;
|
|
302
|
-
await
|
|
303
|
+
await semaphoreFactory
|
|
303
304
|
.create(key, {
|
|
304
305
|
ttl,
|
|
305
306
|
limit,
|
|
306
307
|
})
|
|
307
308
|
.acquire();
|
|
308
309
|
await delay(ttl);
|
|
309
|
-
const result = await
|
|
310
|
+
const result = await semaphoreFactory
|
|
310
311
|
.create(key, {
|
|
311
312
|
ttl,
|
|
312
313
|
limit,
|
|
@@ -320,12 +321,12 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
320
321
|
const key = "a";
|
|
321
322
|
const ttl = null;
|
|
322
323
|
const limit = 1;
|
|
323
|
-
const
|
|
324
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
324
325
|
ttl,
|
|
325
326
|
limit,
|
|
326
327
|
});
|
|
327
|
-
await
|
|
328
|
-
const result =
|
|
328
|
+
await semaphore.acquire();
|
|
329
|
+
const result = semaphore.runOrFail(() => {
|
|
329
330
|
return Promise.resolve(RETURN_VALUE);
|
|
330
331
|
});
|
|
331
332
|
await expect(result).rejects.toBeInstanceOf(LimitReachedSemaphoreError);
|
|
@@ -334,12 +335,12 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
334
335
|
const key = "a";
|
|
335
336
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
336
337
|
const limit = 1;
|
|
337
|
-
const
|
|
338
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
338
339
|
ttl,
|
|
339
340
|
limit,
|
|
340
341
|
});
|
|
341
|
-
await
|
|
342
|
-
const result =
|
|
342
|
+
await semaphore.acquire();
|
|
343
|
+
const result = semaphore.runOrFail(() => {
|
|
343
344
|
return Promise.resolve(RETURN_VALUE);
|
|
344
345
|
});
|
|
345
346
|
await expect(result).rejects.toBeInstanceOf(LimitReachedSemaphoreError);
|
|
@@ -348,13 +349,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
348
349
|
const key = "a";
|
|
349
350
|
const ttl = null;
|
|
350
351
|
const limit = 1;
|
|
351
|
-
await
|
|
352
|
+
await semaphoreFactory
|
|
352
353
|
.create(key, {
|
|
353
354
|
ttl,
|
|
354
355
|
limit,
|
|
355
356
|
})
|
|
356
357
|
.acquire();
|
|
357
|
-
const result =
|
|
358
|
+
const result = semaphoreFactory
|
|
358
359
|
.create(key, {
|
|
359
360
|
ttl,
|
|
360
361
|
limit,
|
|
@@ -368,13 +369,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
368
369
|
const key = "a";
|
|
369
370
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
370
371
|
const limit = 1;
|
|
371
|
-
await
|
|
372
|
+
await semaphoreFactory
|
|
372
373
|
.create(key, {
|
|
373
374
|
ttl,
|
|
374
375
|
limit,
|
|
375
376
|
})
|
|
376
377
|
.acquire();
|
|
377
|
-
const result =
|
|
378
|
+
const result = semaphoreFactory
|
|
378
379
|
.create(key, {
|
|
379
380
|
ttl,
|
|
380
381
|
limit,
|
|
@@ -390,7 +391,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
390
391
|
const key = "a";
|
|
391
392
|
const ttl = null;
|
|
392
393
|
const limit = 1;
|
|
393
|
-
const semaphore =
|
|
394
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
394
395
|
ttl,
|
|
395
396
|
limit,
|
|
396
397
|
});
|
|
@@ -407,7 +408,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
407
408
|
const key = "a";
|
|
408
409
|
const ttl = null;
|
|
409
410
|
const limit = 1;
|
|
410
|
-
const semaphore =
|
|
411
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
411
412
|
ttl,
|
|
412
413
|
limit,
|
|
413
414
|
});
|
|
@@ -425,7 +426,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
425
426
|
const key = "a";
|
|
426
427
|
const ttl = null;
|
|
427
428
|
const limit = 1;
|
|
428
|
-
const semaphore =
|
|
429
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
429
430
|
ttl,
|
|
430
431
|
limit,
|
|
431
432
|
});
|
|
@@ -442,7 +443,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
442
443
|
const key = "a";
|
|
443
444
|
const ttl = null;
|
|
444
445
|
const limit = 1;
|
|
445
|
-
const semaphore =
|
|
446
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
446
447
|
ttl,
|
|
447
448
|
limit,
|
|
448
449
|
});
|
|
@@ -460,7 +461,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
460
461
|
const key = "a";
|
|
461
462
|
const ttl = null;
|
|
462
463
|
const limit = 1;
|
|
463
|
-
const semaphore =
|
|
464
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
464
465
|
ttl,
|
|
465
466
|
limit,
|
|
466
467
|
});
|
|
@@ -482,7 +483,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
482
483
|
const key = "a";
|
|
483
484
|
const ttl = null;
|
|
484
485
|
const limit = 1;
|
|
485
|
-
const semaphore =
|
|
486
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
486
487
|
ttl,
|
|
487
488
|
limit,
|
|
488
489
|
});
|
|
@@ -503,7 +504,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
503
504
|
const handlerFn = vi.fn(() => {
|
|
504
505
|
return Promise.resolve(RETURN_VALUE);
|
|
505
506
|
});
|
|
506
|
-
await
|
|
507
|
+
await semaphoreFactory
|
|
507
508
|
.create(key, {
|
|
508
509
|
ttl,
|
|
509
510
|
limit,
|
|
@@ -518,7 +519,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
518
519
|
const key = "a";
|
|
519
520
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
520
521
|
const limit = 1;
|
|
521
|
-
await
|
|
522
|
+
await semaphoreFactory
|
|
522
523
|
.create(key, {
|
|
523
524
|
ttl,
|
|
524
525
|
limit,
|
|
@@ -528,7 +529,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
528
529
|
const handlerFn = vi.fn(() => {
|
|
529
530
|
return Promise.resolve(RETURN_VALUE);
|
|
530
531
|
});
|
|
531
|
-
await
|
|
532
|
+
await semaphoreFactory
|
|
532
533
|
.create(key, {
|
|
533
534
|
ttl,
|
|
534
535
|
limit,
|
|
@@ -543,7 +544,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
543
544
|
const key = "a";
|
|
544
545
|
const ttl = null;
|
|
545
546
|
const limit = 1;
|
|
546
|
-
const semaphore =
|
|
547
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
547
548
|
ttl,
|
|
548
549
|
limit,
|
|
549
550
|
});
|
|
@@ -566,7 +567,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
566
567
|
const key = "a";
|
|
567
568
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
568
569
|
const limit = 1;
|
|
569
|
-
const semaphore =
|
|
570
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
570
571
|
ttl,
|
|
571
572
|
limit,
|
|
572
573
|
});
|
|
@@ -589,7 +590,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
589
590
|
const key = "a";
|
|
590
591
|
const ttl = null;
|
|
591
592
|
const limit = 1;
|
|
592
|
-
await
|
|
593
|
+
await semaphoreFactory
|
|
593
594
|
.create(key, {
|
|
594
595
|
ttl,
|
|
595
596
|
limit,
|
|
@@ -599,7 +600,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
599
600
|
return Promise.resolve(RETURN_VALUE);
|
|
600
601
|
});
|
|
601
602
|
try {
|
|
602
|
-
await
|
|
603
|
+
await semaphoreFactory
|
|
603
604
|
.create(key, {
|
|
604
605
|
ttl,
|
|
605
606
|
limit,
|
|
@@ -618,7 +619,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
618
619
|
const key = "a";
|
|
619
620
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
620
621
|
const limit = 1;
|
|
621
|
-
await
|
|
622
|
+
await semaphoreFactory
|
|
622
623
|
.create(key, {
|
|
623
624
|
ttl,
|
|
624
625
|
limit,
|
|
@@ -628,7 +629,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
628
629
|
return Promise.resolve(RETURN_VALUE);
|
|
629
630
|
});
|
|
630
631
|
try {
|
|
631
|
-
await
|
|
632
|
+
await semaphoreFactory
|
|
632
633
|
.create(key, {
|
|
633
634
|
ttl,
|
|
634
635
|
limit,
|
|
@@ -647,7 +648,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
647
648
|
const key = "a";
|
|
648
649
|
const ttl = null;
|
|
649
650
|
const limit = 1;
|
|
650
|
-
const result = await
|
|
651
|
+
const result = await semaphoreFactory
|
|
651
652
|
.create(key, {
|
|
652
653
|
ttl,
|
|
653
654
|
limit,
|
|
@@ -664,14 +665,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
664
665
|
const key = "a";
|
|
665
666
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
666
667
|
const limit = 1;
|
|
667
|
-
await
|
|
668
|
+
await semaphoreFactory
|
|
668
669
|
.create(key, {
|
|
669
670
|
ttl,
|
|
670
671
|
limit,
|
|
671
672
|
})
|
|
672
673
|
.acquire();
|
|
673
674
|
await delay(ttl);
|
|
674
|
-
const result = await
|
|
675
|
+
const result = await semaphoreFactory
|
|
675
676
|
.create(key, {
|
|
676
677
|
ttl,
|
|
677
678
|
limit,
|
|
@@ -688,12 +689,12 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
688
689
|
const key = "a";
|
|
689
690
|
const ttl = null;
|
|
690
691
|
const limit = 1;
|
|
691
|
-
const
|
|
692
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
692
693
|
ttl,
|
|
693
694
|
limit,
|
|
694
695
|
});
|
|
695
|
-
await
|
|
696
|
-
const result =
|
|
696
|
+
await semaphore.acquire();
|
|
697
|
+
const result = semaphore.runBlockingOrFail(() => {
|
|
697
698
|
return Promise.resolve(RETURN_VALUE);
|
|
698
699
|
}, {
|
|
699
700
|
time: TimeSpan.fromMilliseconds(5),
|
|
@@ -705,12 +706,12 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
705
706
|
const key = "a";
|
|
706
707
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
707
708
|
const limit = 1;
|
|
708
|
-
const
|
|
709
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
709
710
|
ttl,
|
|
710
711
|
limit,
|
|
711
712
|
});
|
|
712
|
-
await
|
|
713
|
-
const result =
|
|
713
|
+
await semaphore.acquire();
|
|
714
|
+
const result = semaphore.runBlockingOrFail(() => {
|
|
714
715
|
return Promise.resolve(RETURN_VALUE);
|
|
715
716
|
}, {
|
|
716
717
|
time: TimeSpan.fromMilliseconds(5),
|
|
@@ -722,13 +723,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
722
723
|
const key = "a";
|
|
723
724
|
const ttl = null;
|
|
724
725
|
const limit = 1;
|
|
725
|
-
await
|
|
726
|
+
await semaphoreFactory
|
|
726
727
|
.create(key, {
|
|
727
728
|
ttl,
|
|
728
729
|
limit,
|
|
729
730
|
})
|
|
730
731
|
.acquire();
|
|
731
|
-
const result =
|
|
732
|
+
const result = semaphoreFactory
|
|
732
733
|
.create(key, {
|
|
733
734
|
ttl,
|
|
734
735
|
limit,
|
|
@@ -745,13 +746,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
745
746
|
const key = "a";
|
|
746
747
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
747
748
|
const limit = 1;
|
|
748
|
-
await
|
|
749
|
+
await semaphoreFactory
|
|
749
750
|
.create(key, {
|
|
750
751
|
ttl,
|
|
751
752
|
limit,
|
|
752
753
|
})
|
|
753
754
|
.acquire();
|
|
754
|
-
const result =
|
|
755
|
+
const result = semaphoreFactory
|
|
755
756
|
.create(key, {
|
|
756
757
|
ttl,
|
|
757
758
|
limit,
|
|
@@ -764,25 +765,25 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
764
765
|
});
|
|
765
766
|
await expect(result).rejects.toBeInstanceOf(LimitReachedSemaphoreError);
|
|
766
767
|
});
|
|
767
|
-
test("Should retry acquire the
|
|
768
|
+
test("Should retry acquire the semaphore", { retry }, async () => {
|
|
768
769
|
const key = "a";
|
|
769
770
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
770
771
|
const limit = 1;
|
|
771
|
-
const
|
|
772
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
772
773
|
ttl,
|
|
773
774
|
limit,
|
|
774
775
|
});
|
|
775
|
-
await
|
|
776
|
+
await semaphore1.acquire();
|
|
776
777
|
let index = 0;
|
|
777
|
-
await
|
|
778
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.LIMIT_REACHED, (_event) => {
|
|
778
779
|
index++;
|
|
779
780
|
});
|
|
780
|
-
const
|
|
781
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
781
782
|
ttl,
|
|
782
783
|
limit,
|
|
783
784
|
});
|
|
784
785
|
try {
|
|
785
|
-
await
|
|
786
|
+
await semaphore2.runBlockingOrFail(() => {
|
|
786
787
|
return Promise.resolve(RETURN_VALUE);
|
|
787
788
|
}, {
|
|
788
789
|
time: TimeSpan.fromMilliseconds(55),
|
|
@@ -800,7 +801,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
800
801
|
const key = "a";
|
|
801
802
|
const limit = 2;
|
|
802
803
|
const ttl = null;
|
|
803
|
-
const result = await
|
|
804
|
+
const result = await semaphoreFactory
|
|
804
805
|
.create(key, {
|
|
805
806
|
limit,
|
|
806
807
|
ttl,
|
|
@@ -812,7 +813,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
812
813
|
const key = "a";
|
|
813
814
|
const limit = 2;
|
|
814
815
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
815
|
-
const semaphore =
|
|
816
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
816
817
|
limit,
|
|
817
818
|
ttl,
|
|
818
819
|
});
|
|
@@ -825,12 +826,12 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
825
826
|
const key = "a";
|
|
826
827
|
const limit = 2;
|
|
827
828
|
const ttl = null;
|
|
828
|
-
const semaphore1 =
|
|
829
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
829
830
|
limit,
|
|
830
831
|
ttl,
|
|
831
832
|
});
|
|
832
833
|
await semaphore1.acquire();
|
|
833
|
-
const semaphore2 =
|
|
834
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
834
835
|
limit,
|
|
835
836
|
ttl,
|
|
836
837
|
});
|
|
@@ -841,17 +842,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
841
842
|
const key = "a";
|
|
842
843
|
const limit = 2;
|
|
843
844
|
const ttl = null;
|
|
844
|
-
const semaphore1 =
|
|
845
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
845
846
|
limit,
|
|
846
847
|
ttl,
|
|
847
848
|
});
|
|
848
849
|
await semaphore1.acquire();
|
|
849
|
-
const semaphore2 =
|
|
850
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
850
851
|
limit,
|
|
851
852
|
ttl,
|
|
852
853
|
});
|
|
853
854
|
await semaphore2.acquire();
|
|
854
|
-
const semaphore3 =
|
|
855
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
855
856
|
limit,
|
|
856
857
|
ttl,
|
|
857
858
|
});
|
|
@@ -862,20 +863,20 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
862
863
|
const key = "a";
|
|
863
864
|
const limit = 2;
|
|
864
865
|
const ttl1 = null;
|
|
865
|
-
const semaphore1 =
|
|
866
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
866
867
|
limit,
|
|
867
868
|
ttl: ttl1,
|
|
868
869
|
});
|
|
869
870
|
await semaphore1.acquire();
|
|
870
871
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
871
|
-
const semaphore2 =
|
|
872
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
872
873
|
limit,
|
|
873
874
|
ttl: ttl2,
|
|
874
875
|
});
|
|
875
876
|
await semaphore2.acquire();
|
|
876
877
|
await delay(ttl2);
|
|
877
878
|
const ttl3 = null;
|
|
878
|
-
const semaphore3 =
|
|
879
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
879
880
|
ttl: ttl3,
|
|
880
881
|
limit,
|
|
881
882
|
});
|
|
@@ -886,7 +887,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
886
887
|
const key = "a";
|
|
887
888
|
const limit = 2;
|
|
888
889
|
const ttl = null;
|
|
889
|
-
const semaphore =
|
|
890
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
890
891
|
limit,
|
|
891
892
|
ttl,
|
|
892
893
|
});
|
|
@@ -898,7 +899,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
898
899
|
const key = "a";
|
|
899
900
|
const limit = 2;
|
|
900
901
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
901
|
-
const semaphore =
|
|
902
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
902
903
|
limit,
|
|
903
904
|
ttl,
|
|
904
905
|
});
|
|
@@ -910,13 +911,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
910
911
|
const key = "a";
|
|
911
912
|
const limit = 2;
|
|
912
913
|
const ttl = null;
|
|
913
|
-
const semaphore1 =
|
|
914
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
914
915
|
limit,
|
|
915
916
|
ttl,
|
|
916
917
|
});
|
|
917
918
|
await semaphore1.acquire();
|
|
918
919
|
await semaphore1.acquire();
|
|
919
|
-
const semaphore2 =
|
|
920
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
920
921
|
limit,
|
|
921
922
|
ttl,
|
|
922
923
|
});
|
|
@@ -927,13 +928,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
927
928
|
const key = "a";
|
|
928
929
|
const limit = 2;
|
|
929
930
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
930
|
-
const semaphore1 =
|
|
931
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
931
932
|
limit,
|
|
932
933
|
ttl,
|
|
933
934
|
});
|
|
934
935
|
await semaphore1.acquire();
|
|
935
936
|
await semaphore1.acquire();
|
|
936
|
-
const semaphore2 =
|
|
937
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
937
938
|
ttl,
|
|
938
939
|
limit,
|
|
939
940
|
});
|
|
@@ -944,24 +945,24 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
944
945
|
const key = "a";
|
|
945
946
|
const limit = 2;
|
|
946
947
|
const ttl = null;
|
|
947
|
-
const semaphore1 =
|
|
948
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
948
949
|
limit,
|
|
949
950
|
ttl,
|
|
950
951
|
});
|
|
951
952
|
await semaphore1.acquire();
|
|
952
953
|
const newLimit = 3;
|
|
953
|
-
const semaphore2 =
|
|
954
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
954
955
|
limit: newLimit,
|
|
955
956
|
ttl,
|
|
956
957
|
});
|
|
957
958
|
await semaphore2.acquire();
|
|
958
|
-
const semaphore3 =
|
|
959
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
959
960
|
limit: newLimit,
|
|
960
961
|
ttl,
|
|
961
962
|
});
|
|
962
963
|
const result1 = await semaphore3.acquire();
|
|
963
964
|
expect(result1).toBe(false);
|
|
964
|
-
const state = await semaphore3.getState();
|
|
965
|
+
const state = (await semaphore3.getState());
|
|
965
966
|
expect(state.limit).toBe(limit);
|
|
966
967
|
});
|
|
967
968
|
});
|
|
@@ -970,7 +971,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
970
971
|
const key = "a";
|
|
971
972
|
const limit = 2;
|
|
972
973
|
const ttl = null;
|
|
973
|
-
const result =
|
|
974
|
+
const result = semaphoreFactory
|
|
974
975
|
.create(key, {
|
|
975
976
|
limit,
|
|
976
977
|
ttl,
|
|
@@ -982,7 +983,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
982
983
|
const key = "a";
|
|
983
984
|
const limit = 2;
|
|
984
985
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
985
|
-
const semaphore =
|
|
986
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
986
987
|
limit,
|
|
987
988
|
ttl,
|
|
988
989
|
});
|
|
@@ -995,12 +996,12 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
995
996
|
const key = "a";
|
|
996
997
|
const limit = 2;
|
|
997
998
|
const ttl = null;
|
|
998
|
-
const semaphore1 =
|
|
999
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
999
1000
|
limit,
|
|
1000
1001
|
ttl,
|
|
1001
1002
|
});
|
|
1002
1003
|
await semaphore1.acquire();
|
|
1003
|
-
const semaphore2 =
|
|
1004
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1004
1005
|
limit,
|
|
1005
1006
|
ttl,
|
|
1006
1007
|
});
|
|
@@ -1011,17 +1012,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1011
1012
|
const key = "a";
|
|
1012
1013
|
const limit = 2;
|
|
1013
1014
|
const ttl = null;
|
|
1014
|
-
const semaphore1 =
|
|
1015
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1015
1016
|
limit,
|
|
1016
1017
|
ttl,
|
|
1017
1018
|
});
|
|
1018
1019
|
await semaphore1.acquire();
|
|
1019
|
-
const semaphore2 =
|
|
1020
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1020
1021
|
limit,
|
|
1021
1022
|
ttl,
|
|
1022
1023
|
});
|
|
1023
1024
|
await semaphore2.acquire();
|
|
1024
|
-
const semaphore3 =
|
|
1025
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
1025
1026
|
limit,
|
|
1026
1027
|
ttl,
|
|
1027
1028
|
});
|
|
@@ -1032,20 +1033,20 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1032
1033
|
const key = "a";
|
|
1033
1034
|
const limit = 2;
|
|
1034
1035
|
const ttl1 = null;
|
|
1035
|
-
const semaphore1 =
|
|
1036
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1036
1037
|
limit,
|
|
1037
1038
|
ttl: ttl1,
|
|
1038
1039
|
});
|
|
1039
1040
|
await semaphore1.acquire();
|
|
1040
1041
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
1041
|
-
const semaphore2 =
|
|
1042
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1042
1043
|
limit,
|
|
1043
1044
|
ttl: ttl2,
|
|
1044
1045
|
});
|
|
1045
1046
|
await semaphore2.acquire();
|
|
1046
1047
|
await delay(ttl2);
|
|
1047
1048
|
const ttl3 = null;
|
|
1048
|
-
const semaphore3 =
|
|
1049
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
1049
1050
|
ttl: ttl3,
|
|
1050
1051
|
limit,
|
|
1051
1052
|
});
|
|
@@ -1056,7 +1057,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1056
1057
|
const key = "a";
|
|
1057
1058
|
const limit = 2;
|
|
1058
1059
|
const ttl = null;
|
|
1059
|
-
const semaphore =
|
|
1060
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
1060
1061
|
limit,
|
|
1061
1062
|
ttl,
|
|
1062
1063
|
});
|
|
@@ -1068,7 +1069,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1068
1069
|
const key = "a";
|
|
1069
1070
|
const limit = 2;
|
|
1070
1071
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1071
|
-
const semaphore =
|
|
1072
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
1072
1073
|
limit,
|
|
1073
1074
|
ttl,
|
|
1074
1075
|
});
|
|
@@ -1080,13 +1081,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1080
1081
|
const key = "a";
|
|
1081
1082
|
const limit = 2;
|
|
1082
1083
|
const ttl = null;
|
|
1083
|
-
const semaphore1 =
|
|
1084
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1084
1085
|
limit,
|
|
1085
1086
|
ttl,
|
|
1086
1087
|
});
|
|
1087
1088
|
await semaphore1.acquire();
|
|
1088
1089
|
await semaphore1.acquire();
|
|
1089
|
-
const semaphore2 =
|
|
1090
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1090
1091
|
limit,
|
|
1091
1092
|
ttl,
|
|
1092
1093
|
});
|
|
@@ -1097,13 +1098,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1097
1098
|
const key = "a";
|
|
1098
1099
|
const limit = 2;
|
|
1099
1100
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1100
|
-
const semaphore1 =
|
|
1101
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1101
1102
|
limit,
|
|
1102
1103
|
ttl,
|
|
1103
1104
|
});
|
|
1104
1105
|
await semaphore1.acquire();
|
|
1105
1106
|
await semaphore1.acquire();
|
|
1106
|
-
const semaphore2 =
|
|
1107
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1107
1108
|
ttl,
|
|
1108
1109
|
limit,
|
|
1109
1110
|
});
|
|
@@ -1114,24 +1115,24 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1114
1115
|
const key = "a";
|
|
1115
1116
|
const limit = 2;
|
|
1116
1117
|
const ttl = null;
|
|
1117
|
-
const semaphore1 =
|
|
1118
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1118
1119
|
limit,
|
|
1119
1120
|
ttl,
|
|
1120
1121
|
});
|
|
1121
1122
|
await semaphore1.acquire();
|
|
1122
1123
|
const newLimit = 3;
|
|
1123
|
-
const semaphore2 =
|
|
1124
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1124
1125
|
limit: newLimit,
|
|
1125
1126
|
ttl,
|
|
1126
1127
|
});
|
|
1127
1128
|
await semaphore2.acquire();
|
|
1128
|
-
const semaphore3 =
|
|
1129
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
1129
1130
|
limit: newLimit,
|
|
1130
1131
|
ttl,
|
|
1131
1132
|
});
|
|
1132
1133
|
const result1 = semaphore3.acquireOrFail();
|
|
1133
1134
|
await expect(result1).rejects.toBeInstanceOf(LimitReachedSemaphoreError);
|
|
1134
|
-
const state = await semaphore3.getState();
|
|
1135
|
+
const state = (await semaphore3.getState());
|
|
1135
1136
|
expect(state.limit).toBe(limit);
|
|
1136
1137
|
});
|
|
1137
1138
|
});
|
|
@@ -1140,7 +1141,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1140
1141
|
const key = "a";
|
|
1141
1142
|
const limit = 2;
|
|
1142
1143
|
const ttl = null;
|
|
1143
|
-
const result = await
|
|
1144
|
+
const result = await semaphoreFactory
|
|
1144
1145
|
.create(key, {
|
|
1145
1146
|
limit,
|
|
1146
1147
|
ttl,
|
|
@@ -1155,7 +1156,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1155
1156
|
const key = "a";
|
|
1156
1157
|
const limit = 2;
|
|
1157
1158
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1158
|
-
const semaphore =
|
|
1159
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
1159
1160
|
limit,
|
|
1160
1161
|
ttl,
|
|
1161
1162
|
});
|
|
@@ -1171,12 +1172,12 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1171
1172
|
const key = "a";
|
|
1172
1173
|
const limit = 2;
|
|
1173
1174
|
const ttl = null;
|
|
1174
|
-
const semaphore1 =
|
|
1175
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1175
1176
|
limit,
|
|
1176
1177
|
ttl,
|
|
1177
1178
|
});
|
|
1178
1179
|
await semaphore1.acquire();
|
|
1179
|
-
const semaphore2 =
|
|
1180
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1180
1181
|
limit,
|
|
1181
1182
|
ttl,
|
|
1182
1183
|
});
|
|
@@ -1190,17 +1191,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1190
1191
|
const key = "a";
|
|
1191
1192
|
const limit = 2;
|
|
1192
1193
|
const ttl = null;
|
|
1193
|
-
const semaphore1 =
|
|
1194
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1194
1195
|
limit,
|
|
1195
1196
|
ttl,
|
|
1196
1197
|
});
|
|
1197
1198
|
await semaphore1.acquire();
|
|
1198
|
-
const semaphore2 =
|
|
1199
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1199
1200
|
limit,
|
|
1200
1201
|
ttl,
|
|
1201
1202
|
});
|
|
1202
1203
|
await semaphore2.acquire();
|
|
1203
|
-
const semaphore3 =
|
|
1204
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
1204
1205
|
limit,
|
|
1205
1206
|
ttl,
|
|
1206
1207
|
});
|
|
@@ -1214,20 +1215,20 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1214
1215
|
const key = "a";
|
|
1215
1216
|
const limit = 2;
|
|
1216
1217
|
const ttl1 = null;
|
|
1217
|
-
const semaphore1 =
|
|
1218
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1218
1219
|
limit,
|
|
1219
1220
|
ttl: ttl1,
|
|
1220
1221
|
});
|
|
1221
1222
|
await semaphore1.acquire();
|
|
1222
1223
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
1223
|
-
const semaphore2 =
|
|
1224
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1224
1225
|
limit,
|
|
1225
1226
|
ttl: ttl2,
|
|
1226
1227
|
});
|
|
1227
1228
|
await semaphore2.acquire();
|
|
1228
1229
|
await delay(ttl2);
|
|
1229
1230
|
const ttl3 = null;
|
|
1230
|
-
const semaphore3 =
|
|
1231
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
1231
1232
|
ttl: ttl3,
|
|
1232
1233
|
limit,
|
|
1233
1234
|
});
|
|
@@ -1241,7 +1242,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1241
1242
|
const key = "a";
|
|
1242
1243
|
const limit = 2;
|
|
1243
1244
|
const ttl = null;
|
|
1244
|
-
const semaphore =
|
|
1245
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
1245
1246
|
limit,
|
|
1246
1247
|
ttl,
|
|
1247
1248
|
});
|
|
@@ -1256,7 +1257,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1256
1257
|
const key = "a";
|
|
1257
1258
|
const limit = 2;
|
|
1258
1259
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1259
|
-
const semaphore =
|
|
1260
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
1260
1261
|
limit,
|
|
1261
1262
|
ttl,
|
|
1262
1263
|
});
|
|
@@ -1271,13 +1272,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1271
1272
|
const key = "a";
|
|
1272
1273
|
const limit = 2;
|
|
1273
1274
|
const ttl = null;
|
|
1274
|
-
const semaphore1 =
|
|
1275
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1275
1276
|
limit,
|
|
1276
1277
|
ttl,
|
|
1277
1278
|
});
|
|
1278
1279
|
await semaphore1.acquire();
|
|
1279
1280
|
await semaphore1.acquire();
|
|
1280
|
-
const semaphore2 =
|
|
1281
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1281
1282
|
limit,
|
|
1282
1283
|
ttl,
|
|
1283
1284
|
});
|
|
@@ -1291,13 +1292,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1291
1292
|
const key = "a";
|
|
1292
1293
|
const limit = 2;
|
|
1293
1294
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1294
|
-
const semaphore1 =
|
|
1295
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1295
1296
|
limit,
|
|
1296
1297
|
ttl,
|
|
1297
1298
|
});
|
|
1298
1299
|
await semaphore1.acquire();
|
|
1299
1300
|
await semaphore1.acquire();
|
|
1300
|
-
const semaphore2 =
|
|
1301
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1301
1302
|
ttl,
|
|
1302
1303
|
limit,
|
|
1303
1304
|
});
|
|
@@ -1311,18 +1312,18 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1311
1312
|
const key = "a";
|
|
1312
1313
|
const limit = 2;
|
|
1313
1314
|
const ttl = null;
|
|
1314
|
-
const semaphore1 =
|
|
1315
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1315
1316
|
limit,
|
|
1316
1317
|
ttl,
|
|
1317
1318
|
});
|
|
1318
1319
|
await semaphore1.acquire();
|
|
1319
1320
|
const newLimit = 3;
|
|
1320
|
-
const semaphore2 =
|
|
1321
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1321
1322
|
limit: newLimit,
|
|
1322
1323
|
ttl,
|
|
1323
1324
|
});
|
|
1324
1325
|
await semaphore2.acquire();
|
|
1325
|
-
const semaphore3 =
|
|
1326
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
1326
1327
|
limit: newLimit,
|
|
1327
1328
|
ttl,
|
|
1328
1329
|
});
|
|
@@ -1331,23 +1332,23 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1331
1332
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1332
1333
|
});
|
|
1333
1334
|
expect(result1).toBe(false);
|
|
1334
|
-
const state = await semaphore3.getState();
|
|
1335
|
+
const state = (await semaphore3.getState());
|
|
1335
1336
|
expect(state.limit).toBe(limit);
|
|
1336
1337
|
});
|
|
1337
|
-
test("Should retry acquire the semaphore", async () => {
|
|
1338
|
+
test("Should retry acquire the semaphore", { retry }, async () => {
|
|
1338
1339
|
const key = "a";
|
|
1339
1340
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1340
1341
|
const limit = 1;
|
|
1341
|
-
const semaphore1 =
|
|
1342
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1342
1343
|
ttl,
|
|
1343
1344
|
limit,
|
|
1344
1345
|
});
|
|
1345
1346
|
await semaphore1.acquire();
|
|
1346
1347
|
let index = 0;
|
|
1347
|
-
await
|
|
1348
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.LIMIT_REACHED, (_event) => {
|
|
1348
1349
|
index++;
|
|
1349
1350
|
});
|
|
1350
|
-
const semaphore2 =
|
|
1351
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1351
1352
|
ttl,
|
|
1352
1353
|
limit,
|
|
1353
1354
|
});
|
|
@@ -1363,7 +1364,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1363
1364
|
const key = "a";
|
|
1364
1365
|
const limit = 2;
|
|
1365
1366
|
const ttl = null;
|
|
1366
|
-
const result =
|
|
1367
|
+
const result = semaphoreFactory
|
|
1367
1368
|
.create(key, {
|
|
1368
1369
|
limit,
|
|
1369
1370
|
ttl,
|
|
@@ -1378,7 +1379,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1378
1379
|
const key = "a";
|
|
1379
1380
|
const limit = 2;
|
|
1380
1381
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1381
|
-
const semaphore =
|
|
1382
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
1382
1383
|
limit,
|
|
1383
1384
|
ttl,
|
|
1384
1385
|
});
|
|
@@ -1394,12 +1395,12 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1394
1395
|
const key = "a";
|
|
1395
1396
|
const limit = 2;
|
|
1396
1397
|
const ttl = null;
|
|
1397
|
-
const semaphore1 =
|
|
1398
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1398
1399
|
limit,
|
|
1399
1400
|
ttl,
|
|
1400
1401
|
});
|
|
1401
1402
|
await semaphore1.acquire();
|
|
1402
|
-
const semaphore2 =
|
|
1403
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1403
1404
|
limit,
|
|
1404
1405
|
ttl,
|
|
1405
1406
|
});
|
|
@@ -1413,17 +1414,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1413
1414
|
const key = "a";
|
|
1414
1415
|
const limit = 2;
|
|
1415
1416
|
const ttl = null;
|
|
1416
|
-
const semaphore1 =
|
|
1417
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1417
1418
|
limit,
|
|
1418
1419
|
ttl,
|
|
1419
1420
|
});
|
|
1420
1421
|
await semaphore1.acquire();
|
|
1421
|
-
const semaphore2 =
|
|
1422
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1422
1423
|
limit,
|
|
1423
1424
|
ttl,
|
|
1424
1425
|
});
|
|
1425
1426
|
await semaphore2.acquire();
|
|
1426
|
-
const semaphore3 =
|
|
1427
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
1427
1428
|
limit,
|
|
1428
1429
|
ttl,
|
|
1429
1430
|
});
|
|
@@ -1437,20 +1438,20 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1437
1438
|
const key = "a";
|
|
1438
1439
|
const limit = 2;
|
|
1439
1440
|
const ttl1 = null;
|
|
1440
|
-
const semaphore1 =
|
|
1441
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1441
1442
|
limit,
|
|
1442
1443
|
ttl: ttl1,
|
|
1443
1444
|
});
|
|
1444
1445
|
await semaphore1.acquire();
|
|
1445
1446
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
1446
|
-
const semaphore2 =
|
|
1447
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1447
1448
|
limit,
|
|
1448
1449
|
ttl: ttl2,
|
|
1449
1450
|
});
|
|
1450
1451
|
await semaphore2.acquire();
|
|
1451
1452
|
await delay(ttl2);
|
|
1452
1453
|
const ttl3 = null;
|
|
1453
|
-
const semaphore3 =
|
|
1454
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
1454
1455
|
ttl: ttl3,
|
|
1455
1456
|
limit,
|
|
1456
1457
|
});
|
|
@@ -1464,7 +1465,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1464
1465
|
const key = "a";
|
|
1465
1466
|
const limit = 2;
|
|
1466
1467
|
const ttl = null;
|
|
1467
|
-
const semaphore =
|
|
1468
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
1468
1469
|
limit,
|
|
1469
1470
|
ttl,
|
|
1470
1471
|
});
|
|
@@ -1479,7 +1480,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1479
1480
|
const key = "a";
|
|
1480
1481
|
const limit = 2;
|
|
1481
1482
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1482
|
-
const semaphore =
|
|
1483
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
1483
1484
|
limit,
|
|
1484
1485
|
ttl,
|
|
1485
1486
|
});
|
|
@@ -1494,13 +1495,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1494
1495
|
const key = "a";
|
|
1495
1496
|
const limit = 2;
|
|
1496
1497
|
const ttl = null;
|
|
1497
|
-
const semaphore1 =
|
|
1498
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1498
1499
|
limit,
|
|
1499
1500
|
ttl,
|
|
1500
1501
|
});
|
|
1501
1502
|
await semaphore1.acquire();
|
|
1502
1503
|
await semaphore1.acquire();
|
|
1503
|
-
const semaphore2 =
|
|
1504
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1504
1505
|
limit,
|
|
1505
1506
|
ttl,
|
|
1506
1507
|
});
|
|
@@ -1514,13 +1515,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1514
1515
|
const key = "a";
|
|
1515
1516
|
const limit = 2;
|
|
1516
1517
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1517
|
-
const semaphore1 =
|
|
1518
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1518
1519
|
limit,
|
|
1519
1520
|
ttl,
|
|
1520
1521
|
});
|
|
1521
1522
|
await semaphore1.acquire();
|
|
1522
1523
|
await semaphore1.acquire();
|
|
1523
|
-
const semaphore2 =
|
|
1524
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1524
1525
|
ttl,
|
|
1525
1526
|
limit,
|
|
1526
1527
|
});
|
|
@@ -1534,18 +1535,18 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1534
1535
|
const key = "a";
|
|
1535
1536
|
const limit = 2;
|
|
1536
1537
|
const ttl = null;
|
|
1537
|
-
const semaphore1 =
|
|
1538
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1538
1539
|
limit,
|
|
1539
1540
|
ttl,
|
|
1540
1541
|
});
|
|
1541
1542
|
await semaphore1.acquire();
|
|
1542
1543
|
const newLimit = 3;
|
|
1543
|
-
const semaphore2 =
|
|
1544
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1544
1545
|
limit: newLimit,
|
|
1545
1546
|
ttl,
|
|
1546
1547
|
});
|
|
1547
1548
|
await semaphore2.acquire();
|
|
1548
|
-
const semaphore3 =
|
|
1549
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
1549
1550
|
limit: newLimit,
|
|
1550
1551
|
ttl,
|
|
1551
1552
|
});
|
|
@@ -1554,23 +1555,23 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1554
1555
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1555
1556
|
});
|
|
1556
1557
|
await expect(result1).rejects.toBeInstanceOf(LimitReachedSemaphoreError);
|
|
1557
|
-
const state = await semaphore3.getState();
|
|
1558
|
+
const state = (await semaphore3.getState());
|
|
1558
1559
|
expect(state.limit).toBe(limit);
|
|
1559
1560
|
});
|
|
1560
|
-
test("Should retry acquire the semaphore", async () => {
|
|
1561
|
+
test("Should retry acquire the semaphore", { retry }, async () => {
|
|
1561
1562
|
const key = "a";
|
|
1562
1563
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1563
1564
|
const limit = 1;
|
|
1564
|
-
const semaphore1 =
|
|
1565
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1565
1566
|
ttl,
|
|
1566
1567
|
limit,
|
|
1567
1568
|
});
|
|
1568
1569
|
await semaphore1.acquire();
|
|
1569
1570
|
let index = 0;
|
|
1570
|
-
await
|
|
1571
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.LIMIT_REACHED, (_event) => {
|
|
1571
1572
|
index++;
|
|
1572
1573
|
});
|
|
1573
|
-
const semaphore2 =
|
|
1574
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1574
1575
|
ttl,
|
|
1575
1576
|
limit,
|
|
1576
1577
|
});
|
|
@@ -1591,14 +1592,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1591
1592
|
const key = "a";
|
|
1592
1593
|
const limit = 2;
|
|
1593
1594
|
const ttl = null;
|
|
1594
|
-
await
|
|
1595
|
+
await semaphoreFactory
|
|
1595
1596
|
.create(key, {
|
|
1596
1597
|
limit,
|
|
1597
1598
|
ttl,
|
|
1598
1599
|
})
|
|
1599
1600
|
.acquire();
|
|
1600
1601
|
const noneExistingKey = "c";
|
|
1601
|
-
const result = await
|
|
1602
|
+
const result = await semaphoreFactory
|
|
1602
1603
|
.create(noneExistingKey, {
|
|
1603
1604
|
limit,
|
|
1604
1605
|
ttl,
|
|
@@ -1610,14 +1611,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1610
1611
|
const key = "a";
|
|
1611
1612
|
const limit = 2;
|
|
1612
1613
|
const ttl = null;
|
|
1613
|
-
await
|
|
1614
|
+
await semaphoreFactory
|
|
1614
1615
|
.create(key, {
|
|
1615
1616
|
limit,
|
|
1616
1617
|
ttl,
|
|
1617
1618
|
})
|
|
1618
1619
|
.acquire();
|
|
1619
1620
|
const noneExistingSlotId = "1";
|
|
1620
|
-
const result = await
|
|
1621
|
+
const result = await semaphoreFactory
|
|
1621
1622
|
.create(key, {
|
|
1622
1623
|
limit,
|
|
1623
1624
|
ttl,
|
|
@@ -1630,25 +1631,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1630
1631
|
const key = "a";
|
|
1631
1632
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1632
1633
|
const limit = 2;
|
|
1633
|
-
const
|
|
1634
|
-
ttl,
|
|
1635
|
-
limit,
|
|
1636
|
-
});
|
|
1637
|
-
await semaphore1.acquire();
|
|
1638
|
-
await delay(ttl);
|
|
1639
|
-
const result = await semaphoreProvider
|
|
1640
|
-
.create(key, {
|
|
1641
|
-
ttl,
|
|
1642
|
-
limit,
|
|
1643
|
-
})
|
|
1644
|
-
.release();
|
|
1645
|
-
expect(result).toBe(false);
|
|
1646
|
-
});
|
|
1647
|
-
test("Should return false when slot exists, is expired", async () => {
|
|
1648
|
-
const key = "a";
|
|
1649
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1650
|
-
const limit = 2;
|
|
1651
|
-
const semaphore = semaphoreProvider.create(key, {
|
|
1634
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
1652
1635
|
ttl,
|
|
1653
1636
|
limit,
|
|
1654
1637
|
});
|
|
@@ -1657,11 +1640,11 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1657
1640
|
const result = await semaphore.release();
|
|
1658
1641
|
expect(result).toBe(false);
|
|
1659
1642
|
});
|
|
1660
|
-
test("Should return true when slot exists
|
|
1643
|
+
test("Should return true when slot exists and is unexpired", async () => {
|
|
1661
1644
|
const key = "a";
|
|
1662
1645
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1663
1646
|
const limit = 2;
|
|
1664
|
-
const semaphore =
|
|
1647
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
1665
1648
|
ttl,
|
|
1666
1649
|
limit,
|
|
1667
1650
|
});
|
|
@@ -1669,11 +1652,11 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1669
1652
|
const result = await semaphore.release();
|
|
1670
1653
|
expect(result).toBe(true);
|
|
1671
1654
|
});
|
|
1672
|
-
test("Should return true when slot exists
|
|
1655
|
+
test("Should return true when slot exists and is unexpireable", async () => {
|
|
1673
1656
|
const key = "a";
|
|
1674
1657
|
const ttl = null;
|
|
1675
1658
|
const limit = 2;
|
|
1676
|
-
const semaphore =
|
|
1659
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
1677
1660
|
ttl,
|
|
1678
1661
|
limit,
|
|
1679
1662
|
});
|
|
@@ -1685,12 +1668,12 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1685
1668
|
const key = "a";
|
|
1686
1669
|
const limit = 2;
|
|
1687
1670
|
const ttl = null;
|
|
1688
|
-
const semaphore1 =
|
|
1671
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1689
1672
|
ttl,
|
|
1690
1673
|
limit,
|
|
1691
1674
|
});
|
|
1692
1675
|
await semaphore1.acquire();
|
|
1693
|
-
const semaphore2 =
|
|
1676
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1694
1677
|
ttl,
|
|
1695
1678
|
limit,
|
|
1696
1679
|
});
|
|
@@ -1698,25 +1681,25 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1698
1681
|
await semaphore1.release();
|
|
1699
1682
|
await semaphore2.release();
|
|
1700
1683
|
const newLimit = 3;
|
|
1701
|
-
const semaphore3 =
|
|
1684
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
1702
1685
|
ttl,
|
|
1703
1686
|
limit: newLimit,
|
|
1704
1687
|
});
|
|
1705
1688
|
await semaphore3.acquire();
|
|
1706
|
-
const semaphore4 =
|
|
1689
|
+
const semaphore4 = semaphoreFactory.create(key, {
|
|
1707
1690
|
ttl,
|
|
1708
1691
|
limit: newLimit,
|
|
1709
1692
|
});
|
|
1710
1693
|
await semaphore4.acquire();
|
|
1711
|
-
const semaphore5 =
|
|
1694
|
+
const semaphore5 = semaphoreFactory.create(key, {
|
|
1712
1695
|
ttl,
|
|
1713
1696
|
limit: newLimit,
|
|
1714
1697
|
});
|
|
1715
1698
|
const result1 = await semaphore5.acquire();
|
|
1716
1699
|
expect(result1).toBe(true);
|
|
1717
|
-
const state = await semaphore5.getState();
|
|
1700
|
+
const state = (await semaphore5.getState());
|
|
1718
1701
|
expect(state.limit).toBe(newLimit);
|
|
1719
|
-
const semaphore6 =
|
|
1702
|
+
const semaphore6 = semaphoreFactory.create(key, {
|
|
1720
1703
|
ttl,
|
|
1721
1704
|
limit: newLimit,
|
|
1722
1705
|
});
|
|
@@ -1727,25 +1710,25 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1727
1710
|
const key = "a";
|
|
1728
1711
|
const limit = 2;
|
|
1729
1712
|
const ttl = null;
|
|
1730
|
-
const semaphore1 =
|
|
1713
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1731
1714
|
ttl,
|
|
1732
1715
|
limit,
|
|
1733
1716
|
});
|
|
1734
1717
|
await semaphore1.acquire();
|
|
1735
|
-
const semaphore2 =
|
|
1718
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1736
1719
|
ttl,
|
|
1737
1720
|
limit,
|
|
1738
1721
|
});
|
|
1739
1722
|
await semaphore2.acquire();
|
|
1740
1723
|
await semaphore1.release();
|
|
1741
1724
|
await semaphore2.release();
|
|
1742
|
-
const semaphore3 =
|
|
1725
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
1743
1726
|
ttl,
|
|
1744
1727
|
limit,
|
|
1745
1728
|
});
|
|
1746
1729
|
const result1 = await semaphore3.acquire();
|
|
1747
1730
|
expect(result1).toBe(true);
|
|
1748
|
-
const semaphore4 =
|
|
1731
|
+
const semaphore4 = semaphoreFactory.create(key, {
|
|
1749
1732
|
ttl,
|
|
1750
1733
|
limit,
|
|
1751
1734
|
});
|
|
@@ -1758,14 +1741,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1758
1741
|
const key = "a";
|
|
1759
1742
|
const limit = 2;
|
|
1760
1743
|
const ttl = null;
|
|
1761
|
-
await
|
|
1744
|
+
await semaphoreFactory
|
|
1762
1745
|
.create(key, {
|
|
1763
1746
|
limit,
|
|
1764
1747
|
ttl,
|
|
1765
1748
|
})
|
|
1766
1749
|
.acquire();
|
|
1767
1750
|
const noneExistingKey = "c";
|
|
1768
|
-
const result =
|
|
1751
|
+
const result = semaphoreFactory
|
|
1769
1752
|
.create(noneExistingKey, {
|
|
1770
1753
|
limit,
|
|
1771
1754
|
ttl,
|
|
@@ -1777,14 +1760,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1777
1760
|
const key = "a";
|
|
1778
1761
|
const limit = 2;
|
|
1779
1762
|
const ttl = null;
|
|
1780
|
-
await
|
|
1763
|
+
await semaphoreFactory
|
|
1781
1764
|
.create(key, {
|
|
1782
1765
|
limit,
|
|
1783
1766
|
ttl,
|
|
1784
1767
|
})
|
|
1785
1768
|
.acquire();
|
|
1786
1769
|
const noneExistingSlotId = "1";
|
|
1787
|
-
const result =
|
|
1770
|
+
const result = semaphoreFactory
|
|
1788
1771
|
.create(key, {
|
|
1789
1772
|
limit,
|
|
1790
1773
|
ttl,
|
|
@@ -1797,13 +1780,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1797
1780
|
const key = "a";
|
|
1798
1781
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1799
1782
|
const limit = 2;
|
|
1800
|
-
const semaphore1 =
|
|
1783
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1801
1784
|
ttl,
|
|
1802
1785
|
limit,
|
|
1803
1786
|
});
|
|
1804
1787
|
await semaphore1.acquire();
|
|
1805
1788
|
await delay(ttl);
|
|
1806
|
-
const result =
|
|
1789
|
+
const result = semaphoreFactory
|
|
1807
1790
|
.create(key, {
|
|
1808
1791
|
ttl,
|
|
1809
1792
|
limit,
|
|
@@ -1815,7 +1798,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1815
1798
|
const key = "a";
|
|
1816
1799
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1817
1800
|
const limit = 2;
|
|
1818
|
-
const semaphore =
|
|
1801
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
1819
1802
|
ttl,
|
|
1820
1803
|
limit,
|
|
1821
1804
|
});
|
|
@@ -1824,11 +1807,11 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1824
1807
|
const result = semaphore.releaseOrFail();
|
|
1825
1808
|
await expect(result).rejects.toBeInstanceOf(FailedReleaseSemaphoreError);
|
|
1826
1809
|
});
|
|
1827
|
-
test("Should not throw error when slot exists
|
|
1810
|
+
test("Should not throw error when slot exists and is unexpired", async () => {
|
|
1828
1811
|
const key = "a";
|
|
1829
1812
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1830
1813
|
const limit = 2;
|
|
1831
|
-
const semaphore =
|
|
1814
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
1832
1815
|
ttl,
|
|
1833
1816
|
limit,
|
|
1834
1817
|
});
|
|
@@ -1836,11 +1819,11 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1836
1819
|
const result = semaphore.releaseOrFail();
|
|
1837
1820
|
await expect(result).resolves.toBeUndefined();
|
|
1838
1821
|
});
|
|
1839
|
-
test("Should not throw error when slot exists
|
|
1822
|
+
test("Should not throw error when slot exists and is unexpireable", async () => {
|
|
1840
1823
|
const key = "a";
|
|
1841
1824
|
const ttl = null;
|
|
1842
1825
|
const limit = 2;
|
|
1843
|
-
const semaphore =
|
|
1826
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
1844
1827
|
ttl,
|
|
1845
1828
|
limit,
|
|
1846
1829
|
});
|
|
@@ -1852,12 +1835,12 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1852
1835
|
const key = "a";
|
|
1853
1836
|
const limit = 2;
|
|
1854
1837
|
const ttl = null;
|
|
1855
|
-
const semaphore1 =
|
|
1838
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1856
1839
|
ttl,
|
|
1857
1840
|
limit,
|
|
1858
1841
|
});
|
|
1859
1842
|
await semaphore1.acquire();
|
|
1860
|
-
const semaphore2 =
|
|
1843
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1861
1844
|
ttl,
|
|
1862
1845
|
limit,
|
|
1863
1846
|
});
|
|
@@ -1865,25 +1848,25 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1865
1848
|
await semaphore1.release();
|
|
1866
1849
|
await semaphore2.releaseOrFail();
|
|
1867
1850
|
const newLimit = 3;
|
|
1868
|
-
const semaphore3 =
|
|
1851
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
1869
1852
|
ttl,
|
|
1870
1853
|
limit: newLimit,
|
|
1871
1854
|
});
|
|
1872
1855
|
await semaphore3.acquire();
|
|
1873
|
-
const semaphore4 =
|
|
1856
|
+
const semaphore4 = semaphoreFactory.create(key, {
|
|
1874
1857
|
ttl,
|
|
1875
1858
|
limit: newLimit,
|
|
1876
1859
|
});
|
|
1877
1860
|
await semaphore4.acquire();
|
|
1878
|
-
const semaphore5 =
|
|
1861
|
+
const semaphore5 = semaphoreFactory.create(key, {
|
|
1879
1862
|
ttl,
|
|
1880
1863
|
limit: newLimit,
|
|
1881
1864
|
});
|
|
1882
1865
|
const result1 = await semaphore5.acquire();
|
|
1883
1866
|
expect(result1).toBe(true);
|
|
1884
|
-
const state = await semaphore5.getState();
|
|
1867
|
+
const state = (await semaphore5.getState());
|
|
1885
1868
|
expect(state.limit).toBe(newLimit);
|
|
1886
|
-
const semaphore6 =
|
|
1869
|
+
const semaphore6 = semaphoreFactory.create(key, {
|
|
1887
1870
|
ttl,
|
|
1888
1871
|
limit: newLimit,
|
|
1889
1872
|
});
|
|
@@ -1894,25 +1877,25 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1894
1877
|
const key = "a";
|
|
1895
1878
|
const limit = 2;
|
|
1896
1879
|
const ttl = null;
|
|
1897
|
-
const semaphore1 =
|
|
1880
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1898
1881
|
ttl,
|
|
1899
1882
|
limit,
|
|
1900
1883
|
});
|
|
1901
1884
|
await semaphore1.acquire();
|
|
1902
|
-
const semaphore2 =
|
|
1885
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1903
1886
|
ttl,
|
|
1904
1887
|
limit,
|
|
1905
1888
|
});
|
|
1906
1889
|
await semaphore2.acquire();
|
|
1907
1890
|
await semaphore1.release();
|
|
1908
1891
|
await semaphore2.releaseOrFail();
|
|
1909
|
-
const semaphore3 =
|
|
1892
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
1910
1893
|
ttl,
|
|
1911
1894
|
limit,
|
|
1912
1895
|
});
|
|
1913
1896
|
const result1 = await semaphore3.acquire();
|
|
1914
1897
|
expect(result1).toBe(true);
|
|
1915
|
-
const semaphore4 =
|
|
1898
|
+
const semaphore4 = semaphoreFactory.create(key, {
|
|
1916
1899
|
ttl,
|
|
1917
1900
|
limit,
|
|
1918
1901
|
});
|
|
@@ -1925,13 +1908,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1925
1908
|
const key = "a";
|
|
1926
1909
|
const limit = 2;
|
|
1927
1910
|
const ttl = null;
|
|
1928
|
-
const semaphore1 =
|
|
1911
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1929
1912
|
limit,
|
|
1930
1913
|
ttl,
|
|
1931
1914
|
});
|
|
1932
1915
|
await semaphore1.acquire();
|
|
1933
1916
|
const noneExistingKey = "c";
|
|
1934
|
-
const semaphore2 =
|
|
1917
|
+
const semaphore2 = semaphoreFactory.create(noneExistingKey, {
|
|
1935
1918
|
limit,
|
|
1936
1919
|
ttl,
|
|
1937
1920
|
});
|
|
@@ -1942,7 +1925,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1942
1925
|
const key = "a";
|
|
1943
1926
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1944
1927
|
const limit = 2;
|
|
1945
|
-
const semaphore =
|
|
1928
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
1946
1929
|
limit,
|
|
1947
1930
|
ttl,
|
|
1948
1931
|
});
|
|
@@ -1955,12 +1938,12 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1955
1938
|
const key = "a";
|
|
1956
1939
|
const ttl = null;
|
|
1957
1940
|
const limit = 2;
|
|
1958
|
-
const semaphore1 =
|
|
1941
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1959
1942
|
limit,
|
|
1960
1943
|
ttl,
|
|
1961
1944
|
});
|
|
1962
1945
|
await semaphore1.acquire();
|
|
1963
|
-
const semaphore2 =
|
|
1946
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1964
1947
|
limit,
|
|
1965
1948
|
ttl,
|
|
1966
1949
|
});
|
|
@@ -1974,7 +1957,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1974
1957
|
const key = "a";
|
|
1975
1958
|
const ttl = null;
|
|
1976
1959
|
const limit = 2;
|
|
1977
|
-
const semaphore =
|
|
1960
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
1978
1961
|
limit,
|
|
1979
1962
|
ttl,
|
|
1980
1963
|
});
|
|
@@ -1986,27 +1969,27 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
1986
1969
|
const key = "a";
|
|
1987
1970
|
const limit = 2;
|
|
1988
1971
|
const ttl1 = null;
|
|
1989
|
-
const semaphore1 =
|
|
1972
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
1990
1973
|
limit,
|
|
1991
1974
|
ttl: ttl1,
|
|
1992
1975
|
});
|
|
1993
1976
|
await semaphore1.acquire();
|
|
1994
1977
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
1995
|
-
const semaphore2 =
|
|
1978
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
1996
1979
|
limit,
|
|
1997
1980
|
ttl: ttl2,
|
|
1998
1981
|
});
|
|
1999
1982
|
await semaphore2.acquire();
|
|
2000
1983
|
await semaphore2.forceReleaseAll();
|
|
2001
1984
|
const ttl3 = null;
|
|
2002
|
-
const semaphore3 =
|
|
1985
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
2003
1986
|
ttl: ttl3,
|
|
2004
1987
|
limit,
|
|
2005
1988
|
});
|
|
2006
1989
|
const result1 = await semaphore3.acquire();
|
|
2007
1990
|
expect(result1).toBe(true);
|
|
2008
1991
|
const ttl4 = null;
|
|
2009
|
-
const semaphore4 =
|
|
1992
|
+
const semaphore4 = semaphoreFactory.create(key, {
|
|
2010
1993
|
ttl: ttl4,
|
|
2011
1994
|
limit,
|
|
2012
1995
|
});
|
|
@@ -2017,37 +2000,37 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2017
2000
|
const key = "a";
|
|
2018
2001
|
const limit = 2;
|
|
2019
2002
|
const ttl = null;
|
|
2020
|
-
const semaphore1 =
|
|
2003
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2021
2004
|
ttl,
|
|
2022
2005
|
limit,
|
|
2023
2006
|
});
|
|
2024
2007
|
await semaphore1.acquire();
|
|
2025
|
-
const semaphore2 =
|
|
2008
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2026
2009
|
ttl,
|
|
2027
2010
|
limit,
|
|
2028
2011
|
});
|
|
2029
2012
|
await semaphore2.acquire();
|
|
2030
2013
|
await semaphore1.forceReleaseAll();
|
|
2031
2014
|
const newLimit = 3;
|
|
2032
|
-
const semaphore3 =
|
|
2015
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
2033
2016
|
ttl,
|
|
2034
2017
|
limit: newLimit,
|
|
2035
2018
|
});
|
|
2036
2019
|
await semaphore3.acquire();
|
|
2037
|
-
const semaphore4 =
|
|
2020
|
+
const semaphore4 = semaphoreFactory.create(key, {
|
|
2038
2021
|
ttl,
|
|
2039
2022
|
limit: newLimit,
|
|
2040
2023
|
});
|
|
2041
2024
|
await semaphore4.acquire();
|
|
2042
|
-
const semaphore5 =
|
|
2025
|
+
const semaphore5 = semaphoreFactory.create(key, {
|
|
2043
2026
|
ttl,
|
|
2044
2027
|
limit: newLimit,
|
|
2045
2028
|
});
|
|
2046
2029
|
const result1 = await semaphore5.acquire();
|
|
2047
2030
|
expect(result1).toBe(true);
|
|
2048
|
-
const state = await semaphore5.getState();
|
|
2031
|
+
const state = (await semaphore5.getState());
|
|
2049
2032
|
expect(state.limit).toBe(newLimit);
|
|
2050
|
-
const semaphore6 =
|
|
2033
|
+
const semaphore6 = semaphoreFactory.create(key, {
|
|
2051
2034
|
ttl,
|
|
2052
2035
|
limit,
|
|
2053
2036
|
});
|
|
@@ -2060,14 +2043,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2060
2043
|
const key = "a";
|
|
2061
2044
|
const limit = 2;
|
|
2062
2045
|
const ttl = null;
|
|
2063
|
-
const semaphore1 =
|
|
2046
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2064
2047
|
limit,
|
|
2065
2048
|
ttl,
|
|
2066
2049
|
});
|
|
2067
2050
|
await semaphore1.acquire();
|
|
2068
2051
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
2069
2052
|
const noneExistingKey = "c";
|
|
2070
|
-
const semaphore2 =
|
|
2053
|
+
const semaphore2 = semaphoreFactory.create(noneExistingKey, {
|
|
2071
2054
|
ttl: newTtl,
|
|
2072
2055
|
limit,
|
|
2073
2056
|
});
|
|
@@ -2078,14 +2061,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2078
2061
|
const key = "a";
|
|
2079
2062
|
const limit = 2;
|
|
2080
2063
|
const ttl = null;
|
|
2081
|
-
const semaphore1 =
|
|
2064
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2082
2065
|
limit,
|
|
2083
2066
|
ttl,
|
|
2084
2067
|
});
|
|
2085
2068
|
await semaphore1.acquire();
|
|
2086
2069
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
2087
2070
|
const noneExistingSlotId = "1";
|
|
2088
|
-
const semaphore2 =
|
|
2071
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2089
2072
|
ttl: newTtl,
|
|
2090
2073
|
limit,
|
|
2091
2074
|
slotId: noneExistingSlotId,
|
|
@@ -2097,7 +2080,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2097
2080
|
const key = "a";
|
|
2098
2081
|
const limit = 2;
|
|
2099
2082
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2100
|
-
const semaphore =
|
|
2083
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2101
2084
|
ttl,
|
|
2102
2085
|
limit,
|
|
2103
2086
|
});
|
|
@@ -2107,25 +2090,11 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2107
2090
|
const result = await semaphore.refresh(newTtl);
|
|
2108
2091
|
expect(result).toBe(false);
|
|
2109
2092
|
});
|
|
2110
|
-
test("Should return false when slot exists
|
|
2111
|
-
const key = "a";
|
|
2112
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2113
|
-
const limit = 2;
|
|
2114
|
-
const semaphore = semaphoreProvider.create(key, {
|
|
2115
|
-
ttl,
|
|
2116
|
-
limit,
|
|
2117
|
-
});
|
|
2118
|
-
await semaphore.acquire();
|
|
2119
|
-
await delay(ttl);
|
|
2120
|
-
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
2121
|
-
const result = await semaphore.refresh(newTtl);
|
|
2122
|
-
expect(result).toBe(false);
|
|
2123
|
-
});
|
|
2124
|
-
test("Should return false when slot exists, is unexpireable", async () => {
|
|
2093
|
+
test("Should return false when slot exists and is unexpireable", async () => {
|
|
2125
2094
|
const key = "a";
|
|
2126
2095
|
const ttl = null;
|
|
2127
2096
|
const limit = 2;
|
|
2128
|
-
const semaphore =
|
|
2097
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2129
2098
|
ttl,
|
|
2130
2099
|
limit,
|
|
2131
2100
|
});
|
|
@@ -2134,11 +2103,11 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2134
2103
|
const result = await semaphore.refresh(newTtl);
|
|
2135
2104
|
expect(result).toBe(false);
|
|
2136
2105
|
});
|
|
2137
|
-
test("Should return true when slot exists
|
|
2106
|
+
test("Should return true when slot exists and is unexpired", async () => {
|
|
2138
2107
|
const key = "a";
|
|
2139
2108
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2140
2109
|
const limit = 2;
|
|
2141
|
-
const semaphore =
|
|
2110
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2142
2111
|
ttl,
|
|
2143
2112
|
limit,
|
|
2144
2113
|
});
|
|
@@ -2147,17 +2116,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2147
2116
|
const result = await semaphore.refresh(newTtl);
|
|
2148
2117
|
expect(result).toBe(true);
|
|
2149
2118
|
});
|
|
2150
|
-
test("Should not update expiration when slot exists
|
|
2119
|
+
test("Should not update expiration when slot exists and is unexpireable", async () => {
|
|
2151
2120
|
const key = "a";
|
|
2152
2121
|
const limit = 2;
|
|
2153
2122
|
const ttl1 = null;
|
|
2154
|
-
const semaphore1 =
|
|
2123
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2155
2124
|
ttl: ttl1,
|
|
2156
2125
|
limit,
|
|
2157
2126
|
});
|
|
2158
2127
|
await semaphore1.acquire();
|
|
2159
2128
|
const ttl2 = null;
|
|
2160
|
-
const semaphore2 =
|
|
2129
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2161
2130
|
ttl: ttl2,
|
|
2162
2131
|
limit,
|
|
2163
2132
|
});
|
|
@@ -2165,24 +2134,24 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2165
2134
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
2166
2135
|
await semaphore2.refresh(newTtl);
|
|
2167
2136
|
await delay(newTtl);
|
|
2168
|
-
const semaphore3 =
|
|
2137
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
2169
2138
|
ttl: ttl2,
|
|
2170
2139
|
limit,
|
|
2171
2140
|
});
|
|
2172
2141
|
const result1 = await semaphore3.acquire();
|
|
2173
2142
|
expect(result1).toBe(false);
|
|
2174
2143
|
});
|
|
2175
|
-
test("Should update expiration when slot exists
|
|
2144
|
+
test("Should update expiration when slot exists and is unexpired", async () => {
|
|
2176
2145
|
const key = "a";
|
|
2177
2146
|
const limit = 2;
|
|
2178
2147
|
const ttl1 = null;
|
|
2179
|
-
const semaphore1 =
|
|
2148
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2180
2149
|
ttl: ttl1,
|
|
2181
2150
|
limit,
|
|
2182
2151
|
});
|
|
2183
2152
|
await semaphore1.acquire();
|
|
2184
2153
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
2185
|
-
const semaphore2 =
|
|
2154
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2186
2155
|
limit,
|
|
2187
2156
|
ttl: ttl2,
|
|
2188
2157
|
});
|
|
@@ -2190,7 +2159,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2190
2159
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
2191
2160
|
await semaphore2.refresh(newTtl);
|
|
2192
2161
|
await delay(newTtl.divide(2));
|
|
2193
|
-
const semaphore3 =
|
|
2162
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
2194
2163
|
ttl: ttl2,
|
|
2195
2164
|
limit,
|
|
2196
2165
|
});
|
|
@@ -2206,14 +2175,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2206
2175
|
const key = "a";
|
|
2207
2176
|
const limit = 2;
|
|
2208
2177
|
const ttl = null;
|
|
2209
|
-
const semaphore1 =
|
|
2178
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2210
2179
|
limit,
|
|
2211
2180
|
ttl,
|
|
2212
2181
|
});
|
|
2213
2182
|
await semaphore1.acquire();
|
|
2214
2183
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
2215
2184
|
const noneExistingKey = "c";
|
|
2216
|
-
const semaphore2 =
|
|
2185
|
+
const semaphore2 = semaphoreFactory.create(noneExistingKey, {
|
|
2217
2186
|
ttl: newTtl,
|
|
2218
2187
|
limit,
|
|
2219
2188
|
});
|
|
@@ -2224,14 +2193,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2224
2193
|
const key = "a";
|
|
2225
2194
|
const limit = 2;
|
|
2226
2195
|
const ttl = null;
|
|
2227
|
-
const semaphore1 =
|
|
2196
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2228
2197
|
limit,
|
|
2229
2198
|
ttl,
|
|
2230
2199
|
});
|
|
2231
2200
|
await semaphore1.acquire();
|
|
2232
2201
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
2233
2202
|
const noneExistingSlotId = "1";
|
|
2234
|
-
const semaphore2 =
|
|
2203
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2235
2204
|
ttl: newTtl,
|
|
2236
2205
|
limit,
|
|
2237
2206
|
slotId: noneExistingSlotId,
|
|
@@ -2243,7 +2212,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2243
2212
|
const key = "a";
|
|
2244
2213
|
const limit = 2;
|
|
2245
2214
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2246
|
-
const semaphore =
|
|
2215
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2247
2216
|
ttl,
|
|
2248
2217
|
limit,
|
|
2249
2218
|
});
|
|
@@ -2257,7 +2226,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2257
2226
|
const key = "a";
|
|
2258
2227
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2259
2228
|
const limit = 2;
|
|
2260
|
-
const semaphore =
|
|
2229
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2261
2230
|
ttl,
|
|
2262
2231
|
limit,
|
|
2263
2232
|
});
|
|
@@ -2267,11 +2236,11 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2267
2236
|
const result = semaphore.refreshOrFail(newTtl);
|
|
2268
2237
|
await expect(result).rejects.toBeInstanceOf(FailedRefreshSemaphoreError);
|
|
2269
2238
|
});
|
|
2270
|
-
test("Should throw FailedRefreshSemaphoreError when slot exists
|
|
2239
|
+
test("Should throw FailedRefreshSemaphoreError when slot exists and is unexpireable", async () => {
|
|
2271
2240
|
const key = "a";
|
|
2272
2241
|
const ttl = null;
|
|
2273
2242
|
const limit = 2;
|
|
2274
|
-
const semaphore =
|
|
2243
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2275
2244
|
ttl,
|
|
2276
2245
|
limit,
|
|
2277
2246
|
});
|
|
@@ -2280,11 +2249,11 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2280
2249
|
const result = semaphore.refreshOrFail(newTtl);
|
|
2281
2250
|
await expect(result).rejects.toBeInstanceOf(FailedRefreshSemaphoreError);
|
|
2282
2251
|
});
|
|
2283
|
-
test("Should not throw error when slot exists
|
|
2252
|
+
test("Should not throw error when slot exists and is unexpired", async () => {
|
|
2284
2253
|
const key = "a";
|
|
2285
2254
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2286
2255
|
const limit = 2;
|
|
2287
|
-
const semaphore =
|
|
2256
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2288
2257
|
ttl,
|
|
2289
2258
|
limit,
|
|
2290
2259
|
});
|
|
@@ -2293,17 +2262,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2293
2262
|
const result = semaphore.refreshOrFail(newTtl);
|
|
2294
2263
|
await expect(result).resolves.toBeUndefined();
|
|
2295
2264
|
});
|
|
2296
|
-
test("Should not update expiration when slot exists
|
|
2265
|
+
test("Should not update expiration when slot exists and is unexpireable", async () => {
|
|
2297
2266
|
const key = "a";
|
|
2298
2267
|
const limit = 2;
|
|
2299
2268
|
const ttl1 = null;
|
|
2300
|
-
const semaphore1 =
|
|
2269
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2301
2270
|
ttl: ttl1,
|
|
2302
2271
|
limit,
|
|
2303
2272
|
});
|
|
2304
2273
|
await semaphore1.acquire();
|
|
2305
2274
|
const ttl2 = null;
|
|
2306
|
-
const semaphore2 =
|
|
2275
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2307
2276
|
ttl: ttl2,
|
|
2308
2277
|
limit,
|
|
2309
2278
|
});
|
|
@@ -2316,24 +2285,24 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2316
2285
|
/* EMPTY */
|
|
2317
2286
|
}
|
|
2318
2287
|
await delay(newTtl);
|
|
2319
|
-
const semaphore3 =
|
|
2288
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
2320
2289
|
ttl: ttl2,
|
|
2321
2290
|
limit,
|
|
2322
2291
|
});
|
|
2323
2292
|
const result1 = await semaphore3.acquire();
|
|
2324
2293
|
expect(result1).toBe(false);
|
|
2325
2294
|
});
|
|
2326
|
-
test("Should update expiration when slot exists
|
|
2295
|
+
test("Should update expiration when slot exists and is unexpired", async () => {
|
|
2327
2296
|
const key = "a";
|
|
2328
2297
|
const limit = 2;
|
|
2329
2298
|
const ttl1 = null;
|
|
2330
|
-
const semaphore1 =
|
|
2299
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2331
2300
|
ttl: ttl1,
|
|
2332
2301
|
limit,
|
|
2333
2302
|
});
|
|
2334
2303
|
await semaphore1.acquire();
|
|
2335
2304
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
2336
|
-
const semaphore2 =
|
|
2305
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2337
2306
|
limit,
|
|
2338
2307
|
ttl: ttl2,
|
|
2339
2308
|
});
|
|
@@ -2341,7 +2310,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2341
2310
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
2342
2311
|
await semaphore2.refreshOrFail(newTtl);
|
|
2343
2312
|
await delay(newTtl.divide(2));
|
|
2344
|
-
const semaphore3 =
|
|
2313
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
2345
2314
|
ttl: ttl2,
|
|
2346
2315
|
limit,
|
|
2347
2316
|
});
|
|
@@ -2357,7 +2326,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2357
2326
|
const key = "a";
|
|
2358
2327
|
const limit = 2;
|
|
2359
2328
|
const slotId = "1";
|
|
2360
|
-
const semaphore =
|
|
2329
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2361
2330
|
slotId,
|
|
2362
2331
|
limit,
|
|
2363
2332
|
});
|
|
@@ -2366,7 +2335,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2366
2335
|
test("Should return semaphore id of ISemaphore instance when given explicitly", () => {
|
|
2367
2336
|
const key = "a";
|
|
2368
2337
|
const limit = 2;
|
|
2369
|
-
const semaphore =
|
|
2338
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2370
2339
|
limit,
|
|
2371
2340
|
});
|
|
2372
2341
|
expect(semaphore.id).toBeTypeOf("string");
|
|
@@ -2378,7 +2347,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2378
2347
|
const key = "a";
|
|
2379
2348
|
const limit = 2;
|
|
2380
2349
|
const ttl = null;
|
|
2381
|
-
const semaphore =
|
|
2350
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2382
2351
|
ttl,
|
|
2383
2352
|
limit,
|
|
2384
2353
|
});
|
|
@@ -2388,7 +2357,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2388
2357
|
const key = "a";
|
|
2389
2358
|
const limit = 2;
|
|
2390
2359
|
const ttl = TimeSpan.fromMilliseconds(100);
|
|
2391
|
-
const semaphore =
|
|
2360
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2392
2361
|
ttl,
|
|
2393
2362
|
limit,
|
|
2394
2363
|
});
|
|
@@ -2401,7 +2370,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2401
2370
|
const key = "a";
|
|
2402
2371
|
const limit = 3;
|
|
2403
2372
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2404
|
-
const semaphore =
|
|
2373
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2405
2374
|
limit,
|
|
2406
2375
|
ttl,
|
|
2407
2376
|
});
|
|
@@ -2414,7 +2383,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2414
2383
|
const key = "a";
|
|
2415
2384
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2416
2385
|
const limit = 2;
|
|
2417
|
-
const semaphore =
|
|
2386
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2418
2387
|
ttl,
|
|
2419
2388
|
limit,
|
|
2420
2389
|
});
|
|
@@ -2429,13 +2398,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2429
2398
|
const key = "a";
|
|
2430
2399
|
const limit = 2;
|
|
2431
2400
|
const ttl1 = null;
|
|
2432
|
-
const semaphore1 =
|
|
2401
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2433
2402
|
ttl: ttl1,
|
|
2434
2403
|
limit,
|
|
2435
2404
|
});
|
|
2436
2405
|
await semaphore1.acquire();
|
|
2437
2406
|
const ttl2 = null;
|
|
2438
|
-
const semaphore2 =
|
|
2407
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2439
2408
|
ttl: ttl2,
|
|
2440
2409
|
limit,
|
|
2441
2410
|
});
|
|
@@ -2450,13 +2419,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2450
2419
|
const key = "a";
|
|
2451
2420
|
const limit = 2;
|
|
2452
2421
|
const ttl1 = null;
|
|
2453
|
-
const semaphore1 =
|
|
2422
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2454
2423
|
limit,
|
|
2455
2424
|
ttl: ttl1,
|
|
2456
2425
|
});
|
|
2457
2426
|
await semaphore1.acquire();
|
|
2458
2427
|
const ttl2 = null;
|
|
2459
|
-
const semaphore2 =
|
|
2428
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2460
2429
|
ttl: ttl2,
|
|
2461
2430
|
limit,
|
|
2462
2431
|
});
|
|
@@ -2472,13 +2441,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2472
2441
|
const key = "a";
|
|
2473
2442
|
const limit = 3;
|
|
2474
2443
|
const ttl1 = null;
|
|
2475
|
-
const semaphore1 =
|
|
2444
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2476
2445
|
ttl: ttl1,
|
|
2477
2446
|
limit,
|
|
2478
2447
|
});
|
|
2479
2448
|
await semaphore1.acquire();
|
|
2480
2449
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
2481
|
-
const semaphore2 =
|
|
2450
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2482
2451
|
ttl: ttl2,
|
|
2483
2452
|
limit,
|
|
2484
2453
|
});
|
|
@@ -2495,13 +2464,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2495
2464
|
const key = "a";
|
|
2496
2465
|
const limit = 3;
|
|
2497
2466
|
const ttl1 = null;
|
|
2498
|
-
const semaphore1 =
|
|
2467
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2499
2468
|
ttl: ttl1,
|
|
2500
2469
|
limit,
|
|
2501
2470
|
});
|
|
2502
2471
|
await semaphore1.acquire();
|
|
2503
2472
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
2504
|
-
const semaphore2 =
|
|
2473
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2505
2474
|
ttl: ttl2,
|
|
2506
2475
|
limit,
|
|
2507
2476
|
});
|
|
@@ -2517,16 +2486,19 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2517
2486
|
});
|
|
2518
2487
|
});
|
|
2519
2488
|
test("Should return ISemaphoreAcquiredState when slot is unexpired", async () => {
|
|
2489
|
+
expect.addEqualityTesters([
|
|
2490
|
+
createIsTimeSpanEqualityTester(timeSpanEqualityBuffer),
|
|
2491
|
+
]);
|
|
2520
2492
|
const key = "a";
|
|
2521
2493
|
const limit = 3;
|
|
2522
2494
|
const ttl1 = null;
|
|
2523
|
-
const semaphore1 =
|
|
2495
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2524
2496
|
ttl: ttl1,
|
|
2525
2497
|
limit,
|
|
2526
2498
|
});
|
|
2527
2499
|
await semaphore1.acquire();
|
|
2528
2500
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
2529
|
-
const semaphore2 =
|
|
2501
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2530
2502
|
ttl: ttl2,
|
|
2531
2503
|
limit,
|
|
2532
2504
|
});
|
|
@@ -2545,13 +2517,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2545
2517
|
const key = "a";
|
|
2546
2518
|
const limit = 1;
|
|
2547
2519
|
const ttl1 = null;
|
|
2548
|
-
const semaphore1 =
|
|
2520
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2549
2521
|
ttl: ttl1,
|
|
2550
2522
|
limit,
|
|
2551
2523
|
});
|
|
2552
2524
|
await semaphore1.acquire();
|
|
2553
2525
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
2554
|
-
const semaphore2 =
|
|
2526
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2555
2527
|
ttl: ttl2,
|
|
2556
2528
|
limit,
|
|
2557
2529
|
});
|
|
@@ -2573,8 +2545,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2573
2545
|
const limit = 2;
|
|
2574
2546
|
const ttl = null;
|
|
2575
2547
|
const handlerFn = vi.fn((_event) => { });
|
|
2576
|
-
await
|
|
2577
|
-
const semaphore =
|
|
2548
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
2549
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2578
2550
|
limit,
|
|
2579
2551
|
ttl,
|
|
2580
2552
|
});
|
|
@@ -2593,14 +2565,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2593
2565
|
const key = "a";
|
|
2594
2566
|
const limit = 2;
|
|
2595
2567
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2596
|
-
const semaphore =
|
|
2568
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2597
2569
|
limit,
|
|
2598
2570
|
ttl,
|
|
2599
2571
|
});
|
|
2600
2572
|
await semaphore.acquire();
|
|
2601
2573
|
await delay(ttl);
|
|
2602
2574
|
const handlerFn = vi.fn((_event) => { });
|
|
2603
|
-
await
|
|
2575
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
2604
2576
|
await semaphore.acquire();
|
|
2605
2577
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
2606
2578
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
@@ -2616,17 +2588,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2616
2588
|
const key = "a";
|
|
2617
2589
|
const limit = 2;
|
|
2618
2590
|
const ttl = null;
|
|
2619
|
-
const semaphore1 =
|
|
2591
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2620
2592
|
limit,
|
|
2621
2593
|
ttl,
|
|
2622
2594
|
});
|
|
2623
2595
|
await semaphore1.acquire();
|
|
2624
|
-
const semaphore2 =
|
|
2596
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2625
2597
|
limit,
|
|
2626
2598
|
ttl,
|
|
2627
2599
|
});
|
|
2628
2600
|
const handlerFn = vi.fn((_event) => { });
|
|
2629
|
-
await
|
|
2601
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
2630
2602
|
await semaphore2.acquire();
|
|
2631
2603
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
2632
2604
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
@@ -2642,19 +2614,19 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2642
2614
|
const key = "a";
|
|
2643
2615
|
const limit = 2;
|
|
2644
2616
|
const ttl = null;
|
|
2645
|
-
const semaphore1 =
|
|
2617
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2646
2618
|
limit,
|
|
2647
2619
|
ttl,
|
|
2648
2620
|
});
|
|
2649
2621
|
await semaphore1.acquire();
|
|
2650
|
-
const semaphore2 =
|
|
2622
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2651
2623
|
limit,
|
|
2652
2624
|
ttl,
|
|
2653
2625
|
});
|
|
2654
2626
|
await semaphore2.acquire();
|
|
2655
2627
|
const handlerFn = vi.fn((_event) => { });
|
|
2656
|
-
await
|
|
2657
|
-
const semaphore3 =
|
|
2628
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.LIMIT_REACHED, handlerFn);
|
|
2629
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
2658
2630
|
limit,
|
|
2659
2631
|
ttl,
|
|
2660
2632
|
});
|
|
@@ -2673,13 +2645,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2673
2645
|
const key = "a";
|
|
2674
2646
|
const limit = 2;
|
|
2675
2647
|
const ttl1 = null;
|
|
2676
|
-
const semaphore1 =
|
|
2648
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2677
2649
|
limit,
|
|
2678
2650
|
ttl: ttl1,
|
|
2679
2651
|
});
|
|
2680
2652
|
await semaphore1.acquire();
|
|
2681
2653
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
2682
|
-
const semaphore2 =
|
|
2654
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2683
2655
|
limit,
|
|
2684
2656
|
ttl: ttl2,
|
|
2685
2657
|
});
|
|
@@ -2687,8 +2659,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2687
2659
|
await delay(ttl2);
|
|
2688
2660
|
const ttl3 = null;
|
|
2689
2661
|
const handlerFn = vi.fn((_event) => { });
|
|
2690
|
-
await
|
|
2691
|
-
const semaphore3 =
|
|
2662
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
2663
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
2692
2664
|
limit,
|
|
2693
2665
|
ttl: ttl3,
|
|
2694
2666
|
});
|
|
@@ -2708,8 +2680,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2708
2680
|
const limit = 2;
|
|
2709
2681
|
const ttl = null;
|
|
2710
2682
|
const handlerFn = vi.fn((_event) => { });
|
|
2711
|
-
await
|
|
2712
|
-
const semaphore =
|
|
2683
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
2684
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2713
2685
|
limit,
|
|
2714
2686
|
ttl,
|
|
2715
2687
|
});
|
|
@@ -2730,8 +2702,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2730
2702
|
const limit = 2;
|
|
2731
2703
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2732
2704
|
const handlerFn = vi.fn((_event) => { });
|
|
2733
|
-
await
|
|
2734
|
-
const semaphore =
|
|
2705
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
2706
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2735
2707
|
limit,
|
|
2736
2708
|
ttl,
|
|
2737
2709
|
});
|
|
@@ -2754,8 +2726,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2754
2726
|
const limit = 2;
|
|
2755
2727
|
const ttl = null;
|
|
2756
2728
|
const handlerFn = vi.fn((_event) => { });
|
|
2757
|
-
await
|
|
2758
|
-
const semaphore =
|
|
2729
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
2730
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2759
2731
|
limit,
|
|
2760
2732
|
ttl,
|
|
2761
2733
|
});
|
|
@@ -2774,14 +2746,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2774
2746
|
const key = "a";
|
|
2775
2747
|
const limit = 2;
|
|
2776
2748
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2777
|
-
const semaphore =
|
|
2749
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2778
2750
|
limit,
|
|
2779
2751
|
ttl,
|
|
2780
2752
|
});
|
|
2781
2753
|
await semaphore.acquire();
|
|
2782
2754
|
await delay(ttl);
|
|
2783
2755
|
const handlerFn = vi.fn((_event) => { });
|
|
2784
|
-
await
|
|
2756
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
2785
2757
|
await semaphore.acquireOrFail();
|
|
2786
2758
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
2787
2759
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
@@ -2797,17 +2769,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2797
2769
|
const key = "a";
|
|
2798
2770
|
const limit = 2;
|
|
2799
2771
|
const ttl = null;
|
|
2800
|
-
const semaphore1 =
|
|
2772
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2801
2773
|
limit,
|
|
2802
2774
|
ttl,
|
|
2803
2775
|
});
|
|
2804
2776
|
await semaphore1.acquire();
|
|
2805
|
-
const semaphore2 =
|
|
2777
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2806
2778
|
limit,
|
|
2807
2779
|
ttl,
|
|
2808
2780
|
});
|
|
2809
2781
|
const handlerFn = vi.fn((_event) => { });
|
|
2810
|
-
await
|
|
2782
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
2811
2783
|
await semaphore2.acquireOrFail();
|
|
2812
2784
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
2813
2785
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
@@ -2823,19 +2795,19 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2823
2795
|
const key = "a";
|
|
2824
2796
|
const limit = 2;
|
|
2825
2797
|
const ttl = null;
|
|
2826
|
-
const semaphore1 =
|
|
2798
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2827
2799
|
limit,
|
|
2828
2800
|
ttl,
|
|
2829
2801
|
});
|
|
2830
2802
|
await semaphore1.acquire();
|
|
2831
|
-
const semaphore2 =
|
|
2803
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2832
2804
|
limit,
|
|
2833
2805
|
ttl,
|
|
2834
2806
|
});
|
|
2835
2807
|
await semaphore2.acquire();
|
|
2836
2808
|
const handlerFn = vi.fn((_event) => { });
|
|
2837
|
-
await
|
|
2838
|
-
const semaphore3 =
|
|
2809
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.LIMIT_REACHED, handlerFn);
|
|
2810
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
2839
2811
|
limit,
|
|
2840
2812
|
ttl,
|
|
2841
2813
|
});
|
|
@@ -2859,13 +2831,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2859
2831
|
const key = "a";
|
|
2860
2832
|
const limit = 2;
|
|
2861
2833
|
const ttl1 = null;
|
|
2862
|
-
const semaphore1 =
|
|
2834
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2863
2835
|
limit,
|
|
2864
2836
|
ttl: ttl1,
|
|
2865
2837
|
});
|
|
2866
2838
|
await semaphore1.acquire();
|
|
2867
2839
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
2868
|
-
const semaphore2 =
|
|
2840
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2869
2841
|
limit,
|
|
2870
2842
|
ttl: ttl2,
|
|
2871
2843
|
});
|
|
@@ -2873,8 +2845,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2873
2845
|
await delay(ttl2);
|
|
2874
2846
|
const ttl3 = null;
|
|
2875
2847
|
const handlerFn = vi.fn((_event) => { });
|
|
2876
|
-
await
|
|
2877
|
-
const semaphore3 =
|
|
2848
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
2849
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
2878
2850
|
limit,
|
|
2879
2851
|
ttl: ttl3,
|
|
2880
2852
|
});
|
|
@@ -2894,8 +2866,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2894
2866
|
const limit = 2;
|
|
2895
2867
|
const ttl = null;
|
|
2896
2868
|
const handlerFn = vi.fn((_event) => { });
|
|
2897
|
-
await
|
|
2898
|
-
const semaphore =
|
|
2869
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
2870
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2899
2871
|
limit,
|
|
2900
2872
|
ttl,
|
|
2901
2873
|
});
|
|
@@ -2916,8 +2888,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2916
2888
|
const limit = 2;
|
|
2917
2889
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2918
2890
|
const handlerFn = vi.fn((_event) => { });
|
|
2919
|
-
await
|
|
2920
|
-
const semaphore =
|
|
2891
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
2892
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2921
2893
|
limit,
|
|
2922
2894
|
ttl,
|
|
2923
2895
|
});
|
|
@@ -2940,8 +2912,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2940
2912
|
const limit = 2;
|
|
2941
2913
|
const ttl = null;
|
|
2942
2914
|
const handlerFn = vi.fn((_event) => { });
|
|
2943
|
-
await
|
|
2944
|
-
const semaphore =
|
|
2915
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
2916
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2945
2917
|
limit,
|
|
2946
2918
|
ttl,
|
|
2947
2919
|
});
|
|
@@ -2963,14 +2935,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2963
2935
|
const key = "a";
|
|
2964
2936
|
const limit = 2;
|
|
2965
2937
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2966
|
-
const semaphore =
|
|
2938
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
2967
2939
|
limit,
|
|
2968
2940
|
ttl,
|
|
2969
2941
|
});
|
|
2970
2942
|
await semaphore.acquire();
|
|
2971
2943
|
await delay(ttl);
|
|
2972
2944
|
const handlerFn = vi.fn((_event) => { });
|
|
2973
|
-
await
|
|
2945
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
2974
2946
|
await semaphore.acquireBlocking({
|
|
2975
2947
|
time: TimeSpan.fromMilliseconds(5),
|
|
2976
2948
|
interval: TimeSpan.fromMilliseconds(5),
|
|
@@ -2989,17 +2961,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
2989
2961
|
const key = "a";
|
|
2990
2962
|
const limit = 2;
|
|
2991
2963
|
const ttl = null;
|
|
2992
|
-
const semaphore1 =
|
|
2964
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
2993
2965
|
limit,
|
|
2994
2966
|
ttl,
|
|
2995
2967
|
});
|
|
2996
2968
|
await semaphore1.acquire();
|
|
2997
|
-
const semaphore2 =
|
|
2969
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
2998
2970
|
limit,
|
|
2999
2971
|
ttl,
|
|
3000
2972
|
});
|
|
3001
2973
|
const handlerFn = vi.fn((_event) => { });
|
|
3002
|
-
await
|
|
2974
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
3003
2975
|
await semaphore2.acquireBlocking({
|
|
3004
2976
|
time: TimeSpan.fromMilliseconds(5),
|
|
3005
2977
|
interval: TimeSpan.fromMilliseconds(5),
|
|
@@ -3018,19 +2990,19 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3018
2990
|
const key = "a";
|
|
3019
2991
|
const limit = 2;
|
|
3020
2992
|
const ttl = null;
|
|
3021
|
-
const semaphore1 =
|
|
2993
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
3022
2994
|
limit,
|
|
3023
2995
|
ttl,
|
|
3024
2996
|
});
|
|
3025
2997
|
await semaphore1.acquire();
|
|
3026
|
-
const semaphore2 =
|
|
2998
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
3027
2999
|
limit,
|
|
3028
3000
|
ttl,
|
|
3029
3001
|
});
|
|
3030
3002
|
await semaphore2.acquire();
|
|
3031
3003
|
const handlerFn = vi.fn((_event) => { });
|
|
3032
|
-
await
|
|
3033
|
-
const semaphore3 =
|
|
3004
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.LIMIT_REACHED, handlerFn);
|
|
3005
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
3034
3006
|
limit,
|
|
3035
3007
|
ttl,
|
|
3036
3008
|
});
|
|
@@ -3038,7 +3010,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3038
3010
|
time: TimeSpan.fromMilliseconds(5),
|
|
3039
3011
|
interval: TimeSpan.fromMilliseconds(5),
|
|
3040
3012
|
});
|
|
3041
|
-
expect(handlerFn).
|
|
3013
|
+
expect(handlerFn.mock.calls.length).toBeGreaterThanOrEqual(1);
|
|
3014
|
+
expect(handlerFn.mock.calls.length).toBeLessThanOrEqual(4);
|
|
3042
3015
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
3043
3016
|
semaphore: expect.objectContaining({
|
|
3044
3017
|
key: semaphore3.key,
|
|
@@ -3052,13 +3025,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3052
3025
|
const key = "a";
|
|
3053
3026
|
const limit = 2;
|
|
3054
3027
|
const ttl1 = null;
|
|
3055
|
-
const semaphore1 =
|
|
3028
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
3056
3029
|
limit,
|
|
3057
3030
|
ttl: ttl1,
|
|
3058
3031
|
});
|
|
3059
3032
|
await semaphore1.acquire();
|
|
3060
3033
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
3061
|
-
const semaphore2 =
|
|
3034
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
3062
3035
|
limit,
|
|
3063
3036
|
ttl: ttl2,
|
|
3064
3037
|
});
|
|
@@ -3066,8 +3039,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3066
3039
|
await delay(ttl2);
|
|
3067
3040
|
const ttl3 = null;
|
|
3068
3041
|
const handlerFn = vi.fn((_event) => { });
|
|
3069
|
-
await
|
|
3070
|
-
const semaphore3 =
|
|
3042
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
3043
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
3071
3044
|
limit,
|
|
3072
3045
|
ttl: ttl3,
|
|
3073
3046
|
});
|
|
@@ -3090,8 +3063,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3090
3063
|
const limit = 2;
|
|
3091
3064
|
const ttl = null;
|
|
3092
3065
|
const handlerFn = vi.fn((_event) => { });
|
|
3093
|
-
await
|
|
3094
|
-
const semaphore =
|
|
3066
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
3067
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3095
3068
|
limit,
|
|
3096
3069
|
ttl,
|
|
3097
3070
|
});
|
|
@@ -3115,8 +3088,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3115
3088
|
const limit = 2;
|
|
3116
3089
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3117
3090
|
const handlerFn = vi.fn((_event) => { });
|
|
3118
|
-
await
|
|
3119
|
-
const semaphore =
|
|
3091
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
3092
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3120
3093
|
limit,
|
|
3121
3094
|
ttl,
|
|
3122
3095
|
});
|
|
@@ -3142,8 +3115,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3142
3115
|
const limit = 2;
|
|
3143
3116
|
const ttl = null;
|
|
3144
3117
|
const handlerFn = vi.fn((_event) => { });
|
|
3145
|
-
await
|
|
3146
|
-
const semaphore =
|
|
3118
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
3119
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3147
3120
|
limit,
|
|
3148
3121
|
ttl,
|
|
3149
3122
|
});
|
|
@@ -3165,14 +3138,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3165
3138
|
const key = "a";
|
|
3166
3139
|
const limit = 2;
|
|
3167
3140
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3168
|
-
const semaphore =
|
|
3141
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3169
3142
|
limit,
|
|
3170
3143
|
ttl,
|
|
3171
3144
|
});
|
|
3172
3145
|
await semaphore.acquire();
|
|
3173
3146
|
await delay(ttl);
|
|
3174
3147
|
const handlerFn = vi.fn((_event) => { });
|
|
3175
|
-
await
|
|
3148
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
3176
3149
|
await semaphore.acquireBlockingOrFail({
|
|
3177
3150
|
time: TimeSpan.fromMilliseconds(5),
|
|
3178
3151
|
interval: TimeSpan.fromMilliseconds(5),
|
|
@@ -3191,17 +3164,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3191
3164
|
const key = "a";
|
|
3192
3165
|
const limit = 2;
|
|
3193
3166
|
const ttl = null;
|
|
3194
|
-
const semaphore1 =
|
|
3167
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
3195
3168
|
limit,
|
|
3196
3169
|
ttl,
|
|
3197
3170
|
});
|
|
3198
3171
|
await semaphore1.acquire();
|
|
3199
|
-
const semaphore2 =
|
|
3172
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
3200
3173
|
limit,
|
|
3201
3174
|
ttl,
|
|
3202
3175
|
});
|
|
3203
3176
|
const handlerFn = vi.fn((_event) => { });
|
|
3204
|
-
await
|
|
3177
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
3205
3178
|
await semaphore2.acquireBlockingOrFail({
|
|
3206
3179
|
time: TimeSpan.fromMilliseconds(5),
|
|
3207
3180
|
interval: TimeSpan.fromMilliseconds(5),
|
|
@@ -3220,19 +3193,19 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3220
3193
|
const key = "a";
|
|
3221
3194
|
const limit = 2;
|
|
3222
3195
|
const ttl = null;
|
|
3223
|
-
const semaphore1 =
|
|
3196
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
3224
3197
|
limit,
|
|
3225
3198
|
ttl,
|
|
3226
3199
|
});
|
|
3227
3200
|
await semaphore1.acquire();
|
|
3228
|
-
const semaphore2 =
|
|
3201
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
3229
3202
|
limit,
|
|
3230
3203
|
ttl,
|
|
3231
3204
|
});
|
|
3232
3205
|
await semaphore2.acquire();
|
|
3233
3206
|
const handlerFn = vi.fn((_event) => { });
|
|
3234
|
-
await
|
|
3235
|
-
const semaphore3 =
|
|
3207
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.LIMIT_REACHED, handlerFn);
|
|
3208
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
3236
3209
|
limit,
|
|
3237
3210
|
ttl,
|
|
3238
3211
|
});
|
|
@@ -3245,7 +3218,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3245
3218
|
catch {
|
|
3246
3219
|
/* EMPTY */
|
|
3247
3220
|
}
|
|
3248
|
-
expect(handlerFn).
|
|
3221
|
+
expect(handlerFn.mock.calls.length).toBeGreaterThanOrEqual(1);
|
|
3222
|
+
expect(handlerFn.mock.calls.length).toBeLessThanOrEqual(4);
|
|
3249
3223
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
3250
3224
|
semaphore: expect.objectContaining({
|
|
3251
3225
|
key: semaphore3.key,
|
|
@@ -3259,13 +3233,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3259
3233
|
const key = "a";
|
|
3260
3234
|
const limit = 2;
|
|
3261
3235
|
const ttl1 = null;
|
|
3262
|
-
const semaphore1 =
|
|
3236
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
3263
3237
|
limit,
|
|
3264
3238
|
ttl: ttl1,
|
|
3265
3239
|
});
|
|
3266
3240
|
await semaphore1.acquire();
|
|
3267
3241
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
3268
|
-
const semaphore2 =
|
|
3242
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
3269
3243
|
limit,
|
|
3270
3244
|
ttl: ttl2,
|
|
3271
3245
|
});
|
|
@@ -3273,8 +3247,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3273
3247
|
await delay(ttl2);
|
|
3274
3248
|
const ttl3 = null;
|
|
3275
3249
|
const handlerFn = vi.fn((_event) => { });
|
|
3276
|
-
await
|
|
3277
|
-
const semaphore3 =
|
|
3250
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
3251
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
3278
3252
|
limit,
|
|
3279
3253
|
ttl: ttl3,
|
|
3280
3254
|
});
|
|
@@ -3297,8 +3271,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3297
3271
|
const limit = 2;
|
|
3298
3272
|
const ttl = null;
|
|
3299
3273
|
const handlerFn = vi.fn((_event) => { });
|
|
3300
|
-
await
|
|
3301
|
-
const semaphore =
|
|
3274
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
3275
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3302
3276
|
limit,
|
|
3303
3277
|
ttl,
|
|
3304
3278
|
});
|
|
@@ -3322,8 +3296,8 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3322
3296
|
const limit = 2;
|
|
3323
3297
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3324
3298
|
const handlerFn = vi.fn((_event) => { });
|
|
3325
|
-
await
|
|
3326
|
-
const semaphore =
|
|
3299
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ACQUIRED, handlerFn);
|
|
3300
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3327
3301
|
limit,
|
|
3328
3302
|
ttl,
|
|
3329
3303
|
});
|
|
@@ -3348,19 +3322,19 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3348
3322
|
const key = "a";
|
|
3349
3323
|
const limit = 2;
|
|
3350
3324
|
const ttl = null;
|
|
3351
|
-
await
|
|
3325
|
+
await semaphoreFactory
|
|
3352
3326
|
.create(key, {
|
|
3353
3327
|
limit,
|
|
3354
3328
|
ttl,
|
|
3355
3329
|
})
|
|
3356
3330
|
.acquire();
|
|
3357
3331
|
const noneExistingKey = "c";
|
|
3358
|
-
const semaphore =
|
|
3332
|
+
const semaphore = semaphoreFactory.create(noneExistingKey, {
|
|
3359
3333
|
limit,
|
|
3360
3334
|
ttl,
|
|
3361
3335
|
});
|
|
3362
3336
|
const handlerFn = vi.fn((_event) => { });
|
|
3363
|
-
await
|
|
3337
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_RELEASE, handlerFn);
|
|
3364
3338
|
await semaphore.release();
|
|
3365
3339
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3366
3340
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
@@ -3376,20 +3350,20 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3376
3350
|
const key = "a";
|
|
3377
3351
|
const limit = 2;
|
|
3378
3352
|
const ttl = null;
|
|
3379
|
-
await
|
|
3353
|
+
await semaphoreFactory
|
|
3380
3354
|
.create(key, {
|
|
3381
3355
|
limit,
|
|
3382
3356
|
ttl,
|
|
3383
3357
|
})
|
|
3384
3358
|
.acquire();
|
|
3385
3359
|
const noneExistingSlotId = "1";
|
|
3386
|
-
const semaphore =
|
|
3360
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3387
3361
|
limit,
|
|
3388
3362
|
ttl,
|
|
3389
3363
|
slotId: noneExistingSlotId,
|
|
3390
3364
|
});
|
|
3391
3365
|
const handlerFn = vi.fn((_event) => { });
|
|
3392
|
-
await
|
|
3366
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_RELEASE, handlerFn);
|
|
3393
3367
|
await semaphore.release();
|
|
3394
3368
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3395
3369
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
@@ -3405,18 +3379,18 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3405
3379
|
const key = "a";
|
|
3406
3380
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3407
3381
|
const limit = 2;
|
|
3408
|
-
const semaphore1 =
|
|
3382
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
3409
3383
|
ttl,
|
|
3410
3384
|
limit,
|
|
3411
3385
|
});
|
|
3412
3386
|
await semaphore1.acquire();
|
|
3413
3387
|
await delay(ttl);
|
|
3414
|
-
const semaphore =
|
|
3388
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3415
3389
|
ttl,
|
|
3416
3390
|
limit,
|
|
3417
3391
|
});
|
|
3418
3392
|
const handlerFn = vi.fn((_event) => { });
|
|
3419
|
-
await
|
|
3393
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_RELEASE, handlerFn);
|
|
3420
3394
|
await semaphore.release();
|
|
3421
3395
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3422
3396
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
@@ -3432,14 +3406,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3432
3406
|
const key = "a";
|
|
3433
3407
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3434
3408
|
const limit = 2;
|
|
3435
|
-
const semaphore =
|
|
3409
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3436
3410
|
ttl,
|
|
3437
3411
|
limit,
|
|
3438
3412
|
});
|
|
3439
3413
|
await semaphore.acquire();
|
|
3440
3414
|
await delay(ttl);
|
|
3441
3415
|
const handlerFn = vi.fn((_event) => { });
|
|
3442
|
-
await
|
|
3416
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_RELEASE, handlerFn);
|
|
3443
3417
|
await semaphore.release();
|
|
3444
3418
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3445
3419
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
@@ -3451,17 +3425,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3451
3425
|
}),
|
|
3452
3426
|
}));
|
|
3453
3427
|
});
|
|
3454
|
-
test("Should dispatch ReleasedSemaphoreEvent when slot exists
|
|
3428
|
+
test("Should dispatch ReleasedSemaphoreEvent when slot exists and is unexpired", async () => {
|
|
3455
3429
|
const key = "a";
|
|
3456
3430
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3457
3431
|
const limit = 2;
|
|
3458
|
-
const semaphore =
|
|
3432
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3459
3433
|
ttl,
|
|
3460
3434
|
limit,
|
|
3461
3435
|
});
|
|
3462
3436
|
await semaphore.acquire();
|
|
3463
3437
|
const handlerFn = vi.fn((_event) => { });
|
|
3464
|
-
await
|
|
3438
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.RELEASED, handlerFn);
|
|
3465
3439
|
await semaphore.release();
|
|
3466
3440
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3467
3441
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
@@ -3473,17 +3447,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3473
3447
|
}),
|
|
3474
3448
|
}));
|
|
3475
3449
|
});
|
|
3476
|
-
test("Should dispatch ReleasedSemaphoreEvent when slot exists
|
|
3450
|
+
test("Should dispatch ReleasedSemaphoreEvent when slot exists and is unexpireable", async () => {
|
|
3477
3451
|
const key = "a";
|
|
3478
3452
|
const ttl = null;
|
|
3479
3453
|
const limit = 2;
|
|
3480
|
-
const semaphore =
|
|
3454
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3481
3455
|
ttl,
|
|
3482
3456
|
limit,
|
|
3483
3457
|
});
|
|
3484
3458
|
await semaphore.acquire();
|
|
3485
3459
|
const handlerFn = vi.fn((_event) => { });
|
|
3486
|
-
await
|
|
3460
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.RELEASED, handlerFn);
|
|
3487
3461
|
await semaphore.release();
|
|
3488
3462
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3489
3463
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
@@ -3501,19 +3475,19 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3501
3475
|
const key = "a";
|
|
3502
3476
|
const limit = 2;
|
|
3503
3477
|
const ttl = null;
|
|
3504
|
-
await
|
|
3478
|
+
await semaphoreFactory
|
|
3505
3479
|
.create(key, {
|
|
3506
3480
|
limit,
|
|
3507
3481
|
ttl,
|
|
3508
3482
|
})
|
|
3509
3483
|
.acquire();
|
|
3510
3484
|
const noneExistingKey = "c";
|
|
3511
|
-
const semaphore =
|
|
3485
|
+
const semaphore = semaphoreFactory.create(noneExistingKey, {
|
|
3512
3486
|
limit,
|
|
3513
3487
|
ttl,
|
|
3514
3488
|
});
|
|
3515
3489
|
const handlerFn = vi.fn((_event) => { });
|
|
3516
|
-
await
|
|
3490
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_RELEASE, handlerFn);
|
|
3517
3491
|
try {
|
|
3518
3492
|
await semaphore.releaseOrFail();
|
|
3519
3493
|
}
|
|
@@ -3534,20 +3508,20 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3534
3508
|
const key = "a";
|
|
3535
3509
|
const limit = 2;
|
|
3536
3510
|
const ttl = null;
|
|
3537
|
-
await
|
|
3511
|
+
await semaphoreFactory
|
|
3538
3512
|
.create(key, {
|
|
3539
3513
|
limit,
|
|
3540
3514
|
ttl,
|
|
3541
3515
|
})
|
|
3542
3516
|
.acquire();
|
|
3543
3517
|
const noneExistingSlotId = "1";
|
|
3544
|
-
const semaphore =
|
|
3518
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3545
3519
|
limit,
|
|
3546
3520
|
ttl,
|
|
3547
3521
|
slotId: noneExistingSlotId,
|
|
3548
3522
|
});
|
|
3549
3523
|
const handlerFn = vi.fn((_event) => { });
|
|
3550
|
-
await
|
|
3524
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_RELEASE, handlerFn);
|
|
3551
3525
|
try {
|
|
3552
3526
|
await semaphore.releaseOrFail();
|
|
3553
3527
|
}
|
|
@@ -3568,18 +3542,18 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3568
3542
|
const key = "a";
|
|
3569
3543
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3570
3544
|
const limit = 2;
|
|
3571
|
-
const semaphore1 =
|
|
3545
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
3572
3546
|
ttl,
|
|
3573
3547
|
limit,
|
|
3574
3548
|
});
|
|
3575
3549
|
await semaphore1.acquire();
|
|
3576
3550
|
await delay(ttl);
|
|
3577
|
-
const semaphore =
|
|
3551
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3578
3552
|
ttl,
|
|
3579
3553
|
limit,
|
|
3580
3554
|
});
|
|
3581
3555
|
const handlerFn = vi.fn((_event) => { });
|
|
3582
|
-
await
|
|
3556
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_RELEASE, handlerFn);
|
|
3583
3557
|
try {
|
|
3584
3558
|
await semaphore.releaseOrFail();
|
|
3585
3559
|
}
|
|
@@ -3600,14 +3574,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3600
3574
|
const key = "a";
|
|
3601
3575
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3602
3576
|
const limit = 2;
|
|
3603
|
-
const semaphore =
|
|
3577
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3604
3578
|
ttl,
|
|
3605
3579
|
limit,
|
|
3606
3580
|
});
|
|
3607
3581
|
await semaphore.acquire();
|
|
3608
3582
|
await delay(ttl);
|
|
3609
3583
|
const handlerFn = vi.fn((_event) => { });
|
|
3610
|
-
await
|
|
3584
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_RELEASE, handlerFn);
|
|
3611
3585
|
try {
|
|
3612
3586
|
await semaphore.releaseOrFail();
|
|
3613
3587
|
}
|
|
@@ -3624,17 +3598,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3624
3598
|
}),
|
|
3625
3599
|
}));
|
|
3626
3600
|
});
|
|
3627
|
-
test("Should dispatch ReleasedSemaphoreEvent when slot exists
|
|
3601
|
+
test("Should dispatch ReleasedSemaphoreEvent when slot exists and is unexpired", async () => {
|
|
3628
3602
|
const key = "a";
|
|
3629
3603
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3630
3604
|
const limit = 2;
|
|
3631
|
-
const semaphore =
|
|
3605
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3632
3606
|
ttl,
|
|
3633
3607
|
limit,
|
|
3634
3608
|
});
|
|
3635
3609
|
await semaphore.acquire();
|
|
3636
3610
|
const handlerFn = vi.fn((_event) => { });
|
|
3637
|
-
await
|
|
3611
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.RELEASED, handlerFn);
|
|
3638
3612
|
await semaphore.releaseOrFail();
|
|
3639
3613
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3640
3614
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
@@ -3646,17 +3620,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3646
3620
|
}),
|
|
3647
3621
|
}));
|
|
3648
3622
|
});
|
|
3649
|
-
test("Should dispatch ReleasedSemaphoreEvent when slot exists
|
|
3623
|
+
test("Should dispatch ReleasedSemaphoreEvent when slot exists and is unexpireable", async () => {
|
|
3650
3624
|
const key = "a";
|
|
3651
3625
|
const ttl = null;
|
|
3652
3626
|
const limit = 2;
|
|
3653
|
-
const semaphore =
|
|
3627
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3654
3628
|
ttl,
|
|
3655
3629
|
limit,
|
|
3656
3630
|
});
|
|
3657
3631
|
await semaphore.acquire();
|
|
3658
3632
|
const handlerFn = vi.fn((_event) => { });
|
|
3659
|
-
await
|
|
3633
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.RELEASED, handlerFn);
|
|
3660
3634
|
await semaphore.releaseOrFail();
|
|
3661
3635
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3662
3636
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
@@ -3674,13 +3648,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3674
3648
|
const key = "a";
|
|
3675
3649
|
const limit = 3;
|
|
3676
3650
|
const ttl1 = null;
|
|
3677
|
-
const semaphore1 =
|
|
3651
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
3678
3652
|
ttl: ttl1,
|
|
3679
3653
|
limit,
|
|
3680
3654
|
});
|
|
3681
3655
|
await semaphore1.acquire();
|
|
3682
3656
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
3683
|
-
const semaphore2 =
|
|
3657
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
3684
3658
|
ttl: ttl2,
|
|
3685
3659
|
limit,
|
|
3686
3660
|
});
|
|
@@ -3688,12 +3662,12 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3688
3662
|
await delay(ttl2);
|
|
3689
3663
|
await semaphore1.release();
|
|
3690
3664
|
const ttl3 = null;
|
|
3691
|
-
const semaphore3 =
|
|
3665
|
+
const semaphore3 = semaphoreFactory.create(key, {
|
|
3692
3666
|
ttl: ttl3,
|
|
3693
3667
|
limit,
|
|
3694
3668
|
});
|
|
3695
3669
|
const handlerFn = vi.fn((_event) => { });
|
|
3696
|
-
await
|
|
3670
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ALL_FORCE_RELEASED, handlerFn);
|
|
3697
3671
|
await semaphore3.forceReleaseAll();
|
|
3698
3672
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3699
3673
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
@@ -3710,19 +3684,19 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3710
3684
|
const key = "a";
|
|
3711
3685
|
const limit = 2;
|
|
3712
3686
|
const ttl1 = null;
|
|
3713
|
-
const semaphore1 =
|
|
3687
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
3714
3688
|
ttl: ttl1,
|
|
3715
3689
|
limit,
|
|
3716
3690
|
});
|
|
3717
3691
|
await semaphore1.acquire();
|
|
3718
3692
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
3719
|
-
const semaphore2 =
|
|
3693
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
3720
3694
|
ttl: ttl2,
|
|
3721
3695
|
limit,
|
|
3722
3696
|
});
|
|
3723
3697
|
await semaphore2.acquire();
|
|
3724
3698
|
const handlerFn = vi.fn((_event) => { });
|
|
3725
|
-
await
|
|
3699
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.ALL_FORCE_RELEASED, handlerFn);
|
|
3726
3700
|
await semaphore1.forceReleaseAll();
|
|
3727
3701
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3728
3702
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
@@ -3741,19 +3715,19 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3741
3715
|
const key = "a";
|
|
3742
3716
|
const limit = 2;
|
|
3743
3717
|
const ttl = null;
|
|
3744
|
-
const semaphore1 =
|
|
3718
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
3745
3719
|
limit,
|
|
3746
3720
|
ttl,
|
|
3747
3721
|
});
|
|
3748
3722
|
await semaphore1.acquire();
|
|
3749
3723
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
3750
3724
|
const noneExistingKey = "c";
|
|
3751
|
-
const semaphore2 =
|
|
3725
|
+
const semaphore2 = semaphoreFactory.create(noneExistingKey, {
|
|
3752
3726
|
ttl: newTtl,
|
|
3753
3727
|
limit,
|
|
3754
3728
|
});
|
|
3755
3729
|
const handlerFn = vi.fn((_event) => { });
|
|
3756
|
-
await
|
|
3730
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_REFRESH, handlerFn);
|
|
3757
3731
|
await semaphore2.refresh();
|
|
3758
3732
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3759
3733
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
@@ -3769,20 +3743,20 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3769
3743
|
const key = "a";
|
|
3770
3744
|
const limit = 2;
|
|
3771
3745
|
const ttl = null;
|
|
3772
|
-
const semaphore1 =
|
|
3746
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
3773
3747
|
limit,
|
|
3774
3748
|
ttl,
|
|
3775
3749
|
});
|
|
3776
3750
|
await semaphore1.acquire();
|
|
3777
3751
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
3778
3752
|
const noneExistingSlotId = "1";
|
|
3779
|
-
const semaphore2 =
|
|
3753
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
3780
3754
|
ttl: newTtl,
|
|
3781
3755
|
limit,
|
|
3782
3756
|
slotId: noneExistingSlotId,
|
|
3783
3757
|
});
|
|
3784
3758
|
const handlerFn = vi.fn((_event) => { });
|
|
3785
|
-
await
|
|
3759
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_REFRESH, handlerFn);
|
|
3786
3760
|
await semaphore2.refresh();
|
|
3787
3761
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3788
3762
|
expect(handlerFn).toHaveBeenCalledWith(expect.objectContaining({
|
|
@@ -3798,14 +3772,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3798
3772
|
const key = "a";
|
|
3799
3773
|
const limit = 2;
|
|
3800
3774
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3801
|
-
const semaphore =
|
|
3775
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3802
3776
|
ttl,
|
|
3803
3777
|
limit,
|
|
3804
3778
|
});
|
|
3805
3779
|
await semaphore.acquire();
|
|
3806
3780
|
await delay(ttl);
|
|
3807
3781
|
const handlerFn = vi.fn((_event) => { });
|
|
3808
|
-
await
|
|
3782
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_REFRESH, handlerFn);
|
|
3809
3783
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
3810
3784
|
await semaphore.refresh(newTtl);
|
|
3811
3785
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
@@ -3822,14 +3796,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3822
3796
|
const key = "a";
|
|
3823
3797
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3824
3798
|
const limit = 2;
|
|
3825
|
-
const semaphore =
|
|
3799
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3826
3800
|
ttl,
|
|
3827
3801
|
limit,
|
|
3828
3802
|
});
|
|
3829
3803
|
await semaphore.acquire();
|
|
3830
3804
|
await delay(ttl);
|
|
3831
3805
|
const handlerFn = vi.fn((_event) => { });
|
|
3832
|
-
await
|
|
3806
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_REFRESH, handlerFn);
|
|
3833
3807
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
3834
3808
|
await semaphore.refresh(newTtl);
|
|
3835
3809
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
@@ -3842,17 +3816,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3842
3816
|
}),
|
|
3843
3817
|
}));
|
|
3844
3818
|
});
|
|
3845
|
-
test("Should dispatch FailedRefreshSemaphoreEvent when slot exists
|
|
3819
|
+
test("Should dispatch FailedRefreshSemaphoreEvent when slot exists and is unexpireable", async () => {
|
|
3846
3820
|
const key = "a";
|
|
3847
3821
|
const ttl = null;
|
|
3848
3822
|
const limit = 2;
|
|
3849
|
-
const semaphore =
|
|
3823
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3850
3824
|
ttl,
|
|
3851
3825
|
limit,
|
|
3852
3826
|
});
|
|
3853
3827
|
await semaphore.acquire();
|
|
3854
3828
|
const handlerFn = vi.fn((_event) => { });
|
|
3855
|
-
await
|
|
3829
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_REFRESH, handlerFn);
|
|
3856
3830
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
3857
3831
|
await semaphore.refresh(newTtl);
|
|
3858
3832
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
@@ -3865,17 +3839,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3865
3839
|
}),
|
|
3866
3840
|
}));
|
|
3867
3841
|
});
|
|
3868
|
-
test("Should dispatch RefreshedSemaphoreEvent when slot exists
|
|
3842
|
+
test("Should dispatch RefreshedSemaphoreEvent when slot exists and is unexpired", async () => {
|
|
3869
3843
|
const key = "a";
|
|
3870
3844
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3871
3845
|
const limit = 2;
|
|
3872
|
-
const semaphore =
|
|
3846
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3873
3847
|
ttl,
|
|
3874
3848
|
limit,
|
|
3875
3849
|
});
|
|
3876
3850
|
await semaphore.acquire();
|
|
3877
3851
|
const handlerFn = vi.fn((_event) => { });
|
|
3878
|
-
await
|
|
3852
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.REFRESHED, handlerFn);
|
|
3879
3853
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
3880
3854
|
await semaphore.refresh(newTtl);
|
|
3881
3855
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
@@ -3894,19 +3868,19 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3894
3868
|
const key = "a";
|
|
3895
3869
|
const limit = 2;
|
|
3896
3870
|
const ttl = null;
|
|
3897
|
-
const semaphore1 =
|
|
3871
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
3898
3872
|
limit,
|
|
3899
3873
|
ttl,
|
|
3900
3874
|
});
|
|
3901
3875
|
await semaphore1.acquire();
|
|
3902
3876
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
3903
3877
|
const noneExistingKey = "c";
|
|
3904
|
-
const semaphore2 =
|
|
3878
|
+
const semaphore2 = semaphoreFactory.create(noneExistingKey, {
|
|
3905
3879
|
ttl: newTtl,
|
|
3906
3880
|
limit,
|
|
3907
3881
|
});
|
|
3908
3882
|
const handlerFn = vi.fn((_event) => { });
|
|
3909
|
-
await
|
|
3883
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_REFRESH, handlerFn);
|
|
3910
3884
|
try {
|
|
3911
3885
|
await semaphore2.refreshOrFail(newTtl);
|
|
3912
3886
|
}
|
|
@@ -3927,20 +3901,20 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3927
3901
|
const key = "a";
|
|
3928
3902
|
const limit = 2;
|
|
3929
3903
|
const ttl = null;
|
|
3930
|
-
const semaphore1 =
|
|
3904
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
3931
3905
|
limit,
|
|
3932
3906
|
ttl,
|
|
3933
3907
|
});
|
|
3934
3908
|
await semaphore1.acquire();
|
|
3935
3909
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
3936
3910
|
const noneExistingSlotId = "1";
|
|
3937
|
-
const semaphore2 =
|
|
3911
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
3938
3912
|
ttl: newTtl,
|
|
3939
3913
|
limit,
|
|
3940
3914
|
slotId: noneExistingSlotId,
|
|
3941
3915
|
});
|
|
3942
3916
|
const handlerFn = vi.fn((_event) => { });
|
|
3943
|
-
await
|
|
3917
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_REFRESH, handlerFn);
|
|
3944
3918
|
try {
|
|
3945
3919
|
await semaphore2.refreshOrFail(newTtl);
|
|
3946
3920
|
}
|
|
@@ -3961,14 +3935,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3961
3935
|
const key = "a";
|
|
3962
3936
|
const limit = 2;
|
|
3963
3937
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3964
|
-
const semaphore =
|
|
3938
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3965
3939
|
ttl,
|
|
3966
3940
|
limit,
|
|
3967
3941
|
});
|
|
3968
3942
|
await semaphore.acquire();
|
|
3969
3943
|
await delay(ttl);
|
|
3970
3944
|
const handlerFn = vi.fn((_event) => { });
|
|
3971
|
-
await
|
|
3945
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_REFRESH, handlerFn);
|
|
3972
3946
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
3973
3947
|
try {
|
|
3974
3948
|
await semaphore.refreshOrFail(newTtl);
|
|
@@ -3990,14 +3964,14 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
3990
3964
|
const key = "a";
|
|
3991
3965
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3992
3966
|
const limit = 2;
|
|
3993
|
-
const semaphore =
|
|
3967
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
3994
3968
|
ttl,
|
|
3995
3969
|
limit,
|
|
3996
3970
|
});
|
|
3997
3971
|
await semaphore.acquire();
|
|
3998
3972
|
await delay(ttl);
|
|
3999
3973
|
const handlerFn = vi.fn((_event) => { });
|
|
4000
|
-
await
|
|
3974
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_REFRESH, handlerFn);
|
|
4001
3975
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
4002
3976
|
try {
|
|
4003
3977
|
await semaphore.refreshOrFail(newTtl);
|
|
@@ -4015,17 +3989,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
4015
3989
|
}),
|
|
4016
3990
|
}));
|
|
4017
3991
|
});
|
|
4018
|
-
test("Should dispatch FailedRefreshSemaphoreEvent when slot exists
|
|
3992
|
+
test("Should dispatch FailedRefreshSemaphoreEvent when slot exists and is unexpireable", async () => {
|
|
4019
3993
|
const key = "a";
|
|
4020
3994
|
const ttl = null;
|
|
4021
3995
|
const limit = 2;
|
|
4022
|
-
const semaphore =
|
|
3996
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
4023
3997
|
ttl,
|
|
4024
3998
|
limit,
|
|
4025
3999
|
});
|
|
4026
4000
|
await semaphore.acquire();
|
|
4027
4001
|
const handlerFn = vi.fn((_event) => { });
|
|
4028
|
-
await
|
|
4002
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.FAILED_REFRESH, handlerFn);
|
|
4029
4003
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
4030
4004
|
try {
|
|
4031
4005
|
await semaphore.refreshOrFail(newTtl);
|
|
@@ -4043,17 +4017,17 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
4043
4017
|
}),
|
|
4044
4018
|
}));
|
|
4045
4019
|
});
|
|
4046
|
-
test("Should dispatch RefreshedSemaphoreEvent when slot exists
|
|
4020
|
+
test("Should dispatch RefreshedSemaphoreEvent when slot exists and is unexpired", async () => {
|
|
4047
4021
|
const key = "a";
|
|
4048
4022
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
4049
4023
|
const limit = 2;
|
|
4050
|
-
const semaphore =
|
|
4024
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
4051
4025
|
ttl,
|
|
4052
4026
|
limit,
|
|
4053
4027
|
});
|
|
4054
4028
|
await semaphore.acquire();
|
|
4055
4029
|
const handlerFn = vi.fn((_event) => { });
|
|
4056
|
-
await
|
|
4030
|
+
await semaphoreFactory.events.addListener(SEMAPHORE_EVENTS.REFRESHED, handlerFn);
|
|
4057
4031
|
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
4058
4032
|
await semaphore.refreshOrFail(newTtl);
|
|
4059
4033
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
@@ -4075,7 +4049,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
4075
4049
|
const key = "a";
|
|
4076
4050
|
const limit = 3;
|
|
4077
4051
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
4078
|
-
const semaphore =
|
|
4052
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
4079
4053
|
limit,
|
|
4080
4054
|
ttl,
|
|
4081
4055
|
});
|
|
@@ -4089,7 +4063,7 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
4089
4063
|
const key = "a";
|
|
4090
4064
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
4091
4065
|
const limit = 2;
|
|
4092
|
-
const semaphore =
|
|
4066
|
+
const semaphore = semaphoreFactory.create(key, {
|
|
4093
4067
|
ttl,
|
|
4094
4068
|
limit,
|
|
4095
4069
|
});
|
|
@@ -4105,13 +4079,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
4105
4079
|
const key = "a";
|
|
4106
4080
|
const limit = 2;
|
|
4107
4081
|
const ttl1 = null;
|
|
4108
|
-
const semaphore1 =
|
|
4082
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
4109
4083
|
ttl: ttl1,
|
|
4110
4084
|
limit,
|
|
4111
4085
|
});
|
|
4112
4086
|
await semaphore1.acquire();
|
|
4113
4087
|
const ttl2 = null;
|
|
4114
|
-
const semaphore2 =
|
|
4088
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
4115
4089
|
ttl: ttl2,
|
|
4116
4090
|
limit,
|
|
4117
4091
|
});
|
|
@@ -4127,13 +4101,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
4127
4101
|
const key = "a";
|
|
4128
4102
|
const limit = 2;
|
|
4129
4103
|
const ttl1 = null;
|
|
4130
|
-
const semaphore1 =
|
|
4104
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
4131
4105
|
limit,
|
|
4132
4106
|
ttl: ttl1,
|
|
4133
4107
|
});
|
|
4134
4108
|
await semaphore1.acquire();
|
|
4135
4109
|
const ttl2 = null;
|
|
4136
|
-
const semaphore2 =
|
|
4110
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
4137
4111
|
ttl: ttl2,
|
|
4138
4112
|
limit,
|
|
4139
4113
|
});
|
|
@@ -4150,13 +4124,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
4150
4124
|
const key = "a";
|
|
4151
4125
|
const limit = 3;
|
|
4152
4126
|
const ttl1 = null;
|
|
4153
|
-
const semaphore1 =
|
|
4127
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
4154
4128
|
ttl: ttl1,
|
|
4155
4129
|
limit,
|
|
4156
4130
|
});
|
|
4157
4131
|
await semaphore1.acquire();
|
|
4158
4132
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
4159
|
-
const semaphore2 =
|
|
4133
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
4160
4134
|
ttl: ttl2,
|
|
4161
4135
|
limit,
|
|
4162
4136
|
});
|
|
@@ -4174,13 +4148,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
4174
4148
|
const key = "a";
|
|
4175
4149
|
const limit = 3;
|
|
4176
4150
|
const ttl1 = null;
|
|
4177
|
-
const semaphore1 =
|
|
4151
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
4178
4152
|
ttl: ttl1,
|
|
4179
4153
|
limit,
|
|
4180
4154
|
});
|
|
4181
4155
|
await semaphore1.acquire();
|
|
4182
4156
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
4183
|
-
const semaphore2 =
|
|
4157
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
4184
4158
|
ttl: ttl2,
|
|
4185
4159
|
limit,
|
|
4186
4160
|
});
|
|
@@ -4197,16 +4171,19 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
4197
4171
|
});
|
|
4198
4172
|
});
|
|
4199
4173
|
test("Should return ISemaphoreAcquiredState when is derserialized and slot is unexpired", async () => {
|
|
4174
|
+
expect.addEqualityTesters([
|
|
4175
|
+
createIsTimeSpanEqualityTester(timeSpanEqualityBuffer),
|
|
4176
|
+
]);
|
|
4200
4177
|
const key = "a";
|
|
4201
4178
|
const limit = 3;
|
|
4202
4179
|
const ttl1 = null;
|
|
4203
|
-
const semaphore1 =
|
|
4180
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
4204
4181
|
ttl: ttl1,
|
|
4205
4182
|
limit,
|
|
4206
4183
|
});
|
|
4207
4184
|
await semaphore1.acquire();
|
|
4208
4185
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
4209
|
-
const semaphore2 =
|
|
4186
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
4210
4187
|
ttl: ttl2,
|
|
4211
4188
|
limit,
|
|
4212
4189
|
});
|
|
@@ -4226,13 +4203,13 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
4226
4203
|
const key = "a";
|
|
4227
4204
|
const limit = 1;
|
|
4228
4205
|
const ttl1 = null;
|
|
4229
|
-
const semaphore1 =
|
|
4206
|
+
const semaphore1 = semaphoreFactory.create(key, {
|
|
4230
4207
|
ttl: ttl1,
|
|
4231
4208
|
limit,
|
|
4232
4209
|
});
|
|
4233
4210
|
await semaphore1.acquire();
|
|
4234
4211
|
const ttl2 = TimeSpan.fromMilliseconds(50);
|
|
4235
|
-
const semaphore2 =
|
|
4212
|
+
const semaphore2 = semaphoreFactory.create(key, {
|
|
4236
4213
|
ttl: ttl2,
|
|
4237
4214
|
limit,
|
|
4238
4215
|
});
|
|
@@ -4249,4 +4226,4 @@ export function semaphoreProviderTestSuite(settings) {
|
|
|
4249
4226
|
}
|
|
4250
4227
|
});
|
|
4251
4228
|
}
|
|
4252
|
-
//# sourceMappingURL=semaphore-
|
|
4229
|
+
//# sourceMappingURL=semaphore-factory.test-suite.js.map
|