@daiso-tech/core 0.42.0 → 0.44.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 +19 -9
- package/dist/backoff-policies/_module-exports.d.ts +5 -4
- package/dist/backoff-policies/_module-exports.js +5 -4
- package/dist/backoff-policies/_module-exports.js.map +1 -1
- package/dist/backoff-policies/_module.d.ts +7 -0
- package/dist/backoff-policies/_module.js +8 -0
- package/dist/backoff-policies/_module.js.map +1 -0
- package/dist/backoff-policies/_shared.d.ts +8 -3
- package/dist/backoff-policies/_shared.js +57 -2
- package/dist/backoff-policies/_shared.js.map +1 -1
- package/dist/backoff-policies/backoffs-lua.d.ts +7 -0
- package/dist/backoff-policies/backoffs-lua.js +78 -0
- package/dist/backoff-policies/backoffs-lua.js.map +1 -0
- package/dist/backoff-policies/constant-backoff/_module.d.ts +1 -0
- package/dist/backoff-policies/constant-backoff/_module.js +2 -0
- package/dist/backoff-policies/constant-backoff/_module.js.map +1 -0
- package/dist/backoff-policies/constant-backoff/constant-backoff.d.ts +53 -0
- package/dist/backoff-policies/constant-backoff/constant-backoff.js +54 -0
- package/dist/backoff-policies/constant-backoff/constant-backoff.js.map +1 -0
- package/dist/backoff-policies/exponential-backoff/_module.d.ts +1 -0
- package/dist/backoff-policies/exponential-backoff/_module.js +2 -0
- package/dist/backoff-policies/exponential-backoff/_module.js.map +1 -0
- package/dist/backoff-policies/exponential-backoff/exponential-backoff.d.ts +68 -0
- package/dist/backoff-policies/exponential-backoff/exponential-backoff.js +59 -0
- package/dist/backoff-policies/exponential-backoff/exponential-backoff.js.map +1 -0
- package/dist/backoff-policies/linear-backoff/_module.d.ts +1 -0
- package/dist/backoff-policies/linear-backoff/_module.js +2 -0
- package/dist/backoff-policies/linear-backoff/_module.js.map +1 -0
- package/dist/backoff-policies/linear-backoff/linear-backoff.d.ts +63 -0
- package/dist/backoff-policies/linear-backoff/linear-backoff.js +57 -0
- package/dist/backoff-policies/linear-backoff/linear-backoff.js.map +1 -0
- package/dist/backoff-policies/polynomial-backoff/_module.d.ts +1 -0
- package/dist/backoff-policies/polynomial-backoff/_module.js +2 -0
- package/dist/backoff-policies/polynomial-backoff/_module.js.map +1 -0
- package/dist/backoff-policies/polynomial-backoff/polynomial-backoff.d.ts +68 -0
- package/dist/backoff-policies/polynomial-backoff/polynomial-backoff.js +59 -0
- package/dist/backoff-policies/polynomial-backoff/polynomial-backoff.js.map +1 -0
- package/dist/backoff-policies/types.d.ts +83 -0
- package/dist/backoff-policies/types.js +18 -0
- package/dist/backoff-policies/types.js.map +1 -0
- package/dist/cache/contracts/_module-exports.d.ts +5 -4
- package/dist/cache/contracts/_module-exports.js +0 -4
- package/dist/cache/contracts/_module-exports.js.map +1 -1
- package/dist/cache/contracts/_module.d.ts +7 -0
- package/dist/cache/contracts/_module.js +3 -0
- package/dist/cache/contracts/_module.js.map +1 -0
- package/dist/cache/contracts/cache-adapter.contract.d.ts +1 -1
- package/dist/cache/contracts/cache-adapter.contract.js +4 -1
- package/dist/cache/contracts/cache-adapter.contract.js.map +1 -1
- package/dist/cache/contracts/cache-factory.contract.d.ts +1 -1
- package/dist/cache/contracts/cache-factory.contract.js +2 -1
- package/dist/cache/contracts/cache-factory.contract.js.map +1 -1
- package/dist/cache/contracts/cache.contract.d.ts +79 -76
- package/dist/cache/contracts/cache.contract.js +10 -1
- package/dist/cache/contracts/cache.contract.js.map +1 -1
- package/dist/cache/contracts/cache.errors.d.ts +22 -0
- package/dist/cache/contracts/cache.errors.js +29 -0
- package/dist/cache/contracts/cache.errors.js.map +1 -1
- package/dist/cache/contracts/cache.events.d.ts +19 -22
- package/dist/cache/contracts/cache.events.js +8 -1
- package/dist/cache/contracts/cache.events.js.map +1 -1
- package/dist/cache/contracts/types.d.ts +18 -0
- package/dist/cache/contracts/types.js +7 -0
- package/dist/cache/contracts/types.js.map +1 -0
- package/dist/cache/implementations/adapters/_module.d.ts +5 -5
- package/dist/cache/implementations/adapters/_module.js +5 -5
- package/dist/cache/implementations/adapters/_module.js.map +1 -1
- package/dist/cache/implementations/adapters/kysely-cache-adapter/_module.d.ts +1 -0
- package/dist/cache/implementations/adapters/kysely-cache-adapter/_module.js +2 -0
- package/dist/cache/implementations/adapters/kysely-cache-adapter/_module.js.map +1 -0
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.d.ts +14 -7
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js +13 -5
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/memory-cache-adapter/_module.d.ts +1 -0
- package/dist/cache/implementations/adapters/memory-cache-adapter/_module.js +2 -0
- package/dist/cache/implementations/adapters/memory-cache-adapter/_module.js.map +1 -0
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.d.ts +2 -2
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js +2 -1
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/_module.d.ts +1 -0
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/_module.js +2 -0
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/_module.js.map +1 -0
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter-serde.d.ts +1 -1
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter-serde.js +1 -1
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter-serde.js.map +1 -1
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.d.ts +5 -6
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js +8 -5
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/no-op-cache-adapter/_module.d.ts +1 -0
- package/dist/cache/implementations/adapters/no-op-cache-adapter/_module.js +2 -0
- package/dist/cache/implementations/adapters/no-op-cache-adapter/_module.js.map +1 -0
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.d.ts +2 -2
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js +2 -1
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/_module.d.ts +1 -0
- package/dist/cache/implementations/adapters/redis-cache-adapter/_module.js +2 -0
- package/dist/cache/implementations/adapters/redis-cache-adapter/_module.js.map +1 -0
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter-serde.d.ts +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter-serde.js +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter-serde.js.map +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.d.ts +3 -3
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js +6 -2
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/utilities.js +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/utilities.js.map +1 -1
- package/dist/cache/implementations/derivables/_module.d.ts +2 -0
- package/dist/cache/implementations/derivables/_module.js +3 -0
- package/dist/cache/implementations/derivables/_module.js.map +1 -0
- package/dist/cache/implementations/derivables/cache/_module.d.ts +1 -0
- package/dist/cache/implementations/derivables/cache/_module.js +1 -0
- package/dist/cache/implementations/derivables/cache/_module.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/cache.d.ts +44 -39
- package/dist/cache/implementations/derivables/cache/cache.js +139 -78
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/database-cache-adapter.d.ts +2 -2
- package/dist/cache/implementations/derivables/cache/database-cache-adapter.js +2 -1
- package/dist/cache/implementations/derivables/cache/database-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/is-database-cache-adapter.d.ts +2 -3
- package/dist/cache/implementations/derivables/cache/is-database-cache-adapter.js +9 -2
- package/dist/cache/implementations/derivables/cache/is-database-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/resolve-cache-adapter.d.ts +8 -0
- package/dist/cache/implementations/derivables/cache/resolve-cache-adapter.js +16 -0
- package/dist/cache/implementations/derivables/cache/resolve-cache-adapter.js.map +1 -0
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +8 -7
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +13 -2
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
- package/dist/cache/implementations/test-utilities/_module.d.ts +3 -0
- package/dist/cache/implementations/test-utilities/_module.js +4 -0
- package/dist/cache/implementations/test-utilities/_module.js.map +1 -0
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.d.ts +2 -2
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js +4 -4
- 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 +6 -2
- package/dist/cache/implementations/test-utilities/cache.test-suite.js +1479 -607
- package/dist/cache/implementations/test-utilities/cache.test-suite.js.map +1 -1
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.d.ts +2 -2
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js +3 -3
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js.map +1 -1
- package/dist/circuit-breaker/contracts/_module-exports.d.ts +9 -0
- package/dist/circuit-breaker/contracts/_module-exports.js +6 -0
- package/dist/circuit-breaker/contracts/_module-exports.js.map +1 -0
- package/dist/circuit-breaker/contracts/_module.d.ts +9 -0
- package/dist/circuit-breaker/contracts/_module.js +6 -0
- package/dist/circuit-breaker/contracts/_module.js.map +1 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-adapter.contract.d.ts +45 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-adapter.contract.js +7 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-adapter.contract.js.map +1 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-policy.contract.d.ts +114 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-policy.contract.js +41 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-policy.contract.js.map +1 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-provider-factory.contract.d.ts +19 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-provider-factory.contract.js +10 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-provider-factory.contract.js.map +1 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-provider.contract.d.ts +63 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-provider.contract.js +19 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-provider.contract.js.map +1 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-state.contract.d.ts +20 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-state.contract.js +15 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-state.contract.js.map +1 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-storage-adapter.contract.d.ts +52 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-storage-adapter.contract.js +5 -0
- package/dist/circuit-breaker/contracts/circuit-breaker-storage-adapter.contract.js.map +1 -0
- package/dist/circuit-breaker/contracts/circuit-breaker.contract.d.ts +40 -0
- package/dist/circuit-breaker/contracts/circuit-breaker.contract.js +9 -0
- package/dist/circuit-breaker/contracts/circuit-breaker.contract.js.map +1 -0
- package/dist/circuit-breaker/contracts/circuit-breaker.errors.d.ts +49 -0
- package/dist/circuit-breaker/contracts/circuit-breaker.errors.js +61 -0
- package/dist/circuit-breaker/contracts/circuit-breaker.errors.js.map +1 -0
- package/dist/circuit-breaker/contracts/circuit-breaker.events.d.ts +96 -0
- package/dist/circuit-breaker/contracts/circuit-breaker.events.js +20 -0
- package/dist/circuit-breaker/contracts/circuit-breaker.events.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/_module.d.ts +7 -0
- package/dist/circuit-breaker/implementations/adapters/_module.js +8 -0
- package/dist/circuit-breaker/implementations/adapters/_module.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/_module-exports.d.ts +1 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/_module-exports.js +2 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/_module-exports.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/_module.d.ts +1 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/_module.js +2 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/_module.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/circuit-breaker-state-manager.d.ts +18 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/circuit-breaker-state-manager.js +57 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/circuit-breaker-state-manager.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/circuit-breaker-storage.d.ts +17 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/circuit-breaker-storage.js +40 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/circuit-breaker-storage.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/database-circuit-breaker-adapter.d.ts +59 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/database-circuit-breaker-adapter.js +57 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/database-circuit-breaker-adapter.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/internal-circuit-breaker-policy.d.ts +65 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/internal-circuit-breaker-policy.js +128 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/internal-circuit-breaker-policy.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/types.d.ts +12 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/types.js +6 -0
- package/dist/circuit-breaker/implementations/adapters/database-circuit-breaker-adapter/types.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/kysely-circuit-breaker-storage-adapter/_module-exports.d.ts +1 -0
- package/dist/circuit-breaker/implementations/adapters/kysely-circuit-breaker-storage-adapter/_module-exports.js +2 -0
- package/dist/circuit-breaker/implementations/adapters/kysely-circuit-breaker-storage-adapter/_module-exports.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/kysely-circuit-breaker-storage-adapter/_module.d.ts +1 -0
- package/dist/circuit-breaker/implementations/adapters/kysely-circuit-breaker-storage-adapter/_module.js +2 -0
- package/dist/circuit-breaker/implementations/adapters/kysely-circuit-breaker-storage-adapter/_module.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/kysely-circuit-breaker-storage-adapter/kysely-circuit-breaker-storage-adapter.d.ts +81 -0
- package/dist/circuit-breaker/implementations/adapters/kysely-circuit-breaker-storage-adapter/kysely-circuit-breaker-storage-adapter.js +149 -0
- package/dist/circuit-breaker/implementations/adapters/kysely-circuit-breaker-storage-adapter/kysely-circuit-breaker-storage-adapter.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/memory-circuit-breaker-storage-adapter/_module-exports.d.ts +1 -0
- package/dist/circuit-breaker/implementations/adapters/memory-circuit-breaker-storage-adapter/_module-exports.js +2 -0
- package/dist/circuit-breaker/implementations/adapters/memory-circuit-breaker-storage-adapter/_module-exports.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/memory-circuit-breaker-storage-adapter/_module.d.ts +1 -0
- package/dist/circuit-breaker/implementations/adapters/memory-circuit-breaker-storage-adapter/_module.js +2 -0
- package/dist/circuit-breaker/implementations/adapters/memory-circuit-breaker-storage-adapter/_module.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/memory-circuit-breaker-storage-adapter/memory-circuit-breaker-storage-adapter.d.ts +42 -0
- package/dist/circuit-breaker/implementations/adapters/memory-circuit-breaker-storage-adapter/memory-circuit-breaker-storage-adapter.js +60 -0
- package/dist/circuit-breaker/implementations/adapters/memory-circuit-breaker-storage-adapter/memory-circuit-breaker-storage-adapter.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/mongodb-circuit-breaker-storage-adapter/_module-exports.d.ts +1 -0
- package/dist/circuit-breaker/implementations/adapters/mongodb-circuit-breaker-storage-adapter/_module-exports.js +2 -0
- package/dist/circuit-breaker/implementations/adapters/mongodb-circuit-breaker-storage-adapter/_module-exports.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/mongodb-circuit-breaker-storage-adapter/_module.d.ts +1 -0
- package/dist/circuit-breaker/implementations/adapters/mongodb-circuit-breaker-storage-adapter/_module.js +2 -0
- package/dist/circuit-breaker/implementations/adapters/mongodb-circuit-breaker-storage-adapter/_module.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/mongodb-circuit-breaker-storage-adapter/mongodb-circuit-breaker-storage-adapter.d.ts +80 -0
- package/dist/circuit-breaker/implementations/adapters/mongodb-circuit-breaker-storage-adapter/mongodb-circuit-breaker-storage-adapter.js +115 -0
- package/dist/circuit-breaker/implementations/adapters/mongodb-circuit-breaker-storage-adapter/mongodb-circuit-breaker-storage-adapter.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-adapter/_module-exports.d.ts +1 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-adapter/_module-exports.js +2 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-adapter/_module-exports.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-adapter/_module.d.ts +1 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-adapter/_module.js +2 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-adapter/_module.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-adapter/no-op-circuit-breaker-adapter.d.ts +16 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-adapter/no-op-circuit-breaker-adapter.js +32 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-adapter/no-op-circuit-breaker-adapter.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-storage-adapter/_module-exports.d.ts +1 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-storage-adapter/_module-exports.js +2 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-storage-adapter/_module-exports.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-storage-adapter/_module.d.ts +1 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-storage-adapter/_module.js +2 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-storage-adapter/_module.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-storage-adapter/no-op-circuit-breaker-storage-adapter.d.ts +16 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-storage-adapter/no-op-circuit-breaker-storage-adapter.js +24 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-storage-adapter/no-op-circuit-breaker-storage-adapter.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/_module-exports.d.ts +1 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/_module-exports.js +2 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/_module-exports.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/_module.d.ts +1 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/_module.js +2 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/_module.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/_module.d.ts +1 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/_module.js +2 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/_module.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/circuit-breaker-factory-lua.d.ts +4 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/circuit-breaker-factory-lua.js +76 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/circuit-breaker-factory-lua.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/circuit-breaker-lua.d.ts +7 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/circuit-breaker-lua.js +34 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/circuit-breaker-lua.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/circuit-breaker-state-manager-lua.d.ts +7 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/circuit-breaker-state-manager-lua.js +64 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/circuit-breaker-state-manager-lua.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/circuit-breaker-storage-lua.d.ts +7 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/circuit-breaker-storage-lua.js +39 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/circuit-breaker-storage-lua.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/consecutive-breaker-lua.d.ts +7 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/consecutive-breaker-lua.js +75 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/consecutive-breaker-lua.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/count-breaker-lua.d.ts +7 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/count-breaker-lua.js +136 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/count-breaker-lua.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/internal-circuit-breaker-policy-lua.d.ts +7 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/internal-circuit-breaker-policy-lua.js +144 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/internal-circuit-breaker-policy-lua.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/sampling-breaker-lua.d.ts +7 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/sampling-breaker-lua.js +153 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/lua/sampling-breaker-lua.js.map +1 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/redis-circuit-breaker-adapter.d.ts +68 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/redis-circuit-breaker-adapter.js +131 -0
- package/dist/circuit-breaker/implementations/adapters/redis-circuit-breaker-adapter/redis-circuit-breaker-adapter.js.map +1 -0
- package/dist/circuit-breaker/implementations/derivables/_module-exports.d.ts +2 -0
- package/dist/circuit-breaker/implementations/derivables/_module-exports.js +3 -0
- package/dist/circuit-breaker/implementations/derivables/_module-exports.js.map +1 -0
- package/dist/circuit-breaker/implementations/derivables/_module.d.ts +2 -0
- package/dist/circuit-breaker/implementations/derivables/_module.js +3 -0
- package/dist/circuit-breaker/implementations/derivables/_module.js.map +1 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/_module.d.ts +1 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/_module.js +2 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/_module.js.map +1 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-provider.d.ts +154 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-provider.js +138 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-provider.js.map +1 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-serde-transformer.d.ts +41 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-serde-transformer.js +77 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-serde-transformer.js.map +1 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker.d.ts +62 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker.js +201 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker.js.map +1 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/_module.d.ts +2 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/_module.js +3 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/_module.js.map +1 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/circuit-breaker-provider-factory.d.ts +108 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/circuit-breaker-provider-factory.js +140 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/circuit-breaker-provider-factory.js.map +1 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/database-circuit-breaker-provider-factory.d.ts +137 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/database-circuit-breaker-provider-factory.js +164 -0
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/database-circuit-breaker-provider-factory.js.map +1 -0
- package/dist/circuit-breaker/implementations/policies/_module-exports.d.ts +5 -0
- package/dist/circuit-breaker/implementations/policies/_module-exports.js +6 -0
- package/dist/circuit-breaker/implementations/policies/_module-exports.js.map +1 -0
- package/dist/circuit-breaker/implementations/policies/_module.d.ts +5 -0
- package/dist/circuit-breaker/implementations/policies/_module.js +6 -0
- package/dist/circuit-breaker/implementations/policies/_module.js.map +1 -0
- package/dist/circuit-breaker/implementations/policies/_shared.d.ts +12 -0
- package/dist/circuit-breaker/implementations/policies/_shared.js +50 -0
- package/dist/circuit-breaker/implementations/policies/_shared.js.map +1 -0
- package/dist/circuit-breaker/implementations/policies/consecutive-breaker/_module.d.ts +1 -0
- package/dist/circuit-breaker/implementations/policies/consecutive-breaker/_module.js +2 -0
- package/dist/circuit-breaker/implementations/policies/consecutive-breaker/_module.js.map +1 -0
- package/dist/circuit-breaker/implementations/policies/consecutive-breaker/consecutive-breaker.d.ts +51 -0
- package/dist/circuit-breaker/implementations/policies/consecutive-breaker/consecutive-breaker.js +85 -0
- package/dist/circuit-breaker/implementations/policies/consecutive-breaker/consecutive-breaker.js.map +1 -0
- package/dist/circuit-breaker/implementations/policies/count-breaker/_module.d.ts +1 -0
- package/dist/circuit-breaker/implementations/policies/count-breaker/_module.js +2 -0
- package/dist/circuit-breaker/implementations/policies/count-breaker/_module.js.map +1 -0
- package/dist/circuit-breaker/implementations/policies/count-breaker/count-breaker.d.ts +74 -0
- package/dist/circuit-breaker/implementations/policies/count-breaker/count-breaker.js +130 -0
- package/dist/circuit-breaker/implementations/policies/count-breaker/count-breaker.js.map +1 -0
- package/dist/circuit-breaker/implementations/policies/sampling-breaker/_module.d.ts +1 -0
- package/dist/circuit-breaker/implementations/policies/sampling-breaker/_module.js +2 -0
- package/dist/circuit-breaker/implementations/policies/sampling-breaker/_module.js.map +1 -0
- package/dist/circuit-breaker/implementations/policies/sampling-breaker/sampling-breaker.d.ts +112 -0
- package/dist/circuit-breaker/implementations/policies/sampling-breaker/sampling-breaker.js +159 -0
- package/dist/circuit-breaker/implementations/policies/sampling-breaker/sampling-breaker.js.map +1 -0
- package/dist/circuit-breaker/implementations/policies/types.d.ts +51 -0
- package/dist/circuit-breaker/implementations/policies/types.js +16 -0
- package/dist/circuit-breaker/implementations/policies/types.js.map +1 -0
- package/dist/circuit-breaker/implementations/test-utilities/_module-exports.d.ts +4 -0
- package/dist/circuit-breaker/implementations/test-utilities/_module-exports.js +5 -0
- package/dist/circuit-breaker/implementations/test-utilities/_module-exports.js.map +1 -0
- package/dist/circuit-breaker/implementations/test-utilities/_module.d.ts +4 -0
- package/dist/circuit-breaker/implementations/test-utilities/_module.js +5 -0
- package/dist/circuit-breaker/implementations/test-utilities/_module.js.map +1 -0
- package/dist/circuit-breaker/implementations/test-utilities/circuit-breaker-storage-adapter.test-suite.d.ts +45 -0
- package/dist/circuit-breaker/implementations/test-utilities/circuit-breaker-storage-adapter.test-suite.js +110 -0
- package/dist/circuit-breaker/implementations/test-utilities/circuit-breaker-storage-adapter.test-suite.js.map +1 -0
- package/dist/circuit-breaker/implementations/test-utilities/consecutive-breaker.test-suite.d.ts +60 -0
- package/dist/circuit-breaker/implementations/test-utilities/consecutive-breaker.test-suite.js +454 -0
- package/dist/circuit-breaker/implementations/test-utilities/consecutive-breaker.test-suite.js.map +1 -0
- package/dist/circuit-breaker/implementations/test-utilities/count-breaker.test-suite.d.ts +60 -0
- package/dist/circuit-breaker/implementations/test-utilities/count-breaker.test-suite.js +704 -0
- package/dist/circuit-breaker/implementations/test-utilities/count-breaker.test-suite.js.map +1 -0
- package/dist/circuit-breaker/implementations/test-utilities/sampling-breaker.test-suite.d.ts +60 -0
- package/dist/circuit-breaker/implementations/test-utilities/sampling-breaker.test-suite.js +95 -0
- package/dist/circuit-breaker/implementations/test-utilities/sampling-breaker.test-suite.js.map +1 -0
- package/dist/collection/contracts/_module-exports.d.ts +3 -3
- package/dist/collection/contracts/_module-exports.js +0 -3
- package/dist/collection/contracts/_module-exports.js.map +1 -1
- package/dist/collection/contracts/_module.d.ts +4 -0
- package/dist/collection/contracts/_module.js +2 -0
- package/dist/collection/contracts/_module.js.map +1 -0
- package/dist/collection/contracts/_shared/_module.d.ts +11 -11
- package/dist/collection/contracts/_shared/_module.js +1 -11
- package/dist/collection/contracts/_shared/_module.js.map +1 -1
- package/dist/collection/contracts/_shared/compartor.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/compartor.type.js +1 -1
- package/dist/collection/contracts/_shared/compartor.type.js.map +1 -1
- package/dist/collection/contracts/_shared/foreach.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/foreach.type.js +1 -1
- package/dist/collection/contracts/_shared/foreach.type.js.map +1 -1
- package/dist/collection/contracts/_shared/map.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/map.type.js +1 -1
- package/dist/collection/contracts/_shared/map.type.js.map +1 -1
- package/dist/collection/contracts/_shared/modifier.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/modifier.type.js +1 -1
- package/dist/collection/contracts/_shared/modifier.type.js.map +1 -1
- package/dist/collection/contracts/_shared/predicate.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/predicate.type.js +1 -1
- package/dist/collection/contracts/_shared/predicate.type.js.map +1 -1
- package/dist/collection/contracts/_shared/reduce.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/reduce.type.js +1 -1
- package/dist/collection/contracts/_shared/reduce.type.js.map +1 -1
- package/dist/collection/contracts/_shared/tap.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/tap.type.js +1 -1
- package/dist/collection/contracts/_shared/tap.type.js.map +1 -1
- package/dist/collection/contracts/_shared/transform.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/transform.type.js +1 -1
- package/dist/collection/contracts/_shared/transform.type.js.map +1 -1
- package/dist/collection/contracts/async-collection.contract.d.ts +54 -54
- package/dist/collection/contracts/async-collection.contract.js +5 -1
- package/dist/collection/contracts/async-collection.contract.js.map +1 -1
- package/dist/collection/contracts/collection.contract.d.ts +12 -12
- package/dist/collection/contracts/collection.contract.js +5 -1
- package/dist/collection/contracts/collection.contract.js.map +1 -1
- package/dist/collection/contracts/collection.errors.d.ts +18 -10
- package/dist/collection/contracts/collection.errors.js +24 -13
- package/dist/collection/contracts/collection.errors.js.map +1 -1
- package/dist/collection/implementations/_module.d.ts +4 -0
- package/dist/collection/implementations/_module.js +5 -0
- package/dist/collection/implementations/_module.js.map +1 -0
- package/dist/collection/implementations/_shared.d.ts +0 -23
- package/dist/collection/implementations/_shared.js +0 -41
- package/dist/collection/implementations/_shared.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-chunk-iterable.d.ts +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-chunk-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-chunk-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-chunk-while-iterable.d.ts +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-chunk-while-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-chunk-while-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-collapse-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-collapse-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-collapse-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-count-by-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-count-by-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-count-by-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-cross-join-iterable.d.ts +2 -3
- package/dist/collection/implementations/async-iterable-collection/_shared/async-cross-join-iterable.js +3 -4
- package/dist/collection/implementations/async-iterable-collection/_shared/async-cross-join-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-entries-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-entries-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-entries-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-filter-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-filter-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-filter-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-flat-map-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-flat-map-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-flat-map-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-group-by-iterable.d.ts +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-group-by-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-group-by-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-insert-after-iterable.d.ts +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-insert-after-iterable.js +3 -3
- package/dist/collection/implementations/async-iterable-collection/_shared/async-insert-after-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-insert-before-iterable.d.ts +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-insert-before-iterable.js +3 -3
- package/dist/collection/implementations/async-iterable-collection/_shared/async-insert-before-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-map-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-map-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-map-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-merge-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-merge-iterable.js +4 -5
- package/dist/collection/implementations/async-iterable-collection/_shared/async-merge-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-pad-end-iterable.d.ts +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-pad-end-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-pad-end-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-pad-start-iterable.d.ts +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-pad-start-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-pad-start-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-partion-iterable.d.ts +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-partion-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-partion-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-repeat-iterable.d.ts +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-repeat-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-repeat-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-reverse-iterable.d.ts +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-reverse-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-reverse-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-shuffle-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-shuffle-iterable.js +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-shuffle-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-skip-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-skip-iterable.js +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-skip-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-skip-until-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-skip-until-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-skip-until-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-slice-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-slice-iterable.js +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-slice-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-sliding-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-sliding-iterable.js +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-sliding-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-sort-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-sort-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-sort-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-split-iterable.d.ts +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-split-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-split-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-iterable.js +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-tap-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-tap-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-tap-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-unique-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-unique-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-unique-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-update-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-update-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-update-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-validate-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-validate-iterable.js +4 -0
- package/dist/collection/implementations/async-iterable-collection/_shared/async-validate-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-when-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-when-iterable.js +2 -2
- package/dist/collection/implementations/async-iterable-collection/_shared/async-when-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-zip-iterable.d.ts +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-zip-iterable.js +3 -16
- package/dist/collection/implementations/async-iterable-collection/_shared/async-zip-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.d.ts +43 -44
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +32 -32
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/chunk-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/chunk-iterable.js +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/chunk-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/chunk-while-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/chunk-while-iterable.js +2 -2
- package/dist/collection/implementations/iterable-collection/_shared/chunk-while-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/collapse-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/collapse-iterable.js +2 -2
- package/dist/collection/implementations/iterable-collection/_shared/collapse-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/count-by-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/count-by-iterable.js +2 -2
- package/dist/collection/implementations/iterable-collection/_shared/count-by-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/cross-join-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/cross-join-iterable.js +2 -1
- package/dist/collection/implementations/iterable-collection/_shared/cross-join-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/filter-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/filter-iterable.js +2 -2
- package/dist/collection/implementations/iterable-collection/_shared/filter-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/flat-map-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/flat-map-iterable.js +2 -2
- package/dist/collection/implementations/iterable-collection/_shared/flat-map-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/group-by-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/group-by-iterable.js +2 -2
- package/dist/collection/implementations/iterable-collection/_shared/group-by-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/insert-after-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/insert-after-iterable.js +2 -2
- package/dist/collection/implementations/iterable-collection/_shared/insert-after-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/insert-before-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/insert-before-iterable.js +2 -2
- package/dist/collection/implementations/iterable-collection/_shared/insert-before-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/map-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/map-iterable.js +2 -2
- package/dist/collection/implementations/iterable-collection/_shared/map-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/merge-iterable.d.ts +2 -1
- package/dist/collection/implementations/iterable-collection/_shared/merge-iterable.js +3 -2
- package/dist/collection/implementations/iterable-collection/_shared/merge-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/pad-end-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/pad-end-iterable.js +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/pad-end-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/pad-start-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/pad-start-iterable.js +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/pad-start-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/partion-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/partion-iterable.js +2 -2
- package/dist/collection/implementations/iterable-collection/_shared/partion-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/repeat-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/repeat-iterable.js +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/repeat-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/reverse-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/reverse-iterable.js +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/reverse-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/skip-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/skip-iterable.js +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/skip-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/skip-until-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/skip-until-iterable.js +2 -2
- package/dist/collection/implementations/iterable-collection/_shared/skip-until-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/slice-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/slice-iterable.js +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/slice-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/sliding-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/sliding-iterable.js +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/sliding-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/sort-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/sort-iterable.js +2 -2
- package/dist/collection/implementations/iterable-collection/_shared/sort-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/split-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/split-iterable.js +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/split-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/take-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/take-iterable.js +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/take-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/take-until-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/take-until-iterable.js +2 -2
- package/dist/collection/implementations/iterable-collection/_shared/take-until-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/tap-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/tap-iterable.js +2 -2
- package/dist/collection/implementations/iterable-collection/_shared/tap-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/unique-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/unique-iterable.js +2 -2
- package/dist/collection/implementations/iterable-collection/_shared/unique-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/update-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/update-iterable.js +2 -2
- package/dist/collection/implementations/iterable-collection/_shared/update-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/validate-iterable.d.ts +4 -1
- package/dist/collection/implementations/iterable-collection/_shared/validate-iterable.js +2 -1
- package/dist/collection/implementations/iterable-collection/_shared/validate-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/when-iterable.d.ts +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/when-iterable.js +2 -2
- package/dist/collection/implementations/iterable-collection/_shared/when-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/iterable-collection.d.ts +17 -18
- package/dist/collection/implementations/iterable-collection/iterable-collection.js +39 -40
- package/dist/collection/implementations/iterable-collection/iterable-collection.js.map +1 -1
- package/dist/collection/implementations/list-collection/list-collection.d.ts +16 -17
- package/dist/collection/implementations/list-collection/list-collection.js +45 -41
- package/dist/collection/implementations/list-collection/list-collection.js.map +1 -1
- package/dist/event-bus/contracts/_module-exports.d.ts +3 -3
- package/dist/event-bus/contracts/_module-exports.js +1 -3
- package/dist/event-bus/contracts/_module-exports.js.map +1 -1
- package/dist/event-bus/contracts/_module.d.ts +3 -0
- package/dist/event-bus/contracts/_module.js +2 -0
- package/dist/event-bus/contracts/_module.js.map +1 -0
- package/dist/event-bus/contracts/event-bus-adapter.contract.d.ts +21 -8
- package/dist/event-bus/contracts/event-bus-adapter.contract.js +1 -1
- package/dist/event-bus/contracts/event-bus-adapter.contract.js.map +1 -1
- package/dist/event-bus/contracts/event-bus-factory.contract.d.ts +1 -1
- package/dist/event-bus/contracts/event-bus-factory.contract.js +2 -1
- package/dist/event-bus/contracts/event-bus-factory.contract.js.map +1 -1
- package/dist/event-bus/contracts/event-bus.contract.d.ts +12 -12
- package/dist/event-bus/contracts/event-bus.contract.js +3 -1
- package/dist/event-bus/contracts/event-bus.contract.js.map +1 -1
- package/dist/event-bus/implementations/adapters/_module.d.ts +3 -3
- package/dist/event-bus/implementations/adapters/_module.js +3 -3
- package/dist/event-bus/implementations/adapters/_module.js.map +1 -1
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/_module.d.ts +1 -0
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/_module.js +2 -0
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/_module.js.map +1 -0
- 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 -0
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js.map +1 -1
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/_module.d.ts +1 -0
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/_module.js +2 -0
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/_module.js.map +1 -0
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.d.ts +1 -2
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.js +1 -0
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.js.map +1 -1
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/_module.d.ts +1 -0
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/_module.js +2 -0
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/_module.js.map +1 -0
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.d.ts +3 -3
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js +4 -2
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js.map +1 -1
- package/dist/event-bus/implementations/derivables/_module.d.ts +2 -0
- package/dist/event-bus/implementations/derivables/_module.js +3 -0
- package/dist/event-bus/implementations/derivables/_module.js.map +1 -0
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +11 -13
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +7 -6
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus/listener-store.d.ts +1 -1
- package/dist/event-bus/implementations/derivables/event-bus/listener-store.js +2 -1
- package/dist/event-bus/implementations/derivables/event-bus/listener-store.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.d.ts +3 -5
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +4 -5
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
- package/dist/event-bus/implementations/test-utilities/_module.d.ts +2 -0
- package/dist/event-bus/implementations/test-utilities/_module.js +3 -0
- package/dist/event-bus/implementations/test-utilities/_module.js.map +1 -0
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.d.ts +2 -2
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js +4 -3
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js.map +1 -1
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.d.ts +2 -2
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js +6 -6
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js.map +1 -1
- package/dist/hooks/_module-exports.d.ts +1 -1
- package/dist/hooks/_module-exports.js +0 -1
- package/dist/hooks/_module-exports.js.map +1 -1
- package/dist/hooks/_module.d.ts +3 -0
- package/dist/hooks/_module.js +3 -0
- package/dist/hooks/_module.js.map +1 -0
- package/dist/hooks/async-hooks.d.ts +3 -3
- package/dist/hooks/async-hooks.js +8 -5
- package/dist/hooks/async-hooks.js.map +1 -1
- package/dist/hooks/hooks.d.ts +2 -2
- package/dist/hooks/hooks.js +2 -1
- package/dist/hooks/hooks.js.map +1 -1
- package/dist/lock/contracts/_module-exports.d.ts +6 -6
- package/dist/lock/contracts/_module-exports.js +0 -6
- package/dist/lock/contracts/_module-exports.js.map +1 -1
- package/dist/lock/contracts/_module.d.ts +9 -0
- package/dist/lock/contracts/_module.js +4 -0
- package/dist/lock/contracts/_module.js.map +1 -0
- package/dist/lock/contracts/database-lock-adapter.contract.d.ts +8 -3
- package/dist/lock/contracts/database-lock-adapter.contract.js +1 -1
- package/dist/lock/contracts/database-lock-adapter.contract.js.map +1 -1
- package/dist/lock/contracts/lock-adapter.contract.d.ts +1 -1
- package/dist/lock/contracts/lock-adapter.contract.js +3 -1
- package/dist/lock/contracts/lock-adapter.contract.js.map +1 -1
- package/dist/lock/contracts/lock-provider-factory.contract.d.ts +1 -1
- package/dist/lock/contracts/lock-provider-factory.contract.js +2 -1
- package/dist/lock/contracts/lock-provider-factory.contract.js.map +1 -1
- package/dist/lock/contracts/lock-provider.contract.d.ts +4 -8
- package/dist/lock/contracts/lock-provider.contract.js +4 -1
- package/dist/lock/contracts/lock-provider.contract.js.map +1 -1
- package/dist/lock/contracts/lock-state.contract.d.ts +2 -2
- package/dist/lock/contracts/lock-state.contract.js +1 -0
- package/dist/lock/contracts/lock-state.contract.js.map +1 -1
- package/dist/lock/contracts/lock.contract.d.ts +18 -27
- package/dist/lock/contracts/lock.contract.js +5 -1
- package/dist/lock/contracts/lock.contract.js.map +1 -1
- package/dist/lock/contracts/lock.errors.d.ts +19 -0
- package/dist/lock/contracts/lock.errors.js +25 -0
- package/dist/lock/contracts/lock.errors.js.map +1 -1
- package/dist/lock/contracts/lock.events.d.ts +1 -1
- package/dist/lock/contracts/lock.events.js +2 -0
- package/dist/lock/contracts/lock.events.js.map +1 -1
- package/dist/lock/contracts/types.d.ts +2 -2
- package/dist/lock/contracts/types.js +2 -1
- package/dist/lock/contracts/types.js.map +1 -1
- package/dist/lock/implementations/adapters/_module.d.ts +5 -5
- package/dist/lock/implementations/adapters/_module.js +5 -5
- package/dist/lock/implementations/adapters/_module.js.map +1 -1
- package/dist/lock/implementations/adapters/kysely-lock-adapter/_module.d.ts +1 -0
- package/dist/lock/implementations/adapters/kysely-lock-adapter/_module.js +2 -0
- package/dist/lock/implementations/adapters/kysely-lock-adapter/_module.js.map +1 -0
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.d.ts +8 -13
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js +9 -8
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/memory-lock-adapter/_module.d.ts +1 -0
- package/dist/lock/implementations/adapters/memory-lock-adapter/_module.js +2 -0
- package/dist/lock/implementations/adapters/memory-lock-adapter/_module.js.map +1 -0
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.d.ts +7 -4
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +7 -1
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/_module.d.ts +1 -0
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/_module.js +2 -0
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/_module.js.map +1 -0
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.d.ts +4 -5
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +4 -1
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/no-op-lock-adapter/_module.d.ts +1 -0
- package/dist/lock/implementations/adapters/no-op-lock-adapter/_module.js +2 -0
- package/dist/lock/implementations/adapters/no-op-lock-adapter/_module.js.map +1 -0
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.d.ts +2 -2
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js +2 -0
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/redis-lock-adapter/_module.d.ts +1 -0
- package/dist/lock/implementations/adapters/redis-lock-adapter/_module.js +2 -0
- package/dist/lock/implementations/adapters/redis-lock-adapter/_module.js.map +1 -0
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.d.ts +3 -4
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +3 -0
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/_module.d.ts +2 -0
- package/dist/lock/implementations/derivables/_module.js +3 -0
- package/dist/lock/implementations/derivables/_module.js.map +1 -0
- package/dist/lock/implementations/derivables/lock-provider/_module.d.ts +1 -0
- package/dist/lock/implementations/derivables/lock-provider/_module.js +1 -0
- package/dist/lock/implementations/derivables/lock-provider/_module.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.d.ts +2 -2
- package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js +5 -3
- package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.d.ts +1 -2
- package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.js +4 -0
- package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +29 -18
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +19 -14
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.d.ts +6 -6
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js +6 -2
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +19 -23
- package/dist/lock/implementations/derivables/lock-provider/lock.js +13 -37
- package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/resolve-lock-adapter.d.ts +8 -0
- package/dist/lock/implementations/derivables/lock-provider/{resolve-database-lock-adapter.js → resolve-lock-adapter.js} +7 -3
- package/dist/lock/implementations/derivables/lock-provider/resolve-lock-adapter.js.map +1 -0
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +6 -6
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +9 -2
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
- package/dist/lock/implementations/test-utilities/_module.d.ts +3 -0
- package/dist/lock/implementations/test-utilities/_module.js +4 -0
- package/dist/lock/implementations/test-utilities/_module.js.map +1 -0
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.d.ts +2 -2
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js +3 -3
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js.map +1 -1
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.d.ts +2 -2
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js +4 -4
- 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 +3 -3
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +6 -541
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
- package/dist/namespace/_module.d.ts +1 -0
- package/dist/namespace/_module.js +2 -0
- package/dist/namespace/_module.js.map +1 -0
- package/dist/namespace/namespace.d.ts +1 -1
- package/dist/namespace/namespace.js +1 -1
- package/dist/namespace/namespace.js.map +1 -1
- package/dist/rate-limiter/contracts/_module-exports.d.ts +9 -0
- package/dist/rate-limiter/contracts/_module-exports.js +4 -0
- package/dist/rate-limiter/contracts/_module-exports.js.map +1 -0
- package/dist/rate-limiter/contracts/_module.d.ts +9 -0
- package/dist/rate-limiter/contracts/_module.js +4 -0
- package/dist/rate-limiter/contracts/_module.js.map +1 -0
- package/dist/rate-limiter/contracts/rate-limiter-adapter.contract.d.ts +36 -0
- package/dist/rate-limiter/contracts/rate-limiter-adapter.contract.js +7 -0
- package/dist/rate-limiter/contracts/rate-limiter-adapter.contract.js.map +1 -0
- package/dist/rate-limiter/contracts/rate-limiter-policy.contract.d.ts +28 -0
- package/dist/rate-limiter/contracts/rate-limiter-policy.contract.js +5 -0
- package/dist/rate-limiter/contracts/rate-limiter-policy.contract.js.map +1 -0
- package/dist/rate-limiter/contracts/rate-limiter-provider-factory.contract.d.ts +19 -0
- package/dist/rate-limiter/contracts/rate-limiter-provider-factory.contract.js +10 -0
- package/dist/rate-limiter/contracts/rate-limiter-provider-factory.contract.js.map +1 -0
- package/dist/rate-limiter/contracts/rate-limiter-provider.contract.d.ts +39 -0
- package/dist/rate-limiter/contracts/rate-limiter-provider.contract.js +8 -0
- package/dist/rate-limiter/contracts/rate-limiter-provider.contract.js.map +1 -0
- package/dist/rate-limiter/contracts/rate-limiter-state.contract.d.ts +58 -0
- package/dist/rate-limiter/contracts/rate-limiter-state.contract.js +15 -0
- package/dist/rate-limiter/contracts/rate-limiter-state.contract.js.map +1 -0
- package/dist/rate-limiter/contracts/rate-limiter-storage-adapter.contract.d.ts +65 -0
- package/dist/rate-limiter/contracts/rate-limiter-storage-adapter.contract.js +5 -0
- package/dist/rate-limiter/contracts/rate-limiter-storage-adapter.contract.js.map +1 -0
- package/dist/rate-limiter/contracts/rate-limiter.contract.d.ts +46 -0
- package/dist/rate-limiter/contracts/rate-limiter.contract.js +10 -0
- package/dist/rate-limiter/contracts/rate-limiter.contract.js.map +1 -0
- package/dist/rate-limiter/contracts/rate-limiter.errors.d.ts +34 -0
- package/dist/rate-limiter/contracts/rate-limiter.errors.js +40 -0
- package/dist/rate-limiter/contracts/rate-limiter.errors.js.map +1 -0
- package/dist/rate-limiter/contracts/rate-limiter.events.d.ts +74 -0
- package/dist/rate-limiter/contracts/rate-limiter.events.js +17 -0
- package/dist/rate-limiter/contracts/rate-limiter.events.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/_module.d.ts +7 -0
- package/dist/rate-limiter/implementations/adapters/_module.js +8 -0
- package/dist/rate-limiter/implementations/adapters/_module.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/_module-exports.d.ts +1 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/_module-exports.js +2 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/_module-exports.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/_module.d.ts +1 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/_module.js +2 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/_module.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/database-rate-limiter-adapter.d.ts +56 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/database-rate-limiter-adapter.js +77 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/database-rate-limiter-adapter.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/internal-rate-limiter-policy.d.ts +48 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/internal-rate-limiter-policy.js +70 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/internal-rate-limiter-policy.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/rate-limiter-state-manager.d.ts +15 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/rate-limiter-state-manager.js +33 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/rate-limiter-state-manager.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/rate-limiter-storage.d.ts +46 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/rate-limiter-storage.js +68 -0
- package/dist/rate-limiter/implementations/adapters/database-rate-limiter-adapter/rate-limiter-storage.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/kysely-rate-limiter-storage-adapter/_module-exports.d.ts +1 -0
- package/dist/rate-limiter/implementations/adapters/kysely-rate-limiter-storage-adapter/_module-exports.js +2 -0
- package/dist/rate-limiter/implementations/adapters/kysely-rate-limiter-storage-adapter/_module-exports.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/kysely-rate-limiter-storage-adapter/_module.d.ts +1 -0
- package/dist/rate-limiter/implementations/adapters/kysely-rate-limiter-storage-adapter/_module.js +2 -0
- package/dist/rate-limiter/implementations/adapters/kysely-rate-limiter-storage-adapter/_module.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/kysely-rate-limiter-storage-adapter/kysely-rate-limiter-storage-adapter.d.ts +95 -0
- package/dist/rate-limiter/implementations/adapters/kysely-rate-limiter-storage-adapter/kysely-rate-limiter-storage-adapter.js +186 -0
- package/dist/rate-limiter/implementations/adapters/kysely-rate-limiter-storage-adapter/kysely-rate-limiter-storage-adapter.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/memory-rate-limiter-storage-adapter/_module-exports.d.ts +1 -0
- package/dist/rate-limiter/implementations/adapters/memory-rate-limiter-storage-adapter/_module-exports.js +2 -0
- package/dist/rate-limiter/implementations/adapters/memory-rate-limiter-storage-adapter/_module-exports.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/memory-rate-limiter-storage-adapter/_module.d.ts +1 -0
- package/dist/rate-limiter/implementations/adapters/memory-rate-limiter-storage-adapter/_module.js +2 -0
- package/dist/rate-limiter/implementations/adapters/memory-rate-limiter-storage-adapter/_module.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/memory-rate-limiter-storage-adapter/memory-rate-limiter-storage-adapter.d.ts +37 -0
- package/dist/rate-limiter/implementations/adapters/memory-rate-limiter-storage-adapter/memory-rate-limiter-storage-adapter.js +71 -0
- package/dist/rate-limiter/implementations/adapters/memory-rate-limiter-storage-adapter/memory-rate-limiter-storage-adapter.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/mongodb-rate-limiter-storage-adapter/_module-exports.d.ts +1 -0
- package/dist/rate-limiter/implementations/adapters/mongodb-rate-limiter-storage-adapter/_module-exports.js +2 -0
- package/dist/rate-limiter/implementations/adapters/mongodb-rate-limiter-storage-adapter/_module-exports.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/mongodb-rate-limiter-storage-adapter/_module.d.ts +1 -0
- package/dist/rate-limiter/implementations/adapters/mongodb-rate-limiter-storage-adapter/_module.js +2 -0
- package/dist/rate-limiter/implementations/adapters/mongodb-rate-limiter-storage-adapter/_module.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/mongodb-rate-limiter-storage-adapter/mongodb-rate-limiter-storage-adapter.d.ts +77 -0
- package/dist/rate-limiter/implementations/adapters/mongodb-rate-limiter-storage-adapter/mongodb-rate-limiter-storage-adapter.js +126 -0
- package/dist/rate-limiter/implementations/adapters/mongodb-rate-limiter-storage-adapter/mongodb-rate-limiter-storage-adapter.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-adapter/_module-exports.d.ts +1 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-adapter/_module-exports.js +2 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-adapter/_module-exports.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-adapter/_module.d.ts +1 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-adapter/_module.js +2 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-adapter/_module.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-adapter/no-op-rate-limiter-adapter.d.ts +13 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-adapter/no-op-rate-limiter-adapter.js +30 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-adapter/no-op-rate-limiter-adapter.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-storage-adapter/_module-exports.d.ts +1 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-storage-adapter/_module-exports.js +2 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-storage-adapter/_module-exports.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-storage-adapter/_module.d.ts +1 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-storage-adapter/_module.js +2 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-storage-adapter/_module.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-storage-adapter/no-op-rate-limiter-storage-adapter.d.ts +16 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-storage-adapter/no-op-rate-limiter-storage-adapter.js +33 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-storage-adapter/no-op-rate-limiter-storage-adapter.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/_module-exports.d.ts +1 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/_module-exports.js +2 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/_module-exports.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/_module.d.ts +1 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/_module.js +2 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/_module.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/_module.d.ts +1 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/_module.js +2 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/_module.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/fixed-window-limiter-lua.d.ts +7 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/fixed-window-limiter-lua.js +55 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/fixed-window-limiter-lua.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/internal-rate-limiter-policy-lua.d.ts +7 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/internal-rate-limiter-policy-lua.js +100 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/internal-rate-limiter-policy-lua.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/rate-limiter-factory-lua.d.ts +4 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/rate-limiter-factory-lua.js +71 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/rate-limiter-factory-lua.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/rate-limiter-lua.d.ts +4 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/rate-limiter-lua.js +45 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/rate-limiter-lua.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/rate-limiter-state-manager-lua.d.ts +7 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/rate-limiter-state-manager-lua.js +51 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/rate-limiter-state-manager-lua.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/rate-limiter-storage-lua.d.ts +7 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/rate-limiter-storage-lua.js +76 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/rate-limiter-storage-lua.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/sliding-window-limiter-lua.d.ts +7 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/sliding-window-limiter-lua.js +113 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/lua/sliding-window-limiter-lua.js.map +1 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/redis-rate-limiter-adapter.d.ts +69 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/redis-rate-limiter-adapter.js +112 -0
- package/dist/rate-limiter/implementations/adapters/redis-rate-limiter-adapter/redis-rate-limiter-adapter.js.map +1 -0
- package/dist/rate-limiter/implementations/derivables/_module-exports.d.ts +2 -0
- package/dist/rate-limiter/implementations/derivables/_module-exports.js +3 -0
- package/dist/rate-limiter/implementations/derivables/_module-exports.js.map +1 -0
- package/dist/rate-limiter/implementations/derivables/_module.d.ts +2 -0
- package/dist/rate-limiter/implementations/derivables/_module.js +3 -0
- package/dist/rate-limiter/implementations/derivables/_module.js.map +1 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/_module.d.ts +1 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/_module.js +2 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/_module.js.map +1 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-provider.d.ts +123 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-provider.js +104 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-provider.js.map +1 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter.d.ts +41 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter.js +154 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter.js.map +1 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/_module.d.ts +2 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/_module.js +3 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/_module.js.map +1 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/database-rate-limiter-provider-factory.d.ts +135 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/database-rate-limiter-provider-factory.js +156 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/database-rate-limiter-provider-factory.js.map +1 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/rate-limiter-provider-factory.d.ts +106 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/rate-limiter-provider-factory.js +132 -0
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/rate-limiter-provider-factory.js.map +1 -0
- package/dist/rate-limiter/implementations/policies/_module-exports.d.ts +4 -0
- package/dist/rate-limiter/implementations/policies/_module-exports.js +5 -0
- package/dist/rate-limiter/implementations/policies/_module-exports.js.map +1 -0
- package/dist/rate-limiter/implementations/policies/_module.d.ts +4 -0
- package/dist/rate-limiter/implementations/policies/_module.js +5 -0
- package/dist/rate-limiter/implementations/policies/_module.js.map +1 -0
- package/dist/rate-limiter/implementations/policies/_shared.d.ts +12 -0
- package/dist/rate-limiter/implementations/policies/_shared.js +37 -0
- package/dist/rate-limiter/implementations/policies/_shared.js.map +1 -0
- package/dist/rate-limiter/implementations/policies/fixed-window-limiter/_module.d.ts +1 -0
- package/dist/rate-limiter/implementations/policies/fixed-window-limiter/_module.js +2 -0
- package/dist/rate-limiter/implementations/policies/fixed-window-limiter/_module.js.map +1 -0
- package/dist/rate-limiter/implementations/policies/fixed-window-limiter/fixed-window-limiter.d.ts +74 -0
- package/dist/rate-limiter/implementations/policies/fixed-window-limiter/fixed-window-limiter.js +73 -0
- package/dist/rate-limiter/implementations/policies/fixed-window-limiter/fixed-window-limiter.js.map +1 -0
- package/dist/rate-limiter/implementations/policies/sliding-window-limiter/_module.d.ts +1 -0
- package/dist/rate-limiter/implementations/policies/sliding-window-limiter/_module.js +2 -0
- package/dist/rate-limiter/implementations/policies/sliding-window-limiter/_module.js.map +1 -0
- package/dist/rate-limiter/implementations/policies/sliding-window-limiter/sliding-window-limiter.d.ts +86 -0
- package/dist/rate-limiter/implementations/policies/sliding-window-limiter/sliding-window-limiter.js +106 -0
- package/dist/rate-limiter/implementations/policies/sliding-window-limiter/sliding-window-limiter.js.map +1 -0
- package/dist/rate-limiter/implementations/policies/types.d.ts +47 -0
- package/dist/rate-limiter/implementations/policies/types.js +14 -0
- package/dist/rate-limiter/implementations/policies/types.js.map +1 -0
- package/dist/rate-limiter/implementations/test-utilities/_module-exports.d.ts +3 -0
- package/dist/rate-limiter/implementations/test-utilities/_module-exports.js +4 -0
- package/dist/rate-limiter/implementations/test-utilities/_module-exports.js.map +1 -0
- package/dist/rate-limiter/implementations/test-utilities/_module.d.ts +3 -0
- package/dist/rate-limiter/implementations/test-utilities/_module.js +4 -0
- package/dist/rate-limiter/implementations/test-utilities/_module.js.map +1 -0
- package/dist/rate-limiter/implementations/test-utilities/fixed-window-limiter.test-suite.d.ts +60 -0
- package/dist/rate-limiter/implementations/test-utilities/fixed-window-limiter.test-suite.js +250 -0
- package/dist/rate-limiter/implementations/test-utilities/fixed-window-limiter.test-suite.js.map +1 -0
- package/dist/rate-limiter/implementations/test-utilities/rate-limiter-storage-adapter.test-suite.d.ts +45 -0
- package/dist/rate-limiter/implementations/test-utilities/rate-limiter-storage-adapter.test-suite.js +102 -0
- package/dist/rate-limiter/implementations/test-utilities/rate-limiter-storage-adapter.test-suite.js.map +1 -0
- package/dist/rate-limiter/implementations/test-utilities/sliding-window-limiter.test-suite.d.ts +60 -0
- package/dist/rate-limiter/implementations/test-utilities/sliding-window-limiter.test-suite.js +91 -0
- package/dist/rate-limiter/implementations/test-utilities/sliding-window-limiter.test-suite.js.map +1 -0
- package/dist/resilience/_module.d.ts +2 -0
- package/dist/resilience/_module.js +3 -0
- package/dist/resilience/_module.js.map +1 -0
- package/dist/resilience/middlewares/dynamic/dynamic.middleware.d.ts +2 -2
- package/dist/resilience/middlewares/dynamic/dynamic.middleware.js +2 -1
- package/dist/resilience/middlewares/dynamic/dynamic.middleware.js.map +1 -1
- package/dist/resilience/middlewares/fallback/_module.d.ts +1 -1
- package/dist/resilience/middlewares/fallback/_module.js +0 -1
- package/dist/resilience/middlewares/fallback/_module.js.map +1 -1
- package/dist/resilience/middlewares/fallback/fallback.middleware.d.ts +3 -25
- package/dist/resilience/middlewares/fallback/fallback.middleware.js +6 -32
- package/dist/resilience/middlewares/fallback/fallback.middleware.js.map +1 -1
- package/dist/resilience/middlewares/fallback/fallback.types.d.ts +4 -6
- package/dist/resilience/middlewares/fallback/fallback.types.js +2 -2
- package/dist/resilience/middlewares/fallback/fallback.types.js.map +1 -1
- package/dist/resilience/middlewares/observe/_module.d.ts +1 -1
- package/dist/resilience/middlewares/observe/_module.js +0 -1
- package/dist/resilience/middlewares/observe/_module.js.map +1 -1
- package/dist/resilience/middlewares/observe/observe.middleware.d.ts +3 -39
- package/dist/resilience/middlewares/observe/observe.middleware.js +5 -57
- package/dist/resilience/middlewares/observe/observe.middleware.js.map +1 -1
- package/dist/resilience/middlewares/observe/observe.types.d.ts +4 -5
- package/dist/resilience/middlewares/observe/observe.types.js +3 -1
- package/dist/resilience/middlewares/observe/observe.types.js.map +1 -1
- package/dist/resilience/middlewares/retry/_module.d.ts +1 -1
- package/dist/resilience/middlewares/retry/_module.js +0 -1
- package/dist/resilience/middlewares/retry/_module.js.map +1 -1
- package/dist/resilience/middlewares/retry/retry.middleware.d.ts +3 -33
- package/dist/resilience/middlewares/retry/retry.middleware.js +9 -40
- package/dist/resilience/middlewares/retry/retry.middleware.js.map +1 -1
- package/dist/resilience/middlewares/retry/retry.types.d.ts +7 -9
- package/dist/resilience/middlewares/retry/retry.types.js +4 -3
- package/dist/resilience/middlewares/retry/retry.types.js.map +1 -1
- package/dist/resilience/middlewares/timeout/_module.d.ts +1 -1
- package/dist/resilience/middlewares/timeout/_module.js +0 -1
- package/dist/resilience/middlewares/timeout/_module.js.map +1 -1
- package/dist/resilience/middlewares/timeout/timeout.middleware.d.ts +2 -2
- package/dist/resilience/middlewares/timeout/timeout.middleware.js +4 -2
- package/dist/resilience/middlewares/timeout/timeout.middleware.js.map +1 -1
- package/dist/resilience/middlewares/timeout/timeout.type.d.ts +4 -4
- package/dist/resilience/middlewares/timeout/timeout.type.js +4 -1
- package/dist/resilience/middlewares/timeout/timeout.type.js.map +1 -1
- package/dist/resilience/utilities/timeout-and-fail/timeout-and-fail.d.ts +1 -1
- package/dist/resilience/utilities/timeout-and-fail/timeout-and-fail.js +1 -1
- package/dist/resilience/utilities/timeout-and-fail/timeout-and-fail.js.map +1 -1
- package/dist/semaphore/contracts/_module-exports.d.ts +6 -6
- package/dist/semaphore/contracts/_module-exports.js +0 -6
- package/dist/semaphore/contracts/_module-exports.js.map +1 -1
- package/dist/semaphore/contracts/_module.d.ts +9 -0
- package/dist/semaphore/contracts/_module.js +4 -0
- package/dist/semaphore/contracts/_module.js.map +1 -0
- package/dist/semaphore/contracts/database-semaphore-adapter.contract.d.ts +1 -1
- package/dist/semaphore/contracts/database-semaphore-adapter.contract.js +1 -1
- package/dist/semaphore/contracts/database-semaphore-adapter.contract.js.map +1 -1
- package/dist/semaphore/contracts/semaphore-adapter.contract.d.ts +1 -1
- package/dist/semaphore/contracts/semaphore-adapter.contract.js +3 -1
- package/dist/semaphore/contracts/semaphore-adapter.contract.js.map +1 -1
- package/dist/semaphore/contracts/semaphore-provider-factory.contract.d.ts +1 -1
- package/dist/semaphore/contracts/semaphore-provider-factory.contract.js +2 -1
- package/dist/semaphore/contracts/semaphore-provider-factory.contract.js.map +1 -1
- package/dist/semaphore/contracts/semaphore-provider.contract.d.ts +4 -8
- package/dist/semaphore/contracts/semaphore-provider.contract.js +4 -1
- package/dist/semaphore/contracts/semaphore-provider.contract.js.map +1 -1
- package/dist/semaphore/contracts/semaphore-state.contract.d.ts +2 -2
- package/dist/semaphore/contracts/semaphore-state.contract.js +1 -0
- package/dist/semaphore/contracts/semaphore-state.contract.js.map +1 -1
- package/dist/semaphore/contracts/semaphore.contract.d.ts +18 -28
- package/dist/semaphore/contracts/semaphore.contract.js +5 -1
- package/dist/semaphore/contracts/semaphore.contract.js.map +1 -1
- package/dist/semaphore/contracts/semaphore.errors.d.ts +19 -0
- package/dist/semaphore/contracts/semaphore.errors.js +25 -0
- package/dist/semaphore/contracts/semaphore.errors.js.map +1 -1
- package/dist/semaphore/contracts/semaphore.events.d.ts +1 -1
- package/dist/semaphore/contracts/semaphore.events.js +1 -0
- package/dist/semaphore/contracts/semaphore.events.js.map +1 -1
- package/dist/semaphore/contracts/types.d.ts +2 -2
- package/dist/semaphore/contracts/types.js +2 -1
- package/dist/semaphore/contracts/types.js.map +1 -1
- package/dist/semaphore/implementations/adapters/_module.d.ts +5 -5
- package/dist/semaphore/implementations/adapters/_module.js +5 -5
- package/dist/semaphore/implementations/adapters/_module.js.map +1 -1
- package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/_module.d.ts +1 -0
- package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/_module.js +2 -0
- package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/_module.js.map +1 -0
- package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/kysely-semaphore-adapter.d.ts +12 -5
- package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/kysely-semaphore-adapter.js +11 -4
- package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/kysely-semaphore-adapter.js.map +1 -1
- package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/_module.d.ts +1 -0
- package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/_module.js +2 -0
- package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/_module.js.map +1 -0
- package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/memory-semaphore-adapter.d.ts +9 -4
- package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/memory-semaphore-adapter.js +19 -1
- package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/memory-semaphore-adapter.js.map +1 -1
- package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/_module.d.ts +1 -0
- package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/_module.js +2 -0
- package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/_module.js.map +1 -0
- package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/mongodb-semaphore-adapter.d.ts +8 -5
- package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/mongodb-semaphore-adapter.js +7 -3
- package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/mongodb-semaphore-adapter.js.map +1 -1
- package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/_module.d.ts +1 -0
- package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/_module.js +2 -0
- package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/_module.js.map +1 -0
- package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/no-op-semaphore-adapter.d.ts +2 -2
- package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/no-op-semaphore-adapter.js +2 -0
- package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/no-op-semaphore-adapter.js.map +1 -1
- package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/_module.d.ts +1 -0
- package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/_module.js +2 -0
- package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/_module.js.map +1 -0
- package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/redis-semaphore-adapter.d.ts +3 -3
- package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/redis-semaphore-adapter.js +3 -0
- package/dist/semaphore/implementations/adapters/redis-semaphore-adapter/redis-semaphore-adapter.js.map +1 -1
- package/dist/semaphore/implementations/derivables/_module-exports.d.ts +1 -1
- package/dist/semaphore/implementations/derivables/_module-exports.js +0 -1
- package/dist/semaphore/implementations/derivables/_module-exports.js.map +1 -1
- package/dist/semaphore/implementations/derivables/_module.d.ts +2 -0
- package/dist/semaphore/implementations/derivables/_module.js +2 -0
- package/dist/semaphore/implementations/derivables/_module.js.map +1 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/database-semaphore-adapter.d.ts +2 -2
- package/dist/semaphore/implementations/derivables/semaphore-provider/database-semaphore-adapter.js +3 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/database-semaphore-adapter.js.map +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/is-database-semaphore-adapter.d.ts +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/is-database-semaphore-adapter.js +4 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/is-database-semaphore-adapter.js.map +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/resolve-semaphore-adapter.d.ts +8 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/{resolve-database-semaphore-adapter.js → resolve-semaphore-adapter.js} +4 -3
- package/dist/semaphore/implementations/derivables/semaphore-provider/resolve-semaphore-adapter.js.map +1 -0
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.d.ts +30 -18
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.js +19 -12
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.js.map +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.d.ts +6 -6
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.js +6 -3
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.js.map +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.d.ts +19 -23
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.js +13 -36
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.js.map +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/_module.d.ts +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/_module.js +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/_module.js.map +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.d.ts +5 -5
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.js +9 -2
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.js.map +1 -1
- package/dist/semaphore/implementations/test-utilities/_module.d.ts +3 -0
- package/dist/semaphore/implementations/test-utilities/_module.js +4 -0
- package/dist/semaphore/implementations/test-utilities/_module.js.map +1 -0
- package/dist/semaphore/implementations/test-utilities/database-semaphore-adapter.test-suite.d.ts +2 -2
- package/dist/semaphore/implementations/test-utilities/database-semaphore-adapter.test-suite.js +3 -2
- package/dist/semaphore/implementations/test-utilities/database-semaphore-adapter.test-suite.js.map +1 -1
- package/dist/semaphore/implementations/test-utilities/semaphore-adapter.test-suite.d.ts +3 -3
- package/dist/semaphore/implementations/test-utilities/semaphore-adapter.test-suite.js +5 -5
- 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 +3 -3
- package/dist/semaphore/implementations/test-utilities/semaphore-provider.test-suite.js +76 -805
- package/dist/semaphore/implementations/test-utilities/semaphore-provider.test-suite.js.map +1 -1
- package/dist/serde/contracts/_module-exports.d.ts +5 -5
- package/dist/serde/contracts/_module-exports.js +0 -5
- package/dist/serde/contracts/_module-exports.js.map +1 -1
- package/dist/serde/contracts/_module.d.ts +6 -0
- package/dist/serde/contracts/_module.js +2 -0
- package/dist/serde/contracts/_module.js.map +1 -0
- package/dist/serde/contracts/flexible-serde-adapter.contract.d.ts +1 -1
- package/dist/serde/contracts/flexible-serde-adapter.contract.js +1 -1
- package/dist/serde/contracts/flexible-serde-adapter.contract.js.map +1 -1
- package/dist/serde/contracts/flexible-serde.contract.d.ts +2 -2
- package/dist/serde/contracts/flexible-serde.contract.js +2 -1
- package/dist/serde/contracts/flexible-serde.contract.js.map +1 -1
- package/dist/serde/contracts/serde.contract.d.ts +2 -2
- package/dist/serde/contracts/serde.contract.js +2 -1
- package/dist/serde/contracts/serde.contract.js.map +1 -1
- package/dist/serde/contracts/serde.errors.d.ts +12 -0
- package/dist/serde/contracts/serde.errors.js +16 -0
- package/dist/serde/contracts/serde.errors.js.map +1 -1
- package/dist/serde/implementations/adapters/_module.d.ts +2 -2
- package/dist/serde/implementations/adapters/_module.js +2 -2
- package/dist/serde/implementations/adapters/_module.js.map +1 -1
- package/dist/serde/implementations/adapters/no-op-serde-adapter/_module.d.ts +1 -0
- package/dist/serde/implementations/adapters/no-op-serde-adapter/_module.js +2 -0
- package/dist/serde/implementations/adapters/no-op-serde-adapter/_module.js.map +1 -0
- package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.d.ts +1 -1
- package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.js +4 -0
- package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.js.map +1 -1
- package/dist/serde/implementations/adapters/super-json-serde-adapter/_module.d.ts +1 -0
- package/dist/serde/implementations/adapters/super-json-serde-adapter/_module.js +2 -0
- package/dist/serde/implementations/adapters/super-json-serde-adapter/_module.js.map +1 -0
- package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.d.ts +1 -1
- package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.js +3 -3
- package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.js.map +1 -1
- package/dist/serde/implementations/derivables/_module.d.ts +1 -0
- package/dist/serde/implementations/derivables/_module.js +2 -0
- package/dist/serde/implementations/derivables/_module.js.map +1 -0
- package/dist/serde/implementations/derivables/serde-transformers.d.ts +2 -2
- package/dist/serde/implementations/derivables/serde-transformers.js +5 -1
- package/dist/serde/implementations/derivables/serde-transformers.js.map +1 -1
- package/dist/serde/implementations/derivables/serde.d.ts +2 -2
- package/dist/serde/implementations/derivables/serde.js +2 -1
- package/dist/serde/implementations/derivables/serde.js.map +1 -1
- package/dist/serde/implementations/test-utilities/_module.d.ts +2 -0
- package/dist/serde/implementations/test-utilities/_module.js +3 -0
- package/dist/serde/implementations/test-utilities/_module.js.map +1 -0
- package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.d.ts +1 -1
- package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.js +1 -0
- package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.js.map +1 -1
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.d.ts +1 -1
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.js +1 -0
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.js.map +1 -1
- package/dist/shared-lock/contracts/_module-exports.d.ts +7 -7
- package/dist/shared-lock/contracts/_module-exports.js +0 -7
- package/dist/shared-lock/contracts/_module-exports.js.map +1 -1
- package/dist/shared-lock/contracts/_module.d.ts +10 -0
- package/dist/shared-lock/contracts/_module.js +4 -0
- package/dist/shared-lock/contracts/_module.js.map +1 -0
- package/dist/shared-lock/contracts/database-shared-lock-adapter.contract.d.ts +1 -1
- package/dist/shared-lock/contracts/database-shared-lock-adapter.contract.js +1 -1
- package/dist/shared-lock/contracts/database-shared-lock-adapter.contract.js.map +1 -1
- package/dist/shared-lock/contracts/shared-lock-adapter.contract.d.ts +1 -1
- package/dist/shared-lock/contracts/shared-lock-adapter.contract.js +3 -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 +1 -1
- package/dist/shared-lock/contracts/shared-lock-provider-factory.contract.js +2 -1
- package/dist/shared-lock/contracts/shared-lock-provider-factory.contract.js.map +1 -1
- package/dist/shared-lock/contracts/shared-lock-provider.contract.d.ts +4 -8
- package/dist/shared-lock/contracts/shared-lock-provider.contract.js +4 -1
- package/dist/shared-lock/contracts/shared-lock-provider.contract.js.map +1 -1
- package/dist/shared-lock/contracts/shared-lock-state.contract.d.ts +3 -3
- package/dist/shared-lock/contracts/shared-lock-state.contract.js +1 -0
- package/dist/shared-lock/contracts/shared-lock-state.contract.js.map +1 -1
- package/dist/shared-lock/contracts/shared-lock.contract.d.ts +33 -51
- package/dist/shared-lock/contracts/shared-lock.contract.js +5 -0
- package/dist/shared-lock/contracts/shared-lock.contract.js.map +1 -1
- package/dist/shared-lock/contracts/shared-lock.errors.d.ts +37 -0
- package/dist/shared-lock/contracts/shared-lock.errors.js +52 -0
- package/dist/shared-lock/contracts/shared-lock.errors.js.map +1 -1
- package/dist/shared-lock/contracts/shared-lock.events.d.ts +1 -1
- package/dist/shared-lock/contracts/shared-lock.events.js +1 -0
- package/dist/shared-lock/contracts/shared-lock.events.js.map +1 -1
- package/dist/shared-lock/contracts/types.d.ts +2 -2
- package/dist/shared-lock/contracts/types.js +2 -1
- package/dist/shared-lock/contracts/types.js.map +1 -1
- package/dist/shared-lock/implementations/adapters/_module.d.ts +5 -5
- package/dist/shared-lock/implementations/adapters/_module.js +5 -5
- package/dist/shared-lock/implementations/adapters/_module.js.map +1 -1
- package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/_module.d.ts +1 -0
- package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/_module.js +2 -0
- package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/_module.js.map +1 -0
- package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/kysely-shared-lock-adapter.d.ts +12 -5
- package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/kysely-shared-lock-adapter.js +11 -4
- package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/kysely-shared-lock-adapter.js.map +1 -1
- package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/_module.d.ts +1 -0
- package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/_module.js +2 -0
- package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/_module.js.map +1 -0
- package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/memory-shared-lock-adapter.d.ts +7 -4
- package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/memory-shared-lock-adapter.js +7 -2
- package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/memory-shared-lock-adapter.js.map +1 -1
- package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/_module.d.ts +1 -0
- package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/_module.js +2 -0
- package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/_module.js.map +1 -0
- package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/mongodb-shared-lock-adapter.d.ts +6 -6
- package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/mongodb-shared-lock-adapter.js +6 -4
- package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/mongodb-shared-lock-adapter.js.map +1 -1
- package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/_module.d.ts +1 -0
- package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/_module.js +2 -0
- package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/_module.js.map +1 -0
- package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/no-op-shared-lock-adapter.d.ts +2 -2
- package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/no-op-shared-lock-adapter.js +2 -0
- package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/no-op-shared-lock-adapter.js.map +1 -1
- package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/_module.d.ts +1 -0
- package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/_module.js +2 -0
- package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/_module.js.map +1 -0
- package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/redis-shared-lock-adapter.d.ts +3 -3
- package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/redis-shared-lock-adapter.js +3 -0
- package/dist/shared-lock/implementations/adapters/redis-shared-lock-adapter/redis-shared-lock-adapter.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/_module.d.ts +2 -0
- package/dist/shared-lock/implementations/derivables/_module.js +3 -0
- package/dist/shared-lock/implementations/derivables/_module.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/database-shared-lock-adapter.d.ts +2 -3
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/database-shared-lock-adapter.js +6 -3
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/database-shared-lock-adapter.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/is-database-shared-lock-adapter.d.ts +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/is-database-shared-lock-adapter.js +1 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/is-database-shared-lock-adapter.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/resolve-shared-lock-adapter.d.ts +8 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/{resolve-database-shared-lock-adapter.js → resolve-shared-lock-adapter.js} +4 -3
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/resolve-shared-lock-adapter.js.map +1 -0
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.d.ts +29 -17
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.js +18 -12
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.d.ts +6 -6
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.js +6 -3
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.d.ts +31 -35
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.js +17 -68
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.d.ts +6 -6
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.js +9 -2
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.js.map +1 -1
- package/dist/shared-lock/implementations/test-utilities/_module.d.ts +3 -0
- package/dist/shared-lock/implementations/test-utilities/_module.js +4 -0
- package/dist/shared-lock/implementations/test-utilities/_module.js.map +1 -0
- package/dist/shared-lock/implementations/test-utilities/database-shared-lock-adapter.test-suite.d.ts +3 -3
- package/dist/shared-lock/implementations/test-utilities/database-shared-lock-adapter.test-suite.js +7 -1
- package/dist/shared-lock/implementations/test-utilities/database-shared-lock-adapter.test-suite.js.map +1 -1
- package/dist/shared-lock/implementations/test-utilities/shared-lock-adapter.test-suite.d.ts +2 -2
- package/dist/shared-lock/implementations/test-utilities/shared-lock-adapter.test-suite.js +4 -4
- 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 +3 -3
- package/dist/shared-lock/implementations/test-utilities/shared-lock-provider.test-suite.js +1005 -2495
- package/dist/shared-lock/implementations/test-utilities/shared-lock-provider.test-suite.js.map +1 -1
- package/dist/task/contracts/_module-exports.d.ts +1 -0
- package/dist/task/contracts/_module-exports.js +2 -0
- package/dist/task/contracts/_module-exports.js.map +1 -0
- package/dist/task/contracts/_module.d.ts +1 -0
- package/dist/task/contracts/_module.js +2 -0
- package/dist/task/contracts/_module.js.map +1 -0
- package/dist/task/contracts/task.contract.d.ts +20 -0
- package/dist/task/contracts/task.contract.js +6 -0
- package/dist/task/contracts/task.contract.js.map +1 -0
- package/dist/task/implementations/_module-exports.d.ts +1 -0
- package/dist/task/implementations/_module-exports.js +2 -0
- package/dist/task/implementations/_module-exports.js.map +1 -0
- package/dist/task/implementations/_module.d.ts +1 -0
- package/dist/task/implementations/_module.js +2 -0
- package/dist/task/implementations/_module.js.map +1 -0
- package/dist/task/implementations/abort-and-fail.js.map +1 -0
- package/dist/task/{task.d.ts → implementations/task.d.ts} +27 -25
- package/dist/task/{task.js → implementations/task.js} +19 -10
- package/dist/task/implementations/task.js.map +1 -0
- package/dist/time-span/contracts/_module.d.ts +1 -0
- package/dist/time-span/contracts/_module.js +2 -0
- package/dist/time-span/contracts/_module.js.map +1 -0
- package/dist/time-span/implementations/_module.d.ts +1 -0
- package/dist/time-span/implementations/_module.js +2 -0
- package/dist/time-span/implementations/_module.js.map +1 -0
- package/dist/time-span/implementations/time-span.d.ts +3 -3
- package/dist/time-span/implementations/time-span.js +4 -2
- package/dist/time-span/implementations/time-span.js.map +1 -1
- package/dist/utilities/_module-exports.d.ts +2 -2
- package/dist/utilities/_module-exports.js +0 -2
- package/dist/utilities/_module-exports.js.map +1 -1
- package/dist/utilities/_module.d.ts +5 -0
- package/dist/utilities/_module.js +4 -0
- package/dist/utilities/_module.js.map +1 -0
- package/dist/utilities/contracts/_module.d.ts +5 -5
- package/dist/utilities/contracts/_module.js +1 -5
- package/dist/utilities/contracts/_module.js.map +1 -1
- package/dist/utilities/errors.d.ts +2 -10
- package/dist/utilities/errors.js +2 -13
- package/dist/utilities/errors.js.map +1 -1
- package/dist/utilities/functions/_module.d.ts +9 -2
- package/dist/utilities/functions/_module.js +9 -2
- package/dist/utilities/functions/_module.js.map +1 -1
- package/dist/utilities/functions/array-like-to-iterable.d.ts +7 -0
- package/dist/utilities/functions/array-like-to-iterable.js +20 -0
- package/dist/utilities/functions/array-like-to-iterable.js.map +1 -0
- package/dist/utilities/functions/error-policy.d.ts +7 -7
- package/dist/utilities/functions/error-policy.js +17 -28
- package/dist/utilities/functions/error-policy.js.map +1 -1
- package/dist/utilities/functions/invokable.d.ts +2 -33
- package/dist/utilities/functions/invokable.js +3 -1
- package/dist/utilities/functions/invokable.js.map +1 -1
- package/dist/utilities/functions/is-array-like.d.ts +7 -0
- package/dist/utilities/functions/is-array-like.js +17 -0
- package/dist/utilities/functions/is-array-like.js.map +1 -0
- package/dist/utilities/functions/is-async-iterable.d.ts +7 -0
- package/dist/utilities/functions/is-async-iterable.js +14 -0
- package/dist/utilities/functions/is-async-iterable.js.map +1 -0
- package/dist/utilities/functions/is-class.d.ts +1 -1
- package/dist/utilities/functions/is-class.js +1 -0
- package/dist/utilities/functions/is-class.js.map +1 -1
- package/dist/utilities/functions/is-iterable.d.ts +7 -0
- package/dist/utilities/functions/is-iterable.js +13 -0
- package/dist/utilities/functions/is-iterable.js.map +1 -0
- package/dist/utilities/functions/is-standard-schema.d.ts +1 -1
- package/dist/utilities/functions/is-standard-schema.js +1 -0
- package/dist/utilities/functions/is-standard-schema.js.map +1 -1
- package/dist/utilities/functions/iterable-to-async-iterable.d.ts +7 -0
- package/dist/utilities/functions/iterable-to-async-iterable.js +17 -0
- package/dist/utilities/functions/iterable-to-async-iterable.js.map +1 -0
- package/dist/utilities/functions/lazy.d.ts +4 -4
- package/dist/utilities/functions/lazy.js +5 -3
- package/dist/utilities/functions/lazy.js.map +1 -1
- package/dist/utilities/functions/resolve-async-iterable-value.d.ts +8 -0
- package/dist/utilities/functions/resolve-async-iterable-value.js +21 -0
- package/dist/utilities/functions/resolve-async-iterable-value.js.map +1 -0
- package/dist/utilities/functions/resolve-iterable-value.d.ts +8 -0
- package/dist/utilities/functions/resolve-iterable-value.js +16 -0
- package/dist/utilities/functions/resolve-iterable-value.js.map +1 -0
- package/dist/utilities/functions/resolve-one-or-more.js +1 -1
- package/dist/utilities/functions/resolve-one-or-more.js.map +1 -1
- package/dist/utilities/functions/validate.d.ts +1 -1
- package/dist/utilities/functions/validate.js +1 -0
- package/dist/utilities/functions/validate.js.map +1 -1
- package/dist/utilities/functions/with-jitter.d.ts +15 -0
- package/dist/utilities/functions/with-jitter.js +14 -0
- package/dist/utilities/functions/with-jitter.js.map +1 -0
- package/dist/utilities/types/_module.d.ts +4 -4
- package/dist/utilities/types/_module.js +1 -4
- package/dist/utilities/types/_module.js.map +1 -1
- package/dist/utilities/types/async-iterable-value.type.d.ts +6 -1
- package/package.json +113 -10
- package/dist/backoff-policies/constant-backoff-policy/_module.d.ts +0 -1
- package/dist/backoff-policies/constant-backoff-policy/_module.js +0 -2
- package/dist/backoff-policies/constant-backoff-policy/_module.js.map +0 -1
- package/dist/backoff-policies/constant-backoff-policy/constant-backoff-policy.d.ts +0 -30
- package/dist/backoff-policies/constant-backoff-policy/constant-backoff-policy.js +0 -29
- package/dist/backoff-policies/constant-backoff-policy/constant-backoff-policy.js.map +0 -1
- package/dist/backoff-policies/exponential-backoff-policy/_module.d.ts +0 -1
- package/dist/backoff-policies/exponential-backoff-policy/_module.js +0 -2
- package/dist/backoff-policies/exponential-backoff-policy/_module.js.map +0 -1
- package/dist/backoff-policies/exponential-backoff-policy/exponential-backoff-policy.d.ts +0 -38
- package/dist/backoff-policies/exponential-backoff-policy/exponential-backoff-policy.js +0 -30
- package/dist/backoff-policies/exponential-backoff-policy/exponential-backoff-policy.js.map +0 -1
- package/dist/backoff-policies/linear-backoff-policy/_module.d.ts +0 -1
- package/dist/backoff-policies/linear-backoff-policy/_module.js +0 -2
- package/dist/backoff-policies/linear-backoff-policy/_module.js.map +0 -1
- package/dist/backoff-policies/linear-backoff-policy/linear-backoff-policy.d.ts +0 -34
- package/dist/backoff-policies/linear-backoff-policy/linear-backoff-policy.js +0 -30
- package/dist/backoff-policies/linear-backoff-policy/linear-backoff-policy.js.map +0 -1
- package/dist/backoff-policies/polynomial-backoff-policy/_module.d.ts +0 -1
- package/dist/backoff-policies/polynomial-backoff-policy/_module.js +0 -2
- package/dist/backoff-policies/polynomial-backoff-policy/_module.js.map +0 -1
- package/dist/backoff-policies/polynomial-backoff-policy/polynomial-backoff-policy.d.ts +0 -38
- package/dist/backoff-policies/polynomial-backoff-policy/polynomial-backoff-policy.js +0 -30
- package/dist/backoff-policies/polynomial-backoff-policy/polynomial-backoff-policy.js.map +0 -1
- package/dist/lock/implementations/derivables/lock-provider/resolve-database-lock-adapter.d.ts +0 -9
- package/dist/lock/implementations/derivables/lock-provider/resolve-database-lock-adapter.js.map +0 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/resolve-database-semaphore-adapter.d.ts +0 -8
- package/dist/semaphore/implementations/derivables/semaphore-provider/resolve-database-semaphore-adapter.js.map +0 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/resolve-database-shared-lock-adapter.d.ts +0 -8
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/resolve-database-shared-lock-adapter.js.map +0 -1
- package/dist/task/_module-exports.d.ts +0 -1
- package/dist/task/_module-exports.js +0 -2
- package/dist/task/_module-exports.js.map +0 -1
- package/dist/task/abort-and-fail.js.map +0 -1
- package/dist/task/task.js.map +0 -1
- package/dist/utilities/functions/result.d.ts +0 -91
- package/dist/utilities/functions/result.js +0 -59
- package/dist/utilities/functions/result.js.map +0 -1
- /package/dist/task/{abort-and-fail.d.ts → implementations/abort-and-fail.d.ts} +0 -0
- /package/dist/task/{abort-and-fail.js → implementations/abort-and-fail.js} +0 -0
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
* @module SharedLock
|
|
3
3
|
*/
|
|
4
4
|
import { vi, } from "vitest";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { Task } from "../../../task/_module
|
|
8
|
-
import { TimeSpan } from "../../../time-span/implementations/_module
|
|
5
|
+
import {} from "../../../serde/contracts/_module.js";
|
|
6
|
+
import { FailedAcquireWriterLockError, FailedRefreshReaderSemaphoreError, FailedRefreshWriterLockError, FailedReleaseReaderSemaphoreError, FailedReleaseWriterLockError, LimitReachedReaderSemaphoreError, SHARED_LOCK_EVENTS, SHARED_LOCK_STATE, } from "../../../shared-lock/contracts/_module.js";
|
|
7
|
+
import { Task } from "../../../task/implementations/_module.js";
|
|
8
|
+
import { TimeSpan } from "../../../time-span/implementations/_module.js";
|
|
9
|
+
import {} from "../../../utilities/_module.js";
|
|
9
10
|
/**
|
|
10
11
|
* The `sharedLockProviderTestSuite` function simplifies the process of testing your custom implementation of {@link ISharedLock | `ISharedLock`} with `vitest`.
|
|
11
12
|
*
|
|
@@ -57,76 +58,76 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
57
58
|
serde = serde_;
|
|
58
59
|
});
|
|
59
60
|
describe("Api tests:", () => {
|
|
60
|
-
describe("method:
|
|
61
|
-
test("Should call
|
|
61
|
+
describe("method: runWriterOrFail", () => {
|
|
62
|
+
test("Should call acquireReaderOrFail method", async () => {
|
|
62
63
|
const key = "a";
|
|
63
|
-
const limit = 4;
|
|
64
64
|
const ttl = null;
|
|
65
|
+
const limit = 4;
|
|
65
66
|
const sharedLock = sharedLockProvider.create(key, {
|
|
66
67
|
ttl,
|
|
67
68
|
limit,
|
|
68
69
|
});
|
|
69
|
-
const acquireSpy = vi.spyOn(sharedLock, "
|
|
70
|
-
await sharedLock.
|
|
70
|
+
const acquireSpy = vi.spyOn(sharedLock, "acquireWriterOrFail");
|
|
71
|
+
await sharedLock.runWriterOrFail(() => {
|
|
71
72
|
return Promise.resolve(RETURN_VALUE);
|
|
72
73
|
});
|
|
73
74
|
expect(acquireSpy).toHaveBeenCalledTimes(1);
|
|
74
75
|
});
|
|
75
|
-
test("Should call
|
|
76
|
+
test("Should call acquireReaderOrFail before release method", async () => {
|
|
76
77
|
const key = "a";
|
|
77
|
-
const limit = 4;
|
|
78
78
|
const ttl = null;
|
|
79
|
+
const limit = 4;
|
|
79
80
|
const sharedLock = sharedLockProvider.create(key, {
|
|
80
81
|
ttl,
|
|
81
82
|
limit,
|
|
82
83
|
});
|
|
83
|
-
const acquireSpy = vi.spyOn(sharedLock, "
|
|
84
|
+
const acquireSpy = vi.spyOn(sharedLock, "acquireWriterOrFail");
|
|
84
85
|
const releaseSpy = vi.spyOn(sharedLock, "releaseWriter");
|
|
85
|
-
await sharedLock.
|
|
86
|
+
await sharedLock.runWriterOrFail(() => {
|
|
86
87
|
return Promise.resolve(RETURN_VALUE);
|
|
87
88
|
});
|
|
88
89
|
expect(acquireSpy).toHaveBeenCalledBefore(releaseSpy);
|
|
89
90
|
});
|
|
90
91
|
test("Should call release method", async () => {
|
|
91
92
|
const key = "a";
|
|
92
|
-
const limit = 4;
|
|
93
93
|
const ttl = null;
|
|
94
|
+
const limit = 4;
|
|
94
95
|
const sharedLock = sharedLockProvider.create(key, {
|
|
95
96
|
ttl,
|
|
96
97
|
limit,
|
|
97
98
|
});
|
|
98
99
|
const releaseSpy = vi.spyOn(sharedLock, "releaseWriter");
|
|
99
|
-
await sharedLock.
|
|
100
|
+
await sharedLock.runWriterOrFail(() => {
|
|
100
101
|
return Promise.resolve(RETURN_VALUE);
|
|
101
102
|
});
|
|
102
103
|
expect(releaseSpy).toHaveBeenCalledTimes(1);
|
|
103
104
|
});
|
|
104
|
-
test("Should call release after
|
|
105
|
+
test("Should call release after acquireReaderOrFail method", async () => {
|
|
105
106
|
const key = "a";
|
|
106
|
-
const limit = 4;
|
|
107
107
|
const ttl = null;
|
|
108
|
+
const limit = 4;
|
|
108
109
|
const sharedLock = sharedLockProvider.create(key, {
|
|
109
110
|
ttl,
|
|
110
111
|
limit,
|
|
111
112
|
});
|
|
112
113
|
const releaseSpy = vi.spyOn(sharedLock, "releaseWriter");
|
|
113
|
-
const acquireSpy = vi.spyOn(sharedLock, "
|
|
114
|
-
await sharedLock.
|
|
114
|
+
const acquireSpy = vi.spyOn(sharedLock, "acquireWriterOrFail");
|
|
115
|
+
await sharedLock.runWriterOrFail(() => {
|
|
115
116
|
return Promise.resolve(RETURN_VALUE);
|
|
116
117
|
});
|
|
117
118
|
expect(releaseSpy).toHaveBeenCalledAfter(acquireSpy);
|
|
118
119
|
});
|
|
119
120
|
test("Should call release when an error is thrown", async () => {
|
|
120
121
|
const key = "a";
|
|
121
|
-
const limit = 4;
|
|
122
122
|
const ttl = null;
|
|
123
|
+
const limit = 4;
|
|
123
124
|
const sharedLock = sharedLockProvider.create(key, {
|
|
124
125
|
ttl,
|
|
125
126
|
limit,
|
|
126
127
|
});
|
|
127
128
|
const releaseSpy = vi.spyOn(sharedLock, "releaseWriter");
|
|
128
129
|
try {
|
|
129
|
-
await sharedLock.
|
|
130
|
+
await sharedLock.runWriterOrFail(() => {
|
|
130
131
|
return Promise.reject(new Error());
|
|
131
132
|
});
|
|
132
133
|
}
|
|
@@ -137,15 +138,15 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
137
138
|
});
|
|
138
139
|
test("Should propagate thrown error", async () => {
|
|
139
140
|
const key = "a";
|
|
140
|
-
const limit = 4;
|
|
141
141
|
const ttl = null;
|
|
142
|
+
const limit = 4;
|
|
142
143
|
const sharedLock = sharedLockProvider.create(key, {
|
|
143
144
|
ttl,
|
|
144
145
|
limit,
|
|
145
146
|
});
|
|
146
147
|
class CustomError extends Error {
|
|
147
148
|
}
|
|
148
|
-
const error = sharedLock.
|
|
149
|
+
const error = sharedLock.runWriterOrFail(() => {
|
|
149
150
|
return Promise.reject(new CustomError());
|
|
150
151
|
});
|
|
151
152
|
await expect(error).rejects.toBeInstanceOf(CustomError);
|
|
@@ -162,7 +163,7 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
162
163
|
ttl,
|
|
163
164
|
limit,
|
|
164
165
|
})
|
|
165
|
-
.
|
|
166
|
+
.runWriterOrFail(handlerFn);
|
|
166
167
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
167
168
|
});
|
|
168
169
|
test("Should call handler function when key is expired", {
|
|
@@ -186,7 +187,7 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
186
187
|
ttl,
|
|
187
188
|
limit,
|
|
188
189
|
})
|
|
189
|
-
.
|
|
190
|
+
.runWriterOrFail(handlerFn);
|
|
190
191
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
191
192
|
});
|
|
192
193
|
test("Should call handler function when key is unexpireable and acquired by same lockId", async () => {
|
|
@@ -201,7 +202,12 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
201
202
|
const handlerFn = vi.fn(() => {
|
|
202
203
|
return Promise.resolve(RETURN_VALUE);
|
|
203
204
|
});
|
|
204
|
-
|
|
205
|
+
try {
|
|
206
|
+
await sharedLock.runWriterOrFail(handlerFn);
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
/* EMPTY */
|
|
210
|
+
}
|
|
205
211
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
206
212
|
});
|
|
207
213
|
test("Should call handler function when key is unexpired and acquired by same lockId", async () => {
|
|
@@ -216,7 +222,12 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
216
222
|
const handlerFn = vi.fn(() => {
|
|
217
223
|
return Promise.resolve(RETURN_VALUE);
|
|
218
224
|
});
|
|
219
|
-
|
|
225
|
+
try {
|
|
226
|
+
await sharedLock.runWriterOrFail(handlerFn);
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
/* EMPTY */
|
|
230
|
+
}
|
|
220
231
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
221
232
|
});
|
|
222
233
|
test("Should not call handler function when key is unexpireable and acquired by different lockId", async () => {
|
|
@@ -232,12 +243,17 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
232
243
|
const handlerFn = vi.fn(() => {
|
|
233
244
|
return Promise.resolve(RETURN_VALUE);
|
|
234
245
|
});
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
246
|
+
try {
|
|
247
|
+
await sharedLockProvider
|
|
248
|
+
.create(key, {
|
|
249
|
+
ttl,
|
|
250
|
+
limit,
|
|
251
|
+
})
|
|
252
|
+
.runWriterOrFail(handlerFn);
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
/* EMPTY */
|
|
256
|
+
}
|
|
241
257
|
expect(handlerFn).not.toHaveBeenCalled();
|
|
242
258
|
});
|
|
243
259
|
test("Should not call handler function when key is unexpired and acquired by different lockId", async () => {
|
|
@@ -253,15 +269,20 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
253
269
|
const handlerFn = vi.fn(() => {
|
|
254
270
|
return Promise.resolve(RETURN_VALUE);
|
|
255
271
|
});
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
272
|
+
try {
|
|
273
|
+
await sharedLockProvider
|
|
274
|
+
.create(key, {
|
|
275
|
+
ttl,
|
|
276
|
+
limit,
|
|
277
|
+
})
|
|
278
|
+
.runWriterOrFail(handlerFn);
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
/* EMPTY */
|
|
282
|
+
}
|
|
262
283
|
expect(handlerFn).not.toHaveBeenCalled();
|
|
263
284
|
});
|
|
264
|
-
test("Should return
|
|
285
|
+
test("Should return value when key doesnt exists", async () => {
|
|
265
286
|
const key = "a";
|
|
266
287
|
const limit = 4;
|
|
267
288
|
const ttl = null;
|
|
@@ -270,12 +291,12 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
270
291
|
ttl,
|
|
271
292
|
limit,
|
|
272
293
|
})
|
|
273
|
-
.
|
|
294
|
+
.runWriterOrFail(() => {
|
|
274
295
|
return Promise.resolve(RETURN_VALUE);
|
|
275
296
|
});
|
|
276
|
-
expect(result).
|
|
297
|
+
expect(result).toBe(RETURN_VALUE);
|
|
277
298
|
});
|
|
278
|
-
test("Should return
|
|
299
|
+
test("Should return value when key is expired", {
|
|
279
300
|
retry: 10,
|
|
280
301
|
}, async () => {
|
|
281
302
|
const key = "a";
|
|
@@ -293,12 +314,12 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
293
314
|
ttl,
|
|
294
315
|
limit,
|
|
295
316
|
})
|
|
296
|
-
.
|
|
317
|
+
.runWriterOrFail(() => {
|
|
297
318
|
return Promise.resolve(RETURN_VALUE);
|
|
298
319
|
});
|
|
299
|
-
expect(result).
|
|
320
|
+
expect(result).toBe(RETURN_VALUE);
|
|
300
321
|
});
|
|
301
|
-
test("Should
|
|
322
|
+
test("Should not throw error when key is unexpireable and acquired by same lockId", async () => {
|
|
302
323
|
const key = "a";
|
|
303
324
|
const limit = 4;
|
|
304
325
|
const ttl = null;
|
|
@@ -307,12 +328,12 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
307
328
|
limit,
|
|
308
329
|
});
|
|
309
330
|
await sharedLock.acquireWriter();
|
|
310
|
-
const result = await sharedLock.
|
|
331
|
+
const result = await sharedLock.runWriterOrFail(() => {
|
|
311
332
|
return Promise.resolve(RETURN_VALUE);
|
|
312
333
|
});
|
|
313
|
-
expect(result).
|
|
334
|
+
expect(result).toBe(RETURN_VALUE);
|
|
314
335
|
});
|
|
315
|
-
test("Should
|
|
336
|
+
test("Should not throw error when key is unexpired and acquired by same lockId", async () => {
|
|
316
337
|
const key = "a";
|
|
317
338
|
const limit = 4;
|
|
318
339
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
@@ -321,12 +342,12 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
321
342
|
limit,
|
|
322
343
|
});
|
|
323
344
|
await sharedLock.acquireWriter();
|
|
324
|
-
const result = await sharedLock.
|
|
345
|
+
const result = await sharedLock.runWriterOrFail(() => {
|
|
325
346
|
return Promise.resolve(RETURN_VALUE);
|
|
326
347
|
});
|
|
327
|
-
expect(result).
|
|
348
|
+
expect(result).toBe(RETURN_VALUE);
|
|
328
349
|
});
|
|
329
|
-
test("Should
|
|
350
|
+
test("Should throw FailedAcquireWriterLockError when key is unexpireable and acquired by different lockId", async () => {
|
|
330
351
|
const key = "a";
|
|
331
352
|
const limit = 4;
|
|
332
353
|
const ttl = null;
|
|
@@ -336,20 +357,17 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
336
357
|
limit,
|
|
337
358
|
})
|
|
338
359
|
.acquireWriter();
|
|
339
|
-
const result =
|
|
360
|
+
const result = sharedLockProvider
|
|
340
361
|
.create(key, {
|
|
341
362
|
ttl,
|
|
342
363
|
limit,
|
|
343
364
|
})
|
|
344
|
-
.
|
|
365
|
+
.runWriterOrFail(() => {
|
|
345
366
|
return Promise.resolve(RETURN_VALUE);
|
|
346
367
|
});
|
|
347
|
-
expect(result).
|
|
348
|
-
type: RESULT.FAILURE,
|
|
349
|
-
error: expect.any(FailedAcquireWriterLockError),
|
|
350
|
-
}));
|
|
368
|
+
await expect(result).rejects.toBeInstanceOf(FailedAcquireWriterLockError);
|
|
351
369
|
});
|
|
352
|
-
test("Should
|
|
370
|
+
test("Should throw FailedAcquireWriterLockError when key is unexpired and acquired by different lockId", async () => {
|
|
353
371
|
const key = "a";
|
|
354
372
|
const limit = 4;
|
|
355
373
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
@@ -359,22 +377,19 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
359
377
|
limit,
|
|
360
378
|
})
|
|
361
379
|
.acquireWriter();
|
|
362
|
-
const result =
|
|
380
|
+
const result = sharedLockProvider
|
|
363
381
|
.create(key, {
|
|
364
382
|
ttl,
|
|
365
383
|
limit,
|
|
366
384
|
})
|
|
367
|
-
.
|
|
385
|
+
.runWriterOrFail(() => {
|
|
368
386
|
return Promise.resolve(RETURN_VALUE);
|
|
369
387
|
});
|
|
370
|
-
expect(result).
|
|
371
|
-
type: RESULT.FAILURE,
|
|
372
|
-
error: expect.any(FailedAcquireWriterLockError),
|
|
373
|
-
}));
|
|
388
|
+
await expect(result).rejects.toBeInstanceOf(FailedAcquireWriterLockError);
|
|
374
389
|
});
|
|
375
390
|
});
|
|
376
|
-
describe("method:
|
|
377
|
-
test("Should call
|
|
391
|
+
describe("method: runWriterBlockingOrFail", () => {
|
|
392
|
+
test("Should call acquireWriterBlockingOrFail method", async () => {
|
|
378
393
|
const key = "a";
|
|
379
394
|
const ttl = null;
|
|
380
395
|
const limit = 4;
|
|
@@ -382,13 +397,16 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
382
397
|
ttl,
|
|
383
398
|
limit,
|
|
384
399
|
});
|
|
385
|
-
const acquireSpy = vi.spyOn(sharedLock, "
|
|
386
|
-
await sharedLock.
|
|
400
|
+
const acquireSpy = vi.spyOn(sharedLock, "acquireWriterBlockingOrFail");
|
|
401
|
+
await sharedLock.runWriterBlockingOrFail(() => {
|
|
387
402
|
return Promise.resolve(RETURN_VALUE);
|
|
403
|
+
}, {
|
|
404
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
405
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
388
406
|
});
|
|
389
407
|
expect(acquireSpy).toHaveBeenCalledTimes(1);
|
|
390
408
|
});
|
|
391
|
-
test("Should call
|
|
409
|
+
test("Should call acquireWriterBlockingOrFail before release method", async () => {
|
|
392
410
|
const key = "a";
|
|
393
411
|
const ttl = null;
|
|
394
412
|
const limit = 4;
|
|
@@ -396,10 +414,13 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
396
414
|
ttl,
|
|
397
415
|
limit,
|
|
398
416
|
});
|
|
399
|
-
const acquireSpy = vi.spyOn(sharedLock, "
|
|
417
|
+
const acquireSpy = vi.spyOn(sharedLock, "acquireWriterBlockingOrFail");
|
|
400
418
|
const releaseSpy = vi.spyOn(sharedLock, "releaseWriter");
|
|
401
|
-
await sharedLock.
|
|
419
|
+
await sharedLock.runWriterBlockingOrFail(() => {
|
|
402
420
|
return Promise.resolve(RETURN_VALUE);
|
|
421
|
+
}, {
|
|
422
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
423
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
403
424
|
});
|
|
404
425
|
expect(acquireSpy).toHaveBeenCalledBefore(releaseSpy);
|
|
405
426
|
});
|
|
@@ -412,12 +433,15 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
412
433
|
limit,
|
|
413
434
|
});
|
|
414
435
|
const releaseSpy = vi.spyOn(sharedLock, "releaseWriter");
|
|
415
|
-
await sharedLock.
|
|
436
|
+
await sharedLock.runWriterBlockingOrFail(() => {
|
|
416
437
|
return Promise.resolve(RETURN_VALUE);
|
|
438
|
+
}, {
|
|
439
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
440
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
417
441
|
});
|
|
418
442
|
expect(releaseSpy).toHaveBeenCalledTimes(1);
|
|
419
443
|
});
|
|
420
|
-
test("Should call release after
|
|
444
|
+
test("Should call release after acquireWriterBlockingOrFail method", async () => {
|
|
421
445
|
const key = "a";
|
|
422
446
|
const ttl = null;
|
|
423
447
|
const limit = 4;
|
|
@@ -426,9 +450,12 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
426
450
|
limit,
|
|
427
451
|
});
|
|
428
452
|
const releaseSpy = vi.spyOn(sharedLock, "releaseWriter");
|
|
429
|
-
const acquireSpy = vi.spyOn(sharedLock, "
|
|
430
|
-
await sharedLock.
|
|
453
|
+
const acquireSpy = vi.spyOn(sharedLock, "acquireWriterBlockingOrFail");
|
|
454
|
+
await sharedLock.runWriterBlockingOrFail(() => {
|
|
431
455
|
return Promise.resolve(RETURN_VALUE);
|
|
456
|
+
}, {
|
|
457
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
458
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
432
459
|
});
|
|
433
460
|
expect(releaseSpy).toHaveBeenCalledAfter(acquireSpy);
|
|
434
461
|
});
|
|
@@ -442,8 +469,11 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
442
469
|
});
|
|
443
470
|
const releaseSpy = vi.spyOn(sharedLock, "releaseWriter");
|
|
444
471
|
try {
|
|
445
|
-
await sharedLock.
|
|
472
|
+
await sharedLock.runWriterBlockingOrFail(() => {
|
|
446
473
|
return Promise.reject(new Error());
|
|
474
|
+
}, {
|
|
475
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
476
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
447
477
|
});
|
|
448
478
|
}
|
|
449
479
|
catch {
|
|
@@ -461,15 +491,18 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
461
491
|
});
|
|
462
492
|
class CustomError extends Error {
|
|
463
493
|
}
|
|
464
|
-
const error = sharedLock.
|
|
494
|
+
const error = sharedLock.runWriterBlockingOrFail(() => {
|
|
465
495
|
return Promise.reject(new CustomError());
|
|
496
|
+
}, {
|
|
497
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
498
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
466
499
|
});
|
|
467
500
|
await expect(error).rejects.toBeInstanceOf(CustomError);
|
|
468
501
|
});
|
|
469
502
|
test("Should call handler function when key doesnt exists", async () => {
|
|
470
503
|
const key = "a";
|
|
471
|
-
const limit = 4;
|
|
472
504
|
const ttl = null;
|
|
505
|
+
const limit = 4;
|
|
473
506
|
const handlerFn = vi.fn(() => {
|
|
474
507
|
return Promise.resolve(RETURN_VALUE);
|
|
475
508
|
});
|
|
@@ -478,15 +511,18 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
478
511
|
ttl,
|
|
479
512
|
limit,
|
|
480
513
|
})
|
|
481
|
-
.
|
|
514
|
+
.runWriterBlockingOrFail(handlerFn, {
|
|
515
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
516
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
517
|
+
});
|
|
482
518
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
483
519
|
});
|
|
484
520
|
test("Should call handler function when key is expired", {
|
|
485
521
|
retry: 10,
|
|
486
522
|
}, async () => {
|
|
487
523
|
const key = "a";
|
|
488
|
-
const limit = 4;
|
|
489
524
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
525
|
+
const limit = 4;
|
|
490
526
|
await sharedLockProvider
|
|
491
527
|
.create(key, {
|
|
492
528
|
ttl,
|
|
@@ -502,13 +538,16 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
502
538
|
ttl,
|
|
503
539
|
limit,
|
|
504
540
|
})
|
|
505
|
-
.
|
|
541
|
+
.runWriterBlockingOrFail(handlerFn, {
|
|
542
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
543
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
544
|
+
});
|
|
506
545
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
507
546
|
});
|
|
508
547
|
test("Should call handler function when key is unexpireable and acquired by same lockId", async () => {
|
|
509
548
|
const key = "a";
|
|
510
|
-
const limit = 4;
|
|
511
549
|
const ttl = null;
|
|
550
|
+
const limit = 4;
|
|
512
551
|
const sharedLock = sharedLockProvider.create(key, {
|
|
513
552
|
ttl,
|
|
514
553
|
limit,
|
|
@@ -518,7 +557,10 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
518
557
|
return Promise.resolve(RETURN_VALUE);
|
|
519
558
|
});
|
|
520
559
|
try {
|
|
521
|
-
await sharedLock.
|
|
560
|
+
await sharedLock.runWriterBlockingOrFail(handlerFn, {
|
|
561
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
562
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
563
|
+
});
|
|
522
564
|
}
|
|
523
565
|
catch {
|
|
524
566
|
/* EMPTY */
|
|
@@ -527,8 +569,8 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
527
569
|
});
|
|
528
570
|
test("Should call handler function when key is unexpired and acquired by same lockId", async () => {
|
|
529
571
|
const key = "a";
|
|
530
|
-
const limit = 4;
|
|
531
572
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
573
|
+
const limit = 4;
|
|
532
574
|
const sharedLock = sharedLockProvider.create(key, {
|
|
533
575
|
ttl,
|
|
534
576
|
limit,
|
|
@@ -538,7 +580,10 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
538
580
|
return Promise.resolve(RETURN_VALUE);
|
|
539
581
|
});
|
|
540
582
|
try {
|
|
541
|
-
await sharedLock.
|
|
583
|
+
await sharedLock.runWriterBlockingOrFail(handlerFn, {
|
|
584
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
585
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
586
|
+
});
|
|
542
587
|
}
|
|
543
588
|
catch {
|
|
544
589
|
/* EMPTY */
|
|
@@ -547,8 +592,8 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
547
592
|
});
|
|
548
593
|
test("Should not call handler function when key is unexpireable and acquired by different lockId", async () => {
|
|
549
594
|
const key = "a";
|
|
550
|
-
const limit = 4;
|
|
551
595
|
const ttl = null;
|
|
596
|
+
const limit = 4;
|
|
552
597
|
await sharedLockProvider
|
|
553
598
|
.create(key, {
|
|
554
599
|
ttl,
|
|
@@ -564,7 +609,10 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
564
609
|
ttl,
|
|
565
610
|
limit,
|
|
566
611
|
})
|
|
567
|
-
.
|
|
612
|
+
.runWriterBlockingOrFail(handlerFn, {
|
|
613
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
614
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
615
|
+
});
|
|
568
616
|
}
|
|
569
617
|
catch {
|
|
570
618
|
/* EMPTY */
|
|
@@ -573,8 +621,8 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
573
621
|
});
|
|
574
622
|
test("Should not call handler function when key is unexpired and acquired by different lockId", async () => {
|
|
575
623
|
const key = "a";
|
|
576
|
-
const limit = 4;
|
|
577
624
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
625
|
+
const limit = 4;
|
|
578
626
|
await sharedLockProvider
|
|
579
627
|
.create(key, {
|
|
580
628
|
ttl,
|
|
@@ -590,7 +638,10 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
590
638
|
ttl,
|
|
591
639
|
limit,
|
|
592
640
|
})
|
|
593
|
-
.
|
|
641
|
+
.runWriterBlockingOrFail(handlerFn, {
|
|
642
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
643
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
644
|
+
});
|
|
594
645
|
}
|
|
595
646
|
catch {
|
|
596
647
|
/* EMPTY */
|
|
@@ -599,15 +650,18 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
599
650
|
});
|
|
600
651
|
test("Should return value when key doesnt exists", async () => {
|
|
601
652
|
const key = "a";
|
|
602
|
-
const limit = 4;
|
|
603
653
|
const ttl = null;
|
|
654
|
+
const limit = 4;
|
|
604
655
|
const result = await sharedLockProvider
|
|
605
656
|
.create(key, {
|
|
606
657
|
ttl,
|
|
607
658
|
limit,
|
|
608
659
|
})
|
|
609
|
-
.
|
|
660
|
+
.runWriterBlockingOrFail(() => {
|
|
610
661
|
return Promise.resolve(RETURN_VALUE);
|
|
662
|
+
}, {
|
|
663
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
664
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
611
665
|
});
|
|
612
666
|
expect(result).toBe(RETURN_VALUE);
|
|
613
667
|
});
|
|
@@ -615,8 +669,8 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
615
669
|
retry: 10,
|
|
616
670
|
}, async () => {
|
|
617
671
|
const key = "a";
|
|
618
|
-
const limit = 4;
|
|
619
672
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
673
|
+
const limit = 4;
|
|
620
674
|
await sharedLockProvider
|
|
621
675
|
.create(key, {
|
|
622
676
|
ttl,
|
|
@@ -629,43 +683,52 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
629
683
|
ttl,
|
|
630
684
|
limit,
|
|
631
685
|
})
|
|
632
|
-
.
|
|
686
|
+
.runWriterBlockingOrFail(() => {
|
|
633
687
|
return Promise.resolve(RETURN_VALUE);
|
|
688
|
+
}, {
|
|
689
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
690
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
634
691
|
});
|
|
635
692
|
expect(result).toBe(RETURN_VALUE);
|
|
636
693
|
});
|
|
637
|
-
test("Should
|
|
694
|
+
test("Should return value when key is unexpireable and acquired by same lockId", async () => {
|
|
638
695
|
const key = "a";
|
|
639
|
-
const limit = 4;
|
|
640
696
|
const ttl = null;
|
|
697
|
+
const limit = 4;
|
|
641
698
|
const sharedLock = sharedLockProvider.create(key, {
|
|
642
699
|
ttl,
|
|
643
700
|
limit,
|
|
644
701
|
});
|
|
645
702
|
await sharedLock.acquireWriter();
|
|
646
|
-
const result = await sharedLock.
|
|
703
|
+
const result = await sharedLock.runWriterBlockingOrFail(() => {
|
|
647
704
|
return Promise.resolve(RETURN_VALUE);
|
|
705
|
+
}, {
|
|
706
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
707
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
648
708
|
});
|
|
649
709
|
expect(result).toBe(RETURN_VALUE);
|
|
650
710
|
});
|
|
651
|
-
test("Should
|
|
711
|
+
test("Should return value when key is unexpired and acquired by same lockId", async () => {
|
|
652
712
|
const key = "a";
|
|
653
|
-
const limit = 4;
|
|
654
713
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
714
|
+
const limit = 4;
|
|
655
715
|
const sharedLock = sharedLockProvider.create(key, {
|
|
656
716
|
ttl,
|
|
657
717
|
limit,
|
|
658
718
|
});
|
|
659
719
|
await sharedLock.acquireWriter();
|
|
660
|
-
const result = await sharedLock.
|
|
720
|
+
const result = await sharedLock.runWriterBlockingOrFail(() => {
|
|
661
721
|
return Promise.resolve(RETURN_VALUE);
|
|
722
|
+
}, {
|
|
723
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
724
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
662
725
|
});
|
|
663
726
|
expect(result).toBe(RETURN_VALUE);
|
|
664
727
|
});
|
|
665
728
|
test("Should throw FailedAcquireWriterLockError when key is unexpireable and acquired by different lockId", async () => {
|
|
666
729
|
const key = "a";
|
|
667
|
-
const limit = 4;
|
|
668
730
|
const ttl = null;
|
|
731
|
+
const limit = 4;
|
|
669
732
|
await sharedLockProvider
|
|
670
733
|
.create(key, {
|
|
671
734
|
ttl,
|
|
@@ -677,15 +740,18 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
677
740
|
ttl,
|
|
678
741
|
limit,
|
|
679
742
|
})
|
|
680
|
-
.
|
|
743
|
+
.runWriterBlockingOrFail(() => {
|
|
681
744
|
return Promise.resolve(RETURN_VALUE);
|
|
745
|
+
}, {
|
|
746
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
747
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
682
748
|
});
|
|
683
749
|
await expect(result).rejects.toBeInstanceOf(FailedAcquireWriterLockError);
|
|
684
750
|
});
|
|
685
751
|
test("Should throw FailedAcquireWriterLockError when key is unexpired and acquired by different lockId", async () => {
|
|
686
752
|
const key = "a";
|
|
687
|
-
const limit = 4;
|
|
688
753
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
754
|
+
const limit = 4;
|
|
689
755
|
await sharedLockProvider
|
|
690
756
|
.create(key, {
|
|
691
757
|
ttl,
|
|
@@ -697,831 +763,656 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
697
763
|
ttl,
|
|
698
764
|
limit,
|
|
699
765
|
})
|
|
700
|
-
.
|
|
766
|
+
.runWriterBlockingOrFail(() => {
|
|
701
767
|
return Promise.resolve(RETURN_VALUE);
|
|
768
|
+
}, {
|
|
769
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
770
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
702
771
|
});
|
|
703
772
|
await expect(result).rejects.toBeInstanceOf(FailedAcquireWriterLockError);
|
|
704
773
|
});
|
|
705
|
-
|
|
706
|
-
describe("method: runWriterBlocking", () => {
|
|
707
|
-
test("Should call acquireWriterBlocking method", async () => {
|
|
774
|
+
test("Should retry acquire the shared lock when blocked by a writer", async () => {
|
|
708
775
|
const key = "a";
|
|
709
|
-
const ttl =
|
|
776
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
710
777
|
const limit = 4;
|
|
711
|
-
const
|
|
778
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
712
779
|
ttl,
|
|
713
780
|
limit,
|
|
714
781
|
});
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
720
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
721
|
-
});
|
|
722
|
-
expect(acquireSpy).toHaveBeenCalledTimes(1);
|
|
723
|
-
});
|
|
724
|
-
test("Should call acquireWriterBlocking before release method", async () => {
|
|
725
|
-
const key = "a";
|
|
726
|
-
const ttl = null;
|
|
727
|
-
const limit = 4;
|
|
728
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
782
|
+
await sharedLock1.acquireWriter();
|
|
783
|
+
const handlerFn = vi.fn(() => { });
|
|
784
|
+
await sharedLockProvider.addListener(SHARED_LOCK_EVENTS.UNAVAILABLE, handlerFn);
|
|
785
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
729
786
|
ttl,
|
|
730
787
|
limit,
|
|
731
788
|
});
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
const ttl = null;
|
|
745
|
-
const limit = 4;
|
|
746
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
747
|
-
ttl,
|
|
748
|
-
limit,
|
|
749
|
-
});
|
|
750
|
-
const releaseSpy = vi.spyOn(sharedLock, "releaseWriter");
|
|
751
|
-
await sharedLock.runWriterBlocking(() => {
|
|
752
|
-
return Promise.resolve(RETURN_VALUE);
|
|
753
|
-
}, {
|
|
754
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
755
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
756
|
-
});
|
|
757
|
-
expect(releaseSpy).toHaveBeenCalledTimes(1);
|
|
789
|
+
try {
|
|
790
|
+
await sharedLock2.runWriterBlockingOrFail(() => {
|
|
791
|
+
return Promise.resolve(RETURN_VALUE);
|
|
792
|
+
}, {
|
|
793
|
+
time: TimeSpan.fromMilliseconds(55),
|
|
794
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
catch {
|
|
798
|
+
/* EMPTY */
|
|
799
|
+
}
|
|
800
|
+
expect(handlerFn.mock.calls.length).toBeGreaterThan(1);
|
|
758
801
|
});
|
|
759
|
-
test("Should
|
|
802
|
+
test("Should retry acquire the shared lock when blocked by a reader", async () => {
|
|
760
803
|
const key = "a";
|
|
761
|
-
const ttl =
|
|
804
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
762
805
|
const limit = 4;
|
|
763
|
-
const
|
|
806
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
764
807
|
ttl,
|
|
765
808
|
limit,
|
|
766
809
|
});
|
|
767
|
-
|
|
768
|
-
const
|
|
769
|
-
await
|
|
770
|
-
|
|
771
|
-
}, {
|
|
772
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
773
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
774
|
-
});
|
|
775
|
-
expect(releaseSpy).toHaveBeenCalledAfter(acquireSpy);
|
|
776
|
-
});
|
|
777
|
-
test("Should call release when an error is thrown", async () => {
|
|
778
|
-
const key = "a";
|
|
779
|
-
const ttl = null;
|
|
780
|
-
const limit = 4;
|
|
781
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
810
|
+
await sharedLock1.acquireReader();
|
|
811
|
+
const handlerFn = vi.fn(() => { });
|
|
812
|
+
await sharedLockProvider.addListener(SHARED_LOCK_EVENTS.UNAVAILABLE, handlerFn);
|
|
813
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
782
814
|
ttl,
|
|
783
815
|
limit,
|
|
784
816
|
});
|
|
785
|
-
const releaseSpy = vi.spyOn(sharedLock, "releaseWriter");
|
|
786
817
|
try {
|
|
787
|
-
await
|
|
788
|
-
return Promise.
|
|
818
|
+
await sharedLock2.runWriterBlockingOrFail(() => {
|
|
819
|
+
return Promise.resolve(RETURN_VALUE);
|
|
789
820
|
}, {
|
|
790
|
-
time: TimeSpan.fromMilliseconds(
|
|
821
|
+
time: TimeSpan.fromMilliseconds(55),
|
|
791
822
|
interval: TimeSpan.fromMilliseconds(5),
|
|
792
823
|
});
|
|
793
824
|
}
|
|
794
825
|
catch {
|
|
795
826
|
/* EMPTY */
|
|
796
827
|
}
|
|
797
|
-
expect(
|
|
798
|
-
});
|
|
799
|
-
test("Should propagate thrown error", async () => {
|
|
800
|
-
const key = "a";
|
|
801
|
-
const ttl = null;
|
|
802
|
-
const limit = 4;
|
|
803
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
804
|
-
ttl,
|
|
805
|
-
limit,
|
|
806
|
-
});
|
|
807
|
-
class CustomError extends Error {
|
|
808
|
-
}
|
|
809
|
-
const error = sharedLock.runWriterBlocking(() => {
|
|
810
|
-
return Promise.reject(new CustomError());
|
|
811
|
-
}, {
|
|
812
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
813
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
814
|
-
});
|
|
815
|
-
await expect(error).rejects.toBeInstanceOf(CustomError);
|
|
828
|
+
expect(handlerFn.mock.calls.length).toBeGreaterThan(1);
|
|
816
829
|
});
|
|
817
|
-
|
|
830
|
+
});
|
|
831
|
+
describe("method: acquireWriter", () => {
|
|
832
|
+
test("Should return true when key doesnt exists", async () => {
|
|
818
833
|
const key = "a";
|
|
819
834
|
const ttl = null;
|
|
820
835
|
const limit = 4;
|
|
821
|
-
const
|
|
822
|
-
return Promise.resolve(RETURN_VALUE);
|
|
823
|
-
});
|
|
824
|
-
await sharedLockProvider
|
|
836
|
+
const result = await sharedLockProvider
|
|
825
837
|
.create(key, {
|
|
826
|
-
ttl,
|
|
827
838
|
limit,
|
|
839
|
+
ttl,
|
|
828
840
|
})
|
|
829
|
-
.
|
|
830
|
-
|
|
831
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
832
|
-
});
|
|
833
|
-
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
841
|
+
.acquireWriter();
|
|
842
|
+
expect(result).toBe(true);
|
|
834
843
|
});
|
|
835
|
-
test("Should
|
|
844
|
+
test("Should return true when key is expired", {
|
|
836
845
|
retry: 10,
|
|
837
846
|
}, async () => {
|
|
838
847
|
const key = "a";
|
|
839
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
840
848
|
const limit = 4;
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
ttl,
|
|
849
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
850
|
+
const sharedLock = sharedLockProvider.create(key, {
|
|
844
851
|
limit,
|
|
845
|
-
})
|
|
846
|
-
.acquireWriter();
|
|
847
|
-
await delay(ttl);
|
|
848
|
-
const handlerFn = vi.fn(() => {
|
|
849
|
-
return Promise.resolve(RETURN_VALUE);
|
|
850
|
-
});
|
|
851
|
-
await sharedLockProvider
|
|
852
|
-
.create(key, {
|
|
853
852
|
ttl,
|
|
854
|
-
limit,
|
|
855
|
-
})
|
|
856
|
-
.runWriterBlocking(handlerFn, {
|
|
857
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
858
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
859
853
|
});
|
|
860
|
-
|
|
854
|
+
await sharedLock.acquireWriter();
|
|
855
|
+
await delay(ttl);
|
|
856
|
+
const result = await sharedLock.acquireWriter();
|
|
857
|
+
expect(result).toBe(true);
|
|
861
858
|
});
|
|
862
|
-
test("Should
|
|
859
|
+
test("Should return true when key is unexpireable and acquired by same owner", async () => {
|
|
863
860
|
const key = "a";
|
|
864
|
-
const ttl = null;
|
|
865
861
|
const limit = 4;
|
|
862
|
+
const ttl = null;
|
|
866
863
|
const sharedLock = sharedLockProvider.create(key, {
|
|
867
864
|
ttl,
|
|
868
865
|
limit,
|
|
869
866
|
});
|
|
870
867
|
await sharedLock.acquireWriter();
|
|
871
|
-
const
|
|
872
|
-
|
|
873
|
-
});
|
|
874
|
-
await sharedLock.runWriterBlocking(handlerFn, {
|
|
875
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
876
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
877
|
-
});
|
|
878
|
-
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
868
|
+
const result = await sharedLock.acquireWriter();
|
|
869
|
+
expect(result).toBe(true);
|
|
879
870
|
});
|
|
880
|
-
test("Should
|
|
871
|
+
test("Should return true when key is unexpired and acquired by same owner", async () => {
|
|
881
872
|
const key = "a";
|
|
882
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
883
873
|
const limit = 4;
|
|
874
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
884
875
|
const sharedLock = sharedLockProvider.create(key, {
|
|
885
876
|
ttl,
|
|
886
877
|
limit,
|
|
887
878
|
});
|
|
888
879
|
await sharedLock.acquireWriter();
|
|
889
|
-
const
|
|
890
|
-
|
|
891
|
-
});
|
|
892
|
-
await sharedLock.runWriterBlocking(handlerFn, {
|
|
893
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
894
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
895
|
-
});
|
|
896
|
-
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
880
|
+
const result = await sharedLock.acquireWriter();
|
|
881
|
+
expect(result).toBe(true);
|
|
897
882
|
});
|
|
898
|
-
test("Should
|
|
883
|
+
test("Should return false when key is unexpireable and acquired by different owner", async () => {
|
|
899
884
|
const key = "a";
|
|
900
885
|
const ttl = null;
|
|
901
886
|
const limit = 4;
|
|
902
|
-
|
|
903
|
-
.create(key, {
|
|
887
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
904
888
|
ttl,
|
|
905
889
|
limit,
|
|
906
|
-
})
|
|
907
|
-
.acquireWriter();
|
|
908
|
-
const handlerFn = vi.fn(() => {
|
|
909
|
-
return Promise.resolve(RETURN_VALUE);
|
|
910
890
|
});
|
|
911
|
-
await
|
|
912
|
-
|
|
891
|
+
await sharedLock1.acquireWriter();
|
|
892
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
913
893
|
ttl,
|
|
914
894
|
limit,
|
|
915
|
-
})
|
|
916
|
-
.runWriterBlocking(handlerFn, {
|
|
917
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
918
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
919
895
|
});
|
|
920
|
-
|
|
896
|
+
const result = await sharedLock2.acquireWriter();
|
|
897
|
+
expect(result).toBe(false);
|
|
921
898
|
});
|
|
922
|
-
test("Should
|
|
899
|
+
test("Should return false when key is unexpired and acquired by different owner", async () => {
|
|
923
900
|
const key = "a";
|
|
924
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
925
901
|
const limit = 4;
|
|
926
|
-
|
|
927
|
-
|
|
902
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
903
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
904
|
+
limit,
|
|
928
905
|
ttl,
|
|
906
|
+
});
|
|
907
|
+
await sharedLock1.acquireWriter();
|
|
908
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
929
909
|
limit,
|
|
930
|
-
|
|
931
|
-
.acquireWriter();
|
|
932
|
-
const handlerFn = vi.fn(() => {
|
|
933
|
-
return Promise.resolve(RETURN_VALUE);
|
|
910
|
+
ttl,
|
|
934
911
|
});
|
|
935
|
-
await
|
|
936
|
-
|
|
912
|
+
const result = await sharedLock2.acquireWriter();
|
|
913
|
+
expect(result).toBe(false);
|
|
914
|
+
});
|
|
915
|
+
test("Should return false when key is acquired as reader", async () => {
|
|
916
|
+
const key = "a";
|
|
917
|
+
const limit = 2;
|
|
918
|
+
const ttl = null;
|
|
919
|
+
const sharedLock = sharedLockProvider.create(key, {
|
|
920
|
+
limit,
|
|
921
|
+
ttl,
|
|
922
|
+
});
|
|
923
|
+
await sharedLock.acquireReader();
|
|
924
|
+
const result = await sharedLock.acquireWriter();
|
|
925
|
+
expect(result).toBe(false);
|
|
926
|
+
});
|
|
927
|
+
test("Should not update state when key is acquired as reader", async () => {
|
|
928
|
+
const key = "a";
|
|
929
|
+
const limit = 3;
|
|
930
|
+
const ttl = null;
|
|
931
|
+
const sharedLock = sharedLockProvider.create(key, {
|
|
932
|
+
limit,
|
|
937
933
|
ttl,
|
|
934
|
+
});
|
|
935
|
+
await sharedLock.acquireReader();
|
|
936
|
+
await sharedLock.acquireWriter();
|
|
937
|
+
const state = await sharedLock.getState();
|
|
938
|
+
expect(state).toEqual({
|
|
939
|
+
type: SHARED_LOCK_STATE.READER_ACQUIRED,
|
|
938
940
|
limit,
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
941
|
+
remainingTime: null,
|
|
942
|
+
freeSlotsCount: 2,
|
|
943
|
+
acquiredSlotsCount: 1,
|
|
944
|
+
acquiredSlots: [sharedLock.id],
|
|
943
945
|
});
|
|
944
|
-
expect(handlerFn).not.toHaveBeenCalled();
|
|
945
946
|
});
|
|
946
|
-
|
|
947
|
+
});
|
|
948
|
+
describe("method: acquireWriterOrFail", () => {
|
|
949
|
+
test("Should not throw error when key doesnt exists", async () => {
|
|
947
950
|
const key = "a";
|
|
948
951
|
const ttl = null;
|
|
949
952
|
const limit = 4;
|
|
950
|
-
const result =
|
|
953
|
+
const result = sharedLockProvider
|
|
951
954
|
.create(key, {
|
|
952
|
-
ttl,
|
|
953
955
|
limit,
|
|
956
|
+
ttl,
|
|
954
957
|
})
|
|
955
|
-
.
|
|
956
|
-
|
|
957
|
-
}, {
|
|
958
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
959
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
960
|
-
});
|
|
961
|
-
expect(result).toEqual(resultSuccess(RETURN_VALUE));
|
|
958
|
+
.acquireWriterOrFail();
|
|
959
|
+
await expect(result).resolves.toBeUndefined();
|
|
962
960
|
});
|
|
963
|
-
test("Should
|
|
961
|
+
test("Should not throw error when key is expired", {
|
|
964
962
|
retry: 10,
|
|
965
963
|
}, async () => {
|
|
966
964
|
const key = "a";
|
|
967
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
968
965
|
const limit = 4;
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
ttl,
|
|
966
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
967
|
+
const sharedLock = sharedLockProvider.create(key, {
|
|
972
968
|
limit,
|
|
973
|
-
})
|
|
974
|
-
.acquireWriter();
|
|
975
|
-
await delay(ttl);
|
|
976
|
-
const result = await sharedLockProvider
|
|
977
|
-
.create(key, {
|
|
978
969
|
ttl,
|
|
979
|
-
limit,
|
|
980
|
-
})
|
|
981
|
-
.runWriterBlocking(() => {
|
|
982
|
-
return Promise.resolve(RETURN_VALUE);
|
|
983
|
-
}, {
|
|
984
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
985
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
986
970
|
});
|
|
987
|
-
|
|
971
|
+
await sharedLock.acquireWriterOrFail();
|
|
972
|
+
await delay(ttl);
|
|
973
|
+
const result = sharedLock.acquireWriterOrFail();
|
|
974
|
+
await expect(result).resolves.toBeUndefined();
|
|
988
975
|
});
|
|
989
|
-
test("Should
|
|
976
|
+
test("Should not throw error when key is unexpireable and acquired by same owner", async () => {
|
|
990
977
|
const key = "a";
|
|
991
|
-
const ttl = null;
|
|
992
978
|
const limit = 4;
|
|
979
|
+
const ttl = null;
|
|
993
980
|
const sharedLock = sharedLockProvider.create(key, {
|
|
994
981
|
ttl,
|
|
995
982
|
limit,
|
|
996
983
|
});
|
|
997
|
-
await sharedLock.
|
|
998
|
-
const result =
|
|
999
|
-
|
|
1000
|
-
}, {
|
|
1001
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
1002
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1003
|
-
});
|
|
1004
|
-
expect(result).toEqual(resultSuccess(RETURN_VALUE));
|
|
984
|
+
await sharedLock.acquireWriterOrFail();
|
|
985
|
+
const result = sharedLock.acquireWriterOrFail();
|
|
986
|
+
await expect(result).resolves.toBeUndefined();
|
|
1005
987
|
});
|
|
1006
|
-
test("Should
|
|
988
|
+
test("Should not throw error when key is unexpired and acquired by same owner", async () => {
|
|
1007
989
|
const key = "a";
|
|
1008
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1009
990
|
const limit = 4;
|
|
991
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1010
992
|
const sharedLock = sharedLockProvider.create(key, {
|
|
1011
993
|
ttl,
|
|
1012
994
|
limit,
|
|
1013
995
|
});
|
|
1014
|
-
await sharedLock.
|
|
1015
|
-
const result =
|
|
1016
|
-
|
|
1017
|
-
}, {
|
|
1018
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
1019
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1020
|
-
});
|
|
1021
|
-
expect(result).toEqual(resultSuccess(RETURN_VALUE));
|
|
996
|
+
await sharedLock.acquireWriterOrFail();
|
|
997
|
+
const result = sharedLock.acquireWriterOrFail();
|
|
998
|
+
await expect(result).resolves.toBeUndefined();
|
|
1022
999
|
});
|
|
1023
|
-
test("Should
|
|
1000
|
+
test("Should throw FailedAcquireWriterLockError when key is unexpireable and acquired by different owner", async () => {
|
|
1024
1001
|
const key = "a";
|
|
1025
1002
|
const ttl = null;
|
|
1026
1003
|
const limit = 4;
|
|
1027
|
-
|
|
1028
|
-
.create(key, {
|
|
1004
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1029
1005
|
ttl,
|
|
1030
1006
|
limit,
|
|
1031
|
-
})
|
|
1032
|
-
|
|
1033
|
-
const
|
|
1034
|
-
.create(key, {
|
|
1007
|
+
});
|
|
1008
|
+
await sharedLock1.acquireWriterOrFail();
|
|
1009
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1035
1010
|
ttl,
|
|
1036
1011
|
limit,
|
|
1037
|
-
})
|
|
1038
|
-
.runWriterBlocking(() => {
|
|
1039
|
-
return Promise.resolve(RETURN_VALUE);
|
|
1040
|
-
}, {
|
|
1041
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
1042
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1043
1012
|
});
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
error: expect.any(FailedAcquireWriterLockError),
|
|
1047
|
-
}));
|
|
1013
|
+
const result = sharedLock2.acquireWriterOrFail();
|
|
1014
|
+
await expect(result).rejects.toBeInstanceOf(FailedAcquireWriterLockError);
|
|
1048
1015
|
});
|
|
1049
|
-
test("Should
|
|
1016
|
+
test("Should throw FailedAcquireWriterLockError when key is unexpired and acquired by different owner", async () => {
|
|
1050
1017
|
const key = "a";
|
|
1051
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1052
1018
|
const limit = 4;
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
ttl,
|
|
1019
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1020
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1056
1021
|
limit,
|
|
1057
|
-
})
|
|
1058
|
-
.acquireWriter();
|
|
1059
|
-
const result = await sharedLockProvider
|
|
1060
|
-
.create(key, {
|
|
1061
1022
|
ttl,
|
|
1023
|
+
});
|
|
1024
|
+
await sharedLock1.acquireWriterOrFail();
|
|
1025
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1062
1026
|
limit,
|
|
1063
|
-
|
|
1064
|
-
.runWriterBlocking(() => {
|
|
1065
|
-
return Promise.resolve(RETURN_VALUE);
|
|
1066
|
-
}, {
|
|
1067
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
1068
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1027
|
+
ttl,
|
|
1069
1028
|
});
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
error: expect.any(FailedAcquireWriterLockError),
|
|
1073
|
-
}));
|
|
1029
|
+
const result = sharedLock2.acquireWriterOrFail();
|
|
1030
|
+
await expect(result).rejects.toBeInstanceOf(FailedAcquireWriterLockError);
|
|
1074
1031
|
});
|
|
1075
|
-
test("Should
|
|
1032
|
+
test("Should throw FailedAcquireWriterLockError when key is acquired as reader", async () => {
|
|
1076
1033
|
const key = "a";
|
|
1077
|
-
const
|
|
1078
|
-
const
|
|
1079
|
-
const
|
|
1080
|
-
ttl,
|
|
1034
|
+
const limit = 2;
|
|
1035
|
+
const ttl = null;
|
|
1036
|
+
const sharedLock = sharedLockProvider.create(key, {
|
|
1081
1037
|
limit,
|
|
1082
|
-
});
|
|
1083
|
-
await sharedLock1.acquireWriter();
|
|
1084
|
-
const handlerFn = vi.fn(() => { });
|
|
1085
|
-
await sharedLockProvider.addListener(SHARED_LOCK_EVENTS.UNAVAILABLE, handlerFn);
|
|
1086
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1087
1038
|
ttl,
|
|
1039
|
+
});
|
|
1040
|
+
await sharedLock.acquireReader();
|
|
1041
|
+
const result = sharedLock.acquireWriterOrFail();
|
|
1042
|
+
await expect(result).rejects.toBeInstanceOf(FailedAcquireWriterLockError);
|
|
1043
|
+
});
|
|
1044
|
+
test("Should not update state when key is acquired as reader", async () => {
|
|
1045
|
+
const key = "a";
|
|
1046
|
+
const limit = 3;
|
|
1047
|
+
const ttl = null;
|
|
1048
|
+
const sharedLock = sharedLockProvider.create(key, {
|
|
1088
1049
|
limit,
|
|
1050
|
+
ttl,
|
|
1089
1051
|
});
|
|
1090
|
-
await
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1052
|
+
await sharedLock.acquireReader();
|
|
1053
|
+
try {
|
|
1054
|
+
await sharedLock.acquireWriterOrFail();
|
|
1055
|
+
}
|
|
1056
|
+
catch {
|
|
1057
|
+
/* EMPTY */
|
|
1058
|
+
}
|
|
1059
|
+
const state = await sharedLock.getState();
|
|
1060
|
+
expect(state).toEqual({
|
|
1061
|
+
type: SHARED_LOCK_STATE.READER_ACQUIRED,
|
|
1062
|
+
limit,
|
|
1063
|
+
remainingTime: null,
|
|
1064
|
+
freeSlotsCount: 2,
|
|
1065
|
+
acquiredSlotsCount: 1,
|
|
1066
|
+
acquiredSlots: [sharedLock.id],
|
|
1095
1067
|
});
|
|
1096
|
-
expect(handlerFn.mock.calls.length).toBeGreaterThan(1);
|
|
1097
1068
|
});
|
|
1098
|
-
|
|
1069
|
+
});
|
|
1070
|
+
describe("method: acquireWriterBlocking", () => {
|
|
1071
|
+
test("Should return true when key doesnt exists", async () => {
|
|
1099
1072
|
const key = "a";
|
|
1100
|
-
const ttl =
|
|
1073
|
+
const ttl = null;
|
|
1101
1074
|
const limit = 4;
|
|
1102
|
-
const
|
|
1103
|
-
|
|
1075
|
+
const result = await sharedLockProvider
|
|
1076
|
+
.create(key, {
|
|
1104
1077
|
limit,
|
|
1105
|
-
});
|
|
1106
|
-
await sharedLock1.acquireReader();
|
|
1107
|
-
const handlerFn = vi.fn(() => { });
|
|
1108
|
-
await sharedLockProvider.addListener(SHARED_LOCK_EVENTS.UNAVAILABLE, handlerFn);
|
|
1109
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1110
1078
|
ttl,
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
return Promise.resolve(RETURN_VALUE);
|
|
1115
|
-
}, {
|
|
1116
|
-
time: TimeSpan.fromMilliseconds(55),
|
|
1079
|
+
})
|
|
1080
|
+
.acquireWriterBlocking({
|
|
1081
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
1117
1082
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1118
1083
|
});
|
|
1119
|
-
expect(
|
|
1084
|
+
expect(result).toBe(true);
|
|
1120
1085
|
});
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1086
|
+
test("Should return true when key is expired", {
|
|
1087
|
+
retry: 10,
|
|
1088
|
+
}, async () => {
|
|
1124
1089
|
const key = "a";
|
|
1125
|
-
const ttl = null;
|
|
1126
1090
|
const limit = 4;
|
|
1091
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1127
1092
|
const sharedLock = sharedLockProvider.create(key, {
|
|
1128
|
-
ttl,
|
|
1129
1093
|
limit,
|
|
1094
|
+
ttl,
|
|
1130
1095
|
});
|
|
1131
|
-
|
|
1132
|
-
await
|
|
1133
|
-
|
|
1134
|
-
}, {
|
|
1096
|
+
await sharedLock.acquireWriter();
|
|
1097
|
+
await delay(ttl);
|
|
1098
|
+
const result = await sharedLock.acquireWriterBlocking({
|
|
1135
1099
|
time: TimeSpan.fromMilliseconds(5),
|
|
1136
1100
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1137
1101
|
});
|
|
1138
|
-
expect(
|
|
1102
|
+
expect(result).toBe(true);
|
|
1139
1103
|
});
|
|
1140
|
-
test("Should
|
|
1104
|
+
test("Should return true when key is unexpireable and acquired by same owner", async () => {
|
|
1141
1105
|
const key = "a";
|
|
1142
|
-
const ttl = null;
|
|
1143
1106
|
const limit = 4;
|
|
1107
|
+
const ttl = null;
|
|
1144
1108
|
const sharedLock = sharedLockProvider.create(key, {
|
|
1145
1109
|
ttl,
|
|
1146
1110
|
limit,
|
|
1147
1111
|
});
|
|
1148
|
-
|
|
1149
|
-
const
|
|
1150
|
-
await sharedLock.runWriterBlockingOrFail(() => {
|
|
1151
|
-
return Promise.resolve(RETURN_VALUE);
|
|
1152
|
-
}, {
|
|
1112
|
+
await sharedLock.acquireWriter();
|
|
1113
|
+
const result = await sharedLock.acquireWriterBlocking({
|
|
1153
1114
|
time: TimeSpan.fromMilliseconds(5),
|
|
1154
1115
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1155
1116
|
});
|
|
1156
|
-
expect(
|
|
1117
|
+
expect(result).toBe(true);
|
|
1157
1118
|
});
|
|
1158
|
-
test("Should
|
|
1119
|
+
test("Should return true when key is unexpired and acquired by same owner", async () => {
|
|
1159
1120
|
const key = "a";
|
|
1160
|
-
const ttl = null;
|
|
1161
1121
|
const limit = 4;
|
|
1122
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1162
1123
|
const sharedLock = sharedLockProvider.create(key, {
|
|
1163
1124
|
ttl,
|
|
1164
1125
|
limit,
|
|
1165
1126
|
});
|
|
1166
|
-
|
|
1167
|
-
await sharedLock.
|
|
1168
|
-
return Promise.resolve(RETURN_VALUE);
|
|
1169
|
-
}, {
|
|
1127
|
+
await sharedLock.acquireWriter();
|
|
1128
|
+
const result = await sharedLock.acquireWriterBlocking({
|
|
1170
1129
|
time: TimeSpan.fromMilliseconds(5),
|
|
1171
1130
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1172
1131
|
});
|
|
1173
|
-
expect(
|
|
1132
|
+
expect(result).toBe(true);
|
|
1174
1133
|
});
|
|
1175
|
-
test("Should
|
|
1134
|
+
test("Should return false when key is unexpireable and acquired by different owner", async () => {
|
|
1176
1135
|
const key = "a";
|
|
1177
1136
|
const ttl = null;
|
|
1178
1137
|
const limit = 4;
|
|
1179
|
-
const
|
|
1138
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1180
1139
|
ttl,
|
|
1181
1140
|
limit,
|
|
1182
1141
|
});
|
|
1183
|
-
|
|
1184
|
-
const
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
}
|
|
1142
|
+
await sharedLock1.acquireWriter();
|
|
1143
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1144
|
+
ttl,
|
|
1145
|
+
limit,
|
|
1146
|
+
});
|
|
1147
|
+
const result = await sharedLock2.acquireWriterBlocking({
|
|
1188
1148
|
time: TimeSpan.fromMilliseconds(5),
|
|
1189
1149
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1190
1150
|
});
|
|
1191
|
-
expect(
|
|
1151
|
+
expect(result).toBe(false);
|
|
1192
1152
|
});
|
|
1193
|
-
test("Should
|
|
1153
|
+
test("Should return false when key is unexpired and acquired by different owner", async () => {
|
|
1194
1154
|
const key = "a";
|
|
1195
|
-
const ttl = null;
|
|
1196
1155
|
const limit = 4;
|
|
1197
|
-
const
|
|
1156
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1157
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1158
|
+
limit,
|
|
1198
1159
|
ttl,
|
|
1160
|
+
});
|
|
1161
|
+
await sharedLock1.acquireWriter();
|
|
1162
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1199
1163
|
limit,
|
|
1164
|
+
ttl,
|
|
1200
1165
|
});
|
|
1201
|
-
const
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
1207
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1208
|
-
});
|
|
1209
|
-
}
|
|
1210
|
-
catch {
|
|
1211
|
-
/* EMPTY */
|
|
1212
|
-
}
|
|
1213
|
-
expect(releaseSpy).toHaveBeenCalledTimes(1);
|
|
1166
|
+
const result = await sharedLock2.acquireWriterBlocking({
|
|
1167
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
1168
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
1169
|
+
});
|
|
1170
|
+
expect(result).toBe(false);
|
|
1214
1171
|
});
|
|
1215
|
-
test("Should
|
|
1172
|
+
test("Should return false when key is acquired as reader", async () => {
|
|
1216
1173
|
const key = "a";
|
|
1174
|
+
const limit = 2;
|
|
1217
1175
|
const ttl = null;
|
|
1218
|
-
const limit = 4;
|
|
1219
1176
|
const sharedLock = sharedLockProvider.create(key, {
|
|
1220
|
-
ttl,
|
|
1221
1177
|
limit,
|
|
1178
|
+
ttl,
|
|
1222
1179
|
});
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
const error = sharedLock.runWriterBlockingOrFail(() => {
|
|
1226
|
-
return Promise.reject(new CustomError());
|
|
1227
|
-
}, {
|
|
1180
|
+
await sharedLock.acquireReader();
|
|
1181
|
+
const result = await sharedLock.acquireWriterBlocking({
|
|
1228
1182
|
time: TimeSpan.fromMilliseconds(5),
|
|
1229
1183
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1230
1184
|
});
|
|
1231
|
-
|
|
1185
|
+
expect(result).toBe(false);
|
|
1232
1186
|
});
|
|
1233
|
-
test("Should
|
|
1187
|
+
test("Should not update state when key is acquired as reader", async () => {
|
|
1234
1188
|
const key = "a";
|
|
1189
|
+
const limit = 3;
|
|
1235
1190
|
const ttl = null;
|
|
1236
|
-
const
|
|
1237
|
-
const handlerFn = vi.fn(() => {
|
|
1238
|
-
return Promise.resolve(RETURN_VALUE);
|
|
1239
|
-
});
|
|
1240
|
-
await sharedLockProvider
|
|
1241
|
-
.create(key, {
|
|
1242
|
-
ttl,
|
|
1191
|
+
const sharedLock = sharedLockProvider.create(key, {
|
|
1243
1192
|
limit,
|
|
1244
|
-
|
|
1245
|
-
|
|
1193
|
+
ttl,
|
|
1194
|
+
});
|
|
1195
|
+
await sharedLock.acquireReader();
|
|
1196
|
+
await sharedLock.acquireWriterBlocking({
|
|
1246
1197
|
time: TimeSpan.fromMilliseconds(5),
|
|
1247
1198
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1248
1199
|
});
|
|
1249
|
-
|
|
1200
|
+
const state = await sharedLock.getState();
|
|
1201
|
+
expect(state).toEqual({
|
|
1202
|
+
type: SHARED_LOCK_STATE.READER_ACQUIRED,
|
|
1203
|
+
limit,
|
|
1204
|
+
remainingTime: null,
|
|
1205
|
+
freeSlotsCount: 2,
|
|
1206
|
+
acquiredSlotsCount: 1,
|
|
1207
|
+
acquiredSlots: [sharedLock.id],
|
|
1208
|
+
});
|
|
1250
1209
|
});
|
|
1251
|
-
test("Should
|
|
1252
|
-
retry: 10,
|
|
1253
|
-
}, async () => {
|
|
1210
|
+
test("Should retry acquire the shared lock when blocked by a writer", async () => {
|
|
1254
1211
|
const key = "a";
|
|
1255
1212
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1256
1213
|
const limit = 4;
|
|
1257
|
-
|
|
1258
|
-
.create(key, {
|
|
1259
|
-
ttl,
|
|
1260
|
-
limit,
|
|
1261
|
-
})
|
|
1262
|
-
.acquireWriter();
|
|
1263
|
-
await delay(ttl);
|
|
1264
|
-
const handlerFn = vi.fn(() => {
|
|
1265
|
-
return Promise.resolve(RETURN_VALUE);
|
|
1266
|
-
});
|
|
1267
|
-
await sharedLockProvider
|
|
1268
|
-
.create(key, {
|
|
1214
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1269
1215
|
ttl,
|
|
1270
1216
|
limit,
|
|
1271
|
-
})
|
|
1272
|
-
.runWriterBlockingOrFail(handlerFn, {
|
|
1273
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
1274
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1275
1217
|
});
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
const
|
|
1280
|
-
const ttl = null;
|
|
1281
|
-
const limit = 4;
|
|
1282
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
1218
|
+
await sharedLock1.acquireWriter();
|
|
1219
|
+
const handlerFn = vi.fn(() => { });
|
|
1220
|
+
await sharedLockProvider.addListener(SHARED_LOCK_EVENTS.UNAVAILABLE, handlerFn);
|
|
1221
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1283
1222
|
ttl,
|
|
1284
1223
|
limit,
|
|
1285
1224
|
});
|
|
1286
|
-
await
|
|
1287
|
-
|
|
1288
|
-
|
|
1225
|
+
await sharedLock2.acquireWriterBlocking({
|
|
1226
|
+
time: TimeSpan.fromMilliseconds(55),
|
|
1227
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
1289
1228
|
});
|
|
1290
|
-
|
|
1291
|
-
await sharedLock.runWriterBlockingOrFail(handlerFn, {
|
|
1292
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
1293
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1294
|
-
});
|
|
1295
|
-
}
|
|
1296
|
-
catch {
|
|
1297
|
-
/* EMPTY */
|
|
1298
|
-
}
|
|
1299
|
-
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
1229
|
+
expect(handlerFn.mock.calls.length).toBeGreaterThan(1);
|
|
1300
1230
|
});
|
|
1301
|
-
test("Should
|
|
1231
|
+
test("Should retry acquire the shared lock when blocked by a reader", async () => {
|
|
1302
1232
|
const key = "a";
|
|
1303
1233
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1304
1234
|
const limit = 4;
|
|
1305
|
-
const
|
|
1235
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1306
1236
|
ttl,
|
|
1307
1237
|
limit,
|
|
1308
1238
|
});
|
|
1309
|
-
await
|
|
1310
|
-
const handlerFn = vi.fn(() => {
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
try {
|
|
1314
|
-
await sharedLock.runWriterBlockingOrFail(handlerFn, {
|
|
1315
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
1316
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1317
|
-
});
|
|
1318
|
-
}
|
|
1319
|
-
catch {
|
|
1320
|
-
/* EMPTY */
|
|
1321
|
-
}
|
|
1322
|
-
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
1323
|
-
});
|
|
1324
|
-
test("Should not call handler function when key is unexpireable and acquired by different lockId", async () => {
|
|
1325
|
-
const key = "a";
|
|
1326
|
-
const ttl = null;
|
|
1327
|
-
const limit = 4;
|
|
1328
|
-
await sharedLockProvider
|
|
1329
|
-
.create(key, {
|
|
1239
|
+
await sharedLock1.acquireReader();
|
|
1240
|
+
const handlerFn = vi.fn(() => { });
|
|
1241
|
+
await sharedLockProvider.addListener(SHARED_LOCK_EVENTS.UNAVAILABLE, handlerFn);
|
|
1242
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1330
1243
|
ttl,
|
|
1331
1244
|
limit,
|
|
1332
|
-
})
|
|
1333
|
-
.acquireWriter();
|
|
1334
|
-
const handlerFn = vi.fn(() => {
|
|
1335
|
-
return Promise.resolve(RETURN_VALUE);
|
|
1336
1245
|
});
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
ttl,
|
|
1341
|
-
limit,
|
|
1342
|
-
})
|
|
1343
|
-
.runWriterBlockingOrFail(handlerFn, {
|
|
1344
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
1345
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1346
|
-
});
|
|
1347
|
-
}
|
|
1348
|
-
catch {
|
|
1349
|
-
/* EMPTY */
|
|
1350
|
-
}
|
|
1351
|
-
expect(handlerFn).not.toHaveBeenCalled();
|
|
1352
|
-
});
|
|
1353
|
-
test("Should not call handler function when key is unexpired and acquired by different lockId", async () => {
|
|
1354
|
-
const key = "a";
|
|
1355
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1356
|
-
const limit = 4;
|
|
1357
|
-
await sharedLockProvider
|
|
1358
|
-
.create(key, {
|
|
1359
|
-
ttl,
|
|
1360
|
-
limit,
|
|
1361
|
-
})
|
|
1362
|
-
.acquireWriter();
|
|
1363
|
-
const handlerFn = vi.fn(() => {
|
|
1364
|
-
return Promise.resolve(RETURN_VALUE);
|
|
1246
|
+
await sharedLock2.acquireWriterBlocking({
|
|
1247
|
+
time: TimeSpan.fromMilliseconds(55),
|
|
1248
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
1365
1249
|
});
|
|
1366
|
-
|
|
1367
|
-
await sharedLockProvider
|
|
1368
|
-
.create(key, {
|
|
1369
|
-
ttl,
|
|
1370
|
-
limit,
|
|
1371
|
-
})
|
|
1372
|
-
.runWriterBlockingOrFail(handlerFn, {
|
|
1373
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
1374
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1375
|
-
});
|
|
1376
|
-
}
|
|
1377
|
-
catch {
|
|
1378
|
-
/* EMPTY */
|
|
1379
|
-
}
|
|
1380
|
-
expect(handlerFn).not.toHaveBeenCalled();
|
|
1250
|
+
expect(handlerFn.mock.calls.length).toBeGreaterThan(1);
|
|
1381
1251
|
});
|
|
1382
|
-
|
|
1252
|
+
});
|
|
1253
|
+
describe("method: acquireWriterBlockingOrFail", () => {
|
|
1254
|
+
test("Should not throw error when key doesnt exists", async () => {
|
|
1383
1255
|
const key = "a";
|
|
1384
1256
|
const ttl = null;
|
|
1385
1257
|
const limit = 4;
|
|
1386
|
-
const result =
|
|
1258
|
+
const result = sharedLockProvider
|
|
1387
1259
|
.create(key, {
|
|
1388
|
-
ttl,
|
|
1389
1260
|
limit,
|
|
1261
|
+
ttl,
|
|
1390
1262
|
})
|
|
1391
|
-
.
|
|
1392
|
-
return Promise.resolve(RETURN_VALUE);
|
|
1393
|
-
}, {
|
|
1263
|
+
.acquireWriterBlockingOrFail({
|
|
1394
1264
|
time: TimeSpan.fromMilliseconds(5),
|
|
1395
1265
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1396
1266
|
});
|
|
1397
|
-
expect(result).
|
|
1267
|
+
await expect(result).resolves.toBeUndefined();
|
|
1398
1268
|
});
|
|
1399
|
-
test("Should
|
|
1269
|
+
test("Should not throw error when key is expired", {
|
|
1400
1270
|
retry: 10,
|
|
1401
1271
|
}, async () => {
|
|
1402
1272
|
const key = "a";
|
|
1403
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1404
1273
|
const limit = 4;
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
ttl,
|
|
1274
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1275
|
+
const sharedLock = sharedLockProvider.create(key, {
|
|
1408
1276
|
limit,
|
|
1409
|
-
})
|
|
1410
|
-
.acquireWriter();
|
|
1411
|
-
await delay(ttl);
|
|
1412
|
-
const result = await sharedLockProvider
|
|
1413
|
-
.create(key, {
|
|
1414
1277
|
ttl,
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
}, {
|
|
1278
|
+
});
|
|
1279
|
+
await sharedLock.acquireWriter();
|
|
1280
|
+
await delay(ttl);
|
|
1281
|
+
const result = sharedLock.acquireWriterBlockingOrFail({
|
|
1420
1282
|
time: TimeSpan.fromMilliseconds(5),
|
|
1421
1283
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1422
1284
|
});
|
|
1423
|
-
expect(result).
|
|
1285
|
+
await expect(result).resolves.toBeUndefined();
|
|
1424
1286
|
});
|
|
1425
|
-
test("Should
|
|
1287
|
+
test("Should not throw error when key is unexpireable and acquired by same owner", async () => {
|
|
1426
1288
|
const key = "a";
|
|
1427
|
-
const ttl = null;
|
|
1428
1289
|
const limit = 4;
|
|
1290
|
+
const ttl = null;
|
|
1429
1291
|
const sharedLock = sharedLockProvider.create(key, {
|
|
1430
1292
|
ttl,
|
|
1431
1293
|
limit,
|
|
1432
1294
|
});
|
|
1433
1295
|
await sharedLock.acquireWriter();
|
|
1434
|
-
const result =
|
|
1435
|
-
return Promise.resolve(RETURN_VALUE);
|
|
1436
|
-
}, {
|
|
1296
|
+
const result = sharedLock.acquireWriterBlockingOrFail({
|
|
1437
1297
|
time: TimeSpan.fromMilliseconds(5),
|
|
1438
1298
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1439
1299
|
});
|
|
1440
|
-
expect(result).
|
|
1300
|
+
await expect(result).resolves.toBeUndefined();
|
|
1441
1301
|
});
|
|
1442
|
-
test("Should
|
|
1302
|
+
test("Should not throw error when key is unexpired and acquired by same owner", async () => {
|
|
1443
1303
|
const key = "a";
|
|
1444
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1445
1304
|
const limit = 4;
|
|
1305
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1446
1306
|
const sharedLock = sharedLockProvider.create(key, {
|
|
1447
1307
|
ttl,
|
|
1448
1308
|
limit,
|
|
1449
1309
|
});
|
|
1450
1310
|
await sharedLock.acquireWriter();
|
|
1451
|
-
const result =
|
|
1452
|
-
return Promise.resolve(RETURN_VALUE);
|
|
1453
|
-
}, {
|
|
1311
|
+
const result = sharedLock.acquireWriterBlockingOrFail({
|
|
1454
1312
|
time: TimeSpan.fromMilliseconds(5),
|
|
1455
1313
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1456
1314
|
});
|
|
1457
|
-
expect(result).
|
|
1315
|
+
await expect(result).resolves.toBeUndefined();
|
|
1458
1316
|
});
|
|
1459
|
-
test("Should throw FailedAcquireWriterLockError when key is unexpireable and acquired by different
|
|
1317
|
+
test("Should throw FailedAcquireWriterLockError when key is unexpireable and acquired by different owner", async () => {
|
|
1460
1318
|
const key = "a";
|
|
1461
1319
|
const ttl = null;
|
|
1462
1320
|
const limit = 4;
|
|
1463
|
-
|
|
1464
|
-
.create(key, {
|
|
1321
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1465
1322
|
ttl,
|
|
1466
1323
|
limit,
|
|
1467
|
-
})
|
|
1468
|
-
|
|
1469
|
-
const
|
|
1470
|
-
.create(key, {
|
|
1324
|
+
});
|
|
1325
|
+
await sharedLock1.acquireWriter();
|
|
1326
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1471
1327
|
ttl,
|
|
1472
1328
|
limit,
|
|
1473
|
-
})
|
|
1474
|
-
|
|
1475
|
-
return Promise.resolve(RETURN_VALUE);
|
|
1476
|
-
}, {
|
|
1329
|
+
});
|
|
1330
|
+
const result = sharedLock2.acquireWriterBlockingOrFail({
|
|
1477
1331
|
time: TimeSpan.fromMilliseconds(5),
|
|
1478
1332
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1479
1333
|
});
|
|
1480
1334
|
await expect(result).rejects.toBeInstanceOf(FailedAcquireWriterLockError);
|
|
1481
1335
|
});
|
|
1482
|
-
test("Should throw FailedAcquireWriterLockError when key is unexpired and acquired by different
|
|
1336
|
+
test("Should throw FailedAcquireWriterLockError when key is unexpired and acquired by different owner", async () => {
|
|
1483
1337
|
const key = "a";
|
|
1484
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1485
1338
|
const limit = 4;
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
ttl,
|
|
1339
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1340
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1489
1341
|
limit,
|
|
1490
|
-
})
|
|
1491
|
-
.acquireWriter();
|
|
1492
|
-
const result = sharedLockProvider
|
|
1493
|
-
.create(key, {
|
|
1494
1342
|
ttl,
|
|
1343
|
+
});
|
|
1344
|
+
await sharedLock1.acquireWriter();
|
|
1345
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1495
1346
|
limit,
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
}, {
|
|
1347
|
+
ttl,
|
|
1348
|
+
});
|
|
1349
|
+
const result = sharedLock2.acquireWriterBlockingOrFail({
|
|
1500
1350
|
time: TimeSpan.fromMilliseconds(5),
|
|
1501
1351
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1502
1352
|
});
|
|
1503
1353
|
await expect(result).rejects.toBeInstanceOf(FailedAcquireWriterLockError);
|
|
1504
1354
|
});
|
|
1505
|
-
test("Should
|
|
1355
|
+
test("Should throw FailedAcquireWriterLockError when key is acquired as reader", async () => {
|
|
1506
1356
|
const key = "a";
|
|
1507
|
-
const
|
|
1508
|
-
const
|
|
1509
|
-
const
|
|
1510
|
-
ttl,
|
|
1357
|
+
const limit = 2;
|
|
1358
|
+
const ttl = null;
|
|
1359
|
+
const sharedLock = sharedLockProvider.create(key, {
|
|
1511
1360
|
limit,
|
|
1512
|
-
});
|
|
1513
|
-
await sharedLock1.acquireWriter();
|
|
1514
|
-
const handlerFn = vi.fn(() => { });
|
|
1515
|
-
await sharedLockProvider.addListener(SHARED_LOCK_EVENTS.UNAVAILABLE, handlerFn);
|
|
1516
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1517
1361
|
ttl,
|
|
1518
|
-
limit,
|
|
1519
1362
|
});
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1363
|
+
await sharedLock.acquireReader();
|
|
1364
|
+
const result = sharedLock.acquireWriterBlockingOrFail({
|
|
1365
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
1366
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
1367
|
+
});
|
|
1368
|
+
await expect(result).rejects.toBeInstanceOf(FailedAcquireWriterLockError);
|
|
1369
|
+
});
|
|
1370
|
+
test("Should not update state when key is acquired as reader", async () => {
|
|
1371
|
+
const key = "a";
|
|
1372
|
+
const limit = 3;
|
|
1373
|
+
const ttl = null;
|
|
1374
|
+
const sharedLock = sharedLockProvider.create(key, {
|
|
1375
|
+
limit,
|
|
1376
|
+
ttl,
|
|
1377
|
+
});
|
|
1378
|
+
await sharedLock.acquireReader();
|
|
1379
|
+
try {
|
|
1380
|
+
await sharedLock.acquireWriterBlockingOrFail({
|
|
1381
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
1382
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
catch {
|
|
1386
|
+
/* EMPTY */
|
|
1387
|
+
}
|
|
1388
|
+
const state = await sharedLock.getState();
|
|
1389
|
+
expect(state).toEqual({
|
|
1390
|
+
type: SHARED_LOCK_STATE.READER_ACQUIRED,
|
|
1391
|
+
limit,
|
|
1392
|
+
remainingTime: null,
|
|
1393
|
+
freeSlotsCount: 2,
|
|
1394
|
+
acquiredSlotsCount: 1,
|
|
1395
|
+
acquiredSlots: [sharedLock.id],
|
|
1396
|
+
});
|
|
1397
|
+
});
|
|
1398
|
+
test("Should retry acquire the shared lock when blocked by a writer", async () => {
|
|
1399
|
+
const key = "a";
|
|
1400
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1401
|
+
const limit = 4;
|
|
1402
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1403
|
+
ttl,
|
|
1404
|
+
limit,
|
|
1405
|
+
});
|
|
1406
|
+
await sharedLock1.acquireWriter();
|
|
1407
|
+
const handlerFn = vi.fn(() => { });
|
|
1408
|
+
await sharedLockProvider.addListener(SHARED_LOCK_EVENTS.UNAVAILABLE, handlerFn);
|
|
1409
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1410
|
+
ttl,
|
|
1411
|
+
limit,
|
|
1412
|
+
});
|
|
1413
|
+
try {
|
|
1414
|
+
await sharedLock2.acquireWriterBlockingOrFail({
|
|
1415
|
+
time: TimeSpan.fromMilliseconds(55),
|
|
1525
1416
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1526
1417
|
});
|
|
1527
1418
|
}
|
|
@@ -1546,9 +1437,7 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
1546
1437
|
limit,
|
|
1547
1438
|
});
|
|
1548
1439
|
try {
|
|
1549
|
-
await sharedLock2.
|
|
1550
|
-
return Promise.resolve(RETURN_VALUE);
|
|
1551
|
-
}, {
|
|
1440
|
+
await sharedLock2.acquireWriterBlockingOrFail({
|
|
1552
1441
|
time: TimeSpan.fromMilliseconds(55),
|
|
1553
1442
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1554
1443
|
});
|
|
@@ -1559,59 +1448,109 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
1559
1448
|
expect(handlerFn.mock.calls.length).toBeGreaterThan(1);
|
|
1560
1449
|
});
|
|
1561
1450
|
});
|
|
1562
|
-
describe("method:
|
|
1563
|
-
test("Should return
|
|
1451
|
+
describe("method: releaseWriter", () => {
|
|
1452
|
+
test("Should return false when key doesnt exists", async () => {
|
|
1564
1453
|
const key = "a";
|
|
1565
1454
|
const ttl = null;
|
|
1566
1455
|
const limit = 4;
|
|
1567
|
-
const
|
|
1568
|
-
|
|
1456
|
+
const sharedLock = sharedLockProvider.create(key, {
|
|
1457
|
+
ttl,
|
|
1569
1458
|
limit,
|
|
1459
|
+
});
|
|
1460
|
+
const result = await sharedLock.releaseWriter();
|
|
1461
|
+
expect(result).toBe(false);
|
|
1462
|
+
});
|
|
1463
|
+
test("Should return false when key is unexpireable and released by different owner", async () => {
|
|
1464
|
+
const key = "a";
|
|
1465
|
+
const ttl = null;
|
|
1466
|
+
const limit = 4;
|
|
1467
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1570
1468
|
ttl,
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1469
|
+
limit,
|
|
1470
|
+
});
|
|
1471
|
+
await sharedLock1.acquireWriter();
|
|
1472
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1473
|
+
ttl,
|
|
1474
|
+
limit,
|
|
1475
|
+
});
|
|
1476
|
+
const result = await sharedLock2.releaseWriter();
|
|
1477
|
+
expect(result).toBe(false);
|
|
1574
1478
|
});
|
|
1575
|
-
test("Should return
|
|
1479
|
+
test("Should return false when key is unexpired and released by different owner", async () => {
|
|
1480
|
+
const key = "a";
|
|
1481
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1482
|
+
const limit = 4;
|
|
1483
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1484
|
+
limit,
|
|
1485
|
+
ttl,
|
|
1486
|
+
});
|
|
1487
|
+
await sharedLock1.acquireWriter();
|
|
1488
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1489
|
+
limit,
|
|
1490
|
+
ttl,
|
|
1491
|
+
});
|
|
1492
|
+
const result = await sharedLock2.releaseWriter();
|
|
1493
|
+
expect(result).toBe(false);
|
|
1494
|
+
});
|
|
1495
|
+
test("Should return false when key is expired and released by different owner", {
|
|
1576
1496
|
retry: 10,
|
|
1577
1497
|
}, async () => {
|
|
1578
1498
|
const key = "a";
|
|
1499
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1579
1500
|
const limit = 4;
|
|
1501
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1502
|
+
ttl,
|
|
1503
|
+
limit,
|
|
1504
|
+
});
|
|
1505
|
+
await sharedLock1.acquireWriter();
|
|
1506
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1507
|
+
ttl,
|
|
1508
|
+
limit,
|
|
1509
|
+
});
|
|
1510
|
+
const result = await sharedLock2.releaseWriter();
|
|
1511
|
+
await delay(ttl);
|
|
1512
|
+
expect(result).toBe(false);
|
|
1513
|
+
});
|
|
1514
|
+
test("Should return false when key is expired and released by same owner", {
|
|
1515
|
+
retry: 10,
|
|
1516
|
+
}, async () => {
|
|
1517
|
+
const key = "a";
|
|
1580
1518
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1519
|
+
const limit = 4;
|
|
1581
1520
|
const sharedLock = sharedLockProvider.create(key, {
|
|
1582
|
-
limit,
|
|
1583
1521
|
ttl,
|
|
1522
|
+
limit,
|
|
1584
1523
|
});
|
|
1585
1524
|
await sharedLock.acquireWriter();
|
|
1586
1525
|
await delay(ttl);
|
|
1587
|
-
const result = await sharedLock.
|
|
1588
|
-
expect(result).toBe(
|
|
1526
|
+
const result = await sharedLock.releaseWriter();
|
|
1527
|
+
expect(result).toBe(false);
|
|
1589
1528
|
});
|
|
1590
|
-
test("Should return true when key is unexpireable and
|
|
1529
|
+
test("Should return true when key is unexpireable and released by same owner", async () => {
|
|
1591
1530
|
const key = "a";
|
|
1592
|
-
const limit = 4;
|
|
1593
1531
|
const ttl = null;
|
|
1532
|
+
const limit = 4;
|
|
1594
1533
|
const sharedLock = sharedLockProvider.create(key, {
|
|
1595
1534
|
ttl,
|
|
1596
1535
|
limit,
|
|
1597
1536
|
});
|
|
1598
1537
|
await sharedLock.acquireWriter();
|
|
1599
|
-
const result = await sharedLock.
|
|
1538
|
+
const result = await sharedLock.releaseWriter();
|
|
1600
1539
|
expect(result).toBe(true);
|
|
1601
1540
|
});
|
|
1602
|
-
test("Should return true when key is unexpired and
|
|
1541
|
+
test("Should return true when key is unexpired and released by same owner", async () => {
|
|
1603
1542
|
const key = "a";
|
|
1604
|
-
const limit = 4;
|
|
1605
1543
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1544
|
+
const limit = 4;
|
|
1606
1545
|
const sharedLock = sharedLockProvider.create(key, {
|
|
1607
1546
|
ttl,
|
|
1608
1547
|
limit,
|
|
1609
1548
|
});
|
|
1610
1549
|
await sharedLock.acquireWriter();
|
|
1611
|
-
const result = await sharedLock.
|
|
1550
|
+
const result = await sharedLock.releaseWriter();
|
|
1612
1551
|
expect(result).toBe(true);
|
|
1613
1552
|
});
|
|
1614
|
-
test("Should
|
|
1553
|
+
test("Should not be reacquirable when key is unexpireable and released by different owner", async () => {
|
|
1615
1554
|
const key = "a";
|
|
1616
1555
|
const ttl = null;
|
|
1617
1556
|
const limit = 4;
|
|
@@ -1624,35 +1563,71 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
1624
1563
|
ttl,
|
|
1625
1564
|
limit,
|
|
1626
1565
|
});
|
|
1566
|
+
await sharedLock2.releaseWriter();
|
|
1627
1567
|
const result = await sharedLock2.acquireWriter();
|
|
1628
1568
|
expect(result).toBe(false);
|
|
1629
1569
|
});
|
|
1630
|
-
test("Should
|
|
1570
|
+
test("Should not be reacquirable when key is unexpired and released by different owner", async () => {
|
|
1631
1571
|
const key = "a";
|
|
1632
|
-
const limit = 4;
|
|
1633
1572
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1573
|
+
const limit = 4;
|
|
1634
1574
|
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1575
|
+
ttl,
|
|
1576
|
+
limit,
|
|
1577
|
+
});
|
|
1578
|
+
await sharedLock1.acquireWriter();
|
|
1579
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1580
|
+
ttl,
|
|
1635
1581
|
limit,
|
|
1582
|
+
});
|
|
1583
|
+
await sharedLock2.releaseWriter();
|
|
1584
|
+
const result = await sharedLock2.acquireWriter();
|
|
1585
|
+
expect(result).toBe(false);
|
|
1586
|
+
});
|
|
1587
|
+
test("Should be reacquirable when key is unexpireable and released by same owner", async () => {
|
|
1588
|
+
const key = "a";
|
|
1589
|
+
const ttl = null;
|
|
1590
|
+
const limit = 4;
|
|
1591
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1636
1592
|
ttl,
|
|
1593
|
+
limit,
|
|
1637
1594
|
});
|
|
1638
1595
|
await sharedLock1.acquireWriter();
|
|
1596
|
+
await sharedLock1.releaseWriter();
|
|
1639
1597
|
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1598
|
+
ttl,
|
|
1599
|
+
limit,
|
|
1600
|
+
});
|
|
1601
|
+
const result = await sharedLock2.acquireWriter();
|
|
1602
|
+
expect(result).toBe(true);
|
|
1603
|
+
});
|
|
1604
|
+
test("Should be reacquirable when key is unexpired and released by same owner", async () => {
|
|
1605
|
+
const key = "a";
|
|
1606
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1607
|
+
const limit = 4;
|
|
1608
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1609
|
+
ttl,
|
|
1640
1610
|
limit,
|
|
1611
|
+
});
|
|
1612
|
+
await sharedLock1.acquireWriter();
|
|
1613
|
+
await sharedLock1.releaseWriter();
|
|
1614
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1641
1615
|
ttl,
|
|
1616
|
+
limit,
|
|
1642
1617
|
});
|
|
1643
1618
|
const result = await sharedLock2.acquireWriter();
|
|
1644
|
-
expect(result).toBe(
|
|
1619
|
+
expect(result).toBe(true);
|
|
1645
1620
|
});
|
|
1646
1621
|
test("Should return false when key is acquired as reader", async () => {
|
|
1647
1622
|
const key = "a";
|
|
1648
1623
|
const limit = 2;
|
|
1649
|
-
const ttl =
|
|
1624
|
+
const ttl = TimeSpan.fromSeconds(10);
|
|
1650
1625
|
const sharedLock = sharedLockProvider.create(key, {
|
|
1651
|
-
limit,
|
|
1652
1626
|
ttl,
|
|
1627
|
+
limit,
|
|
1653
1628
|
});
|
|
1654
1629
|
await sharedLock.acquireReader();
|
|
1655
|
-
const result = await sharedLock.
|
|
1630
|
+
const result = await sharedLock.releaseWriter();
|
|
1656
1631
|
expect(result).toBe(false);
|
|
1657
1632
|
});
|
|
1658
1633
|
test("Should not update state when key is acquired as reader", async () => {
|
|
@@ -1660,11 +1635,11 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
1660
1635
|
const limit = 3;
|
|
1661
1636
|
const ttl = null;
|
|
1662
1637
|
const sharedLock = sharedLockProvider.create(key, {
|
|
1663
|
-
limit,
|
|
1664
1638
|
ttl,
|
|
1639
|
+
limit,
|
|
1665
1640
|
});
|
|
1666
1641
|
await sharedLock.acquireReader();
|
|
1667
|
-
await sharedLock.
|
|
1642
|
+
await sharedLock.releaseWriter();
|
|
1668
1643
|
const state = await sharedLock.getState();
|
|
1669
1644
|
expect(state).toEqual({
|
|
1670
1645
|
type: SHARED_LOCK_STATE.READER_ACQUIRED,
|
|
@@ -1676,59 +1651,19 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
1676
1651
|
});
|
|
1677
1652
|
});
|
|
1678
1653
|
});
|
|
1679
|
-
describe("method:
|
|
1680
|
-
test("Should
|
|
1681
|
-
const key = "a";
|
|
1682
|
-
const ttl = null;
|
|
1683
|
-
const limit = 4;
|
|
1684
|
-
const result = sharedLockProvider
|
|
1685
|
-
.create(key, {
|
|
1686
|
-
limit,
|
|
1687
|
-
ttl,
|
|
1688
|
-
})
|
|
1689
|
-
.acquireWriterOrFail();
|
|
1690
|
-
await expect(result).resolves.toBeUndefined();
|
|
1691
|
-
});
|
|
1692
|
-
test("Should not throw error when key is expired", {
|
|
1693
|
-
retry: 10,
|
|
1694
|
-
}, async () => {
|
|
1695
|
-
const key = "a";
|
|
1696
|
-
const limit = 4;
|
|
1697
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1698
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
1699
|
-
limit,
|
|
1700
|
-
ttl,
|
|
1701
|
-
});
|
|
1702
|
-
await sharedLock.acquireWriterOrFail();
|
|
1703
|
-
await delay(ttl);
|
|
1704
|
-
const result = sharedLock.acquireWriterOrFail();
|
|
1705
|
-
await expect(result).resolves.toBeUndefined();
|
|
1706
|
-
});
|
|
1707
|
-
test("Should not throw error when key is unexpireable and acquired by same owner", async () => {
|
|
1654
|
+
describe("method: releaseWriterOrFail", () => {
|
|
1655
|
+
test("Should throw FailedReleaseWriterLockError when key doesnt exists", async () => {
|
|
1708
1656
|
const key = "a";
|
|
1709
|
-
const limit = 4;
|
|
1710
1657
|
const ttl = null;
|
|
1711
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
1712
|
-
ttl,
|
|
1713
|
-
limit,
|
|
1714
|
-
});
|
|
1715
|
-
await sharedLock.acquireWriterOrFail();
|
|
1716
|
-
const result = sharedLock.acquireWriterOrFail();
|
|
1717
|
-
await expect(result).resolves.toBeUndefined();
|
|
1718
|
-
});
|
|
1719
|
-
test("Should not throw error when key is unexpired and acquired by same owner", async () => {
|
|
1720
|
-
const key = "a";
|
|
1721
1658
|
const limit = 4;
|
|
1722
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1723
1659
|
const sharedLock = sharedLockProvider.create(key, {
|
|
1724
1660
|
ttl,
|
|
1725
1661
|
limit,
|
|
1726
1662
|
});
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
await expect(result).resolves.toBeUndefined();
|
|
1663
|
+
const result = sharedLock.releaseWriterOrFail();
|
|
1664
|
+
await expect(result).rejects.toBeInstanceOf(FailedReleaseWriterLockError);
|
|
1730
1665
|
});
|
|
1731
|
-
test("Should throw
|
|
1666
|
+
test("Should throw FailedReleaseWriterLockError when key is unexpireable and released by different owner", async () => {
|
|
1732
1667
|
const key = "a";
|
|
1733
1668
|
const ttl = null;
|
|
1734
1669
|
const limit = 4;
|
|
@@ -1736,133 +1671,133 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
1736
1671
|
ttl,
|
|
1737
1672
|
limit,
|
|
1738
1673
|
});
|
|
1739
|
-
await sharedLock1.
|
|
1674
|
+
await sharedLock1.acquireWriter();
|
|
1740
1675
|
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1741
1676
|
ttl,
|
|
1742
1677
|
limit,
|
|
1743
1678
|
});
|
|
1744
|
-
const result = sharedLock2.
|
|
1745
|
-
await expect(result).rejects.toBeInstanceOf(
|
|
1679
|
+
const result = sharedLock2.releaseWriterOrFail();
|
|
1680
|
+
await expect(result).rejects.toBeInstanceOf(FailedReleaseWriterLockError);
|
|
1746
1681
|
});
|
|
1747
|
-
test("Should throw
|
|
1682
|
+
test("Should throw FailedReleaseWriterLockError when key is unexpired and released by different owner", async () => {
|
|
1748
1683
|
const key = "a";
|
|
1749
|
-
const limit = 4;
|
|
1750
1684
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1685
|
+
const limit = 4;
|
|
1751
1686
|
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1752
1687
|
limit,
|
|
1753
1688
|
ttl,
|
|
1754
1689
|
});
|
|
1755
|
-
await sharedLock1.
|
|
1690
|
+
await sharedLock1.acquireWriter();
|
|
1756
1691
|
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1757
1692
|
limit,
|
|
1758
1693
|
ttl,
|
|
1759
1694
|
});
|
|
1760
|
-
const result = sharedLock2.
|
|
1761
|
-
await expect(result).rejects.toBeInstanceOf(
|
|
1695
|
+
const result = sharedLock2.releaseWriterOrFail();
|
|
1696
|
+
await expect(result).rejects.toBeInstanceOf(FailedReleaseWriterLockError);
|
|
1762
1697
|
});
|
|
1763
|
-
test("Should throw
|
|
1698
|
+
test("Should throw FailedReleaseWriterLockError when key is expired and released by different owner", {
|
|
1699
|
+
retry: 10,
|
|
1700
|
+
}, async () => {
|
|
1764
1701
|
const key = "a";
|
|
1765
|
-
const
|
|
1766
|
-
const
|
|
1767
|
-
const
|
|
1702
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1703
|
+
const limit = 4;
|
|
1704
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1705
|
+
ttl,
|
|
1768
1706
|
limit,
|
|
1707
|
+
});
|
|
1708
|
+
await sharedLock1.acquireWriter();
|
|
1709
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1769
1710
|
ttl,
|
|
1711
|
+
limit,
|
|
1770
1712
|
});
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
await expect(result).rejects.toBeInstanceOf(
|
|
1713
|
+
const result = sharedLock2.releaseWriterOrFail();
|
|
1714
|
+
await delay(ttl);
|
|
1715
|
+
await expect(result).rejects.toBeInstanceOf(FailedReleaseWriterLockError);
|
|
1774
1716
|
});
|
|
1775
|
-
test("Should
|
|
1717
|
+
test("Should throw FailedReleaseWriterLockError when key is expired and released by same owner", {
|
|
1718
|
+
retry: 10,
|
|
1719
|
+
}, async () => {
|
|
1776
1720
|
const key = "a";
|
|
1777
|
-
const
|
|
1778
|
-
const
|
|
1721
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1722
|
+
const limit = 4;
|
|
1779
1723
|
const sharedLock = sharedLockProvider.create(key, {
|
|
1780
|
-
limit,
|
|
1781
1724
|
ttl,
|
|
1782
|
-
});
|
|
1783
|
-
await sharedLock.acquireReader();
|
|
1784
|
-
try {
|
|
1785
|
-
await sharedLock.acquireWriterOrFail();
|
|
1786
|
-
}
|
|
1787
|
-
catch {
|
|
1788
|
-
/* EMPTY */
|
|
1789
|
-
}
|
|
1790
|
-
const state = await sharedLock.getState();
|
|
1791
|
-
expect(state).toEqual({
|
|
1792
|
-
type: SHARED_LOCK_STATE.READER_ACQUIRED,
|
|
1793
1725
|
limit,
|
|
1794
|
-
remainingTime: null,
|
|
1795
|
-
freeSlotsCount: 2,
|
|
1796
|
-
acquiredSlotsCount: 1,
|
|
1797
|
-
acquiredSlots: [sharedLock.id],
|
|
1798
1726
|
});
|
|
1727
|
+
await sharedLock.acquireWriter();
|
|
1728
|
+
await delay(ttl);
|
|
1729
|
+
const result = sharedLock.releaseWriterOrFail();
|
|
1730
|
+
await expect(result).rejects.toBeInstanceOf(FailedReleaseWriterLockError);
|
|
1799
1731
|
});
|
|
1800
|
-
|
|
1801
|
-
describe("method: acquireWriterBlocking", () => {
|
|
1802
|
-
test("Should return true when key doesnt exists", async () => {
|
|
1732
|
+
test("Should not throw error when key is unexpireable and released by same owner", async () => {
|
|
1803
1733
|
const key = "a";
|
|
1804
1734
|
const ttl = null;
|
|
1805
1735
|
const limit = 4;
|
|
1806
|
-
const
|
|
1807
|
-
.create(key, {
|
|
1808
|
-
limit,
|
|
1736
|
+
const sharedLock = sharedLockProvider.create(key, {
|
|
1809
1737
|
ttl,
|
|
1810
|
-
|
|
1811
|
-
.acquireWriterBlocking({
|
|
1812
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
1813
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1738
|
+
limit,
|
|
1814
1739
|
});
|
|
1815
|
-
|
|
1740
|
+
await sharedLock.acquireWriter();
|
|
1741
|
+
const result = sharedLock.releaseWriterOrFail();
|
|
1742
|
+
await expect(result).resolves.toBeUndefined();
|
|
1816
1743
|
});
|
|
1817
|
-
test("Should
|
|
1818
|
-
retry: 10,
|
|
1819
|
-
}, async () => {
|
|
1744
|
+
test("Should not throw error when key is unexpired and released by same owner", async () => {
|
|
1820
1745
|
const key = "a";
|
|
1821
|
-
const limit = 4;
|
|
1822
1746
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1747
|
+
const limit = 4;
|
|
1823
1748
|
const sharedLock = sharedLockProvider.create(key, {
|
|
1824
|
-
limit,
|
|
1825
1749
|
ttl,
|
|
1750
|
+
limit,
|
|
1826
1751
|
});
|
|
1827
1752
|
await sharedLock.acquireWriter();
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
1831
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1832
|
-
});
|
|
1833
|
-
expect(result).toBe(true);
|
|
1753
|
+
const result = sharedLock.releaseWriterOrFail();
|
|
1754
|
+
await expect(result).resolves.toBeUndefined();
|
|
1834
1755
|
});
|
|
1835
|
-
test("Should
|
|
1756
|
+
test("Should not be reacquirable when key is unexpireable and released by different owner", async () => {
|
|
1836
1757
|
const key = "a";
|
|
1837
|
-
const limit = 4;
|
|
1838
1758
|
const ttl = null;
|
|
1839
|
-
const
|
|
1759
|
+
const limit = 4;
|
|
1760
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1840
1761
|
ttl,
|
|
1841
1762
|
limit,
|
|
1842
1763
|
});
|
|
1843
|
-
await
|
|
1844
|
-
const
|
|
1845
|
-
|
|
1846
|
-
|
|
1764
|
+
await sharedLock1.acquireWriter();
|
|
1765
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1766
|
+
ttl,
|
|
1767
|
+
limit,
|
|
1847
1768
|
});
|
|
1848
|
-
|
|
1769
|
+
try {
|
|
1770
|
+
await sharedLock2.releaseWriterOrFail();
|
|
1771
|
+
}
|
|
1772
|
+
catch {
|
|
1773
|
+
/* EMPTY */
|
|
1774
|
+
}
|
|
1775
|
+
const result = await sharedLock2.acquireWriter();
|
|
1776
|
+
expect(result).toBe(false);
|
|
1849
1777
|
});
|
|
1850
|
-
test("Should
|
|
1778
|
+
test("Should not be reacquirable when key is unexpired and released by different owner", async () => {
|
|
1851
1779
|
const key = "a";
|
|
1852
|
-
const limit = 4;
|
|
1853
1780
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1854
|
-
const
|
|
1781
|
+
const limit = 4;
|
|
1782
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1855
1783
|
ttl,
|
|
1856
1784
|
limit,
|
|
1857
1785
|
});
|
|
1858
|
-
await
|
|
1859
|
-
const
|
|
1860
|
-
|
|
1861
|
-
|
|
1786
|
+
await sharedLock1.acquireWriter();
|
|
1787
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1788
|
+
ttl,
|
|
1789
|
+
limit,
|
|
1862
1790
|
});
|
|
1863
|
-
|
|
1791
|
+
try {
|
|
1792
|
+
await sharedLock2.releaseWriterOrFail();
|
|
1793
|
+
}
|
|
1794
|
+
catch {
|
|
1795
|
+
/* EMPTY */
|
|
1796
|
+
}
|
|
1797
|
+
const result = await sharedLock2.acquireWriter();
|
|
1798
|
+
expect(result).toBe(false);
|
|
1864
1799
|
});
|
|
1865
|
-
test("Should
|
|
1800
|
+
test("Should be reacquirable when key is unexpireable and released by same owner", async () => {
|
|
1866
1801
|
const key = "a";
|
|
1867
1802
|
const ttl = null;
|
|
1868
1803
|
const limit = 4;
|
|
@@ -1871,63 +1806,58 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
1871
1806
|
limit,
|
|
1872
1807
|
});
|
|
1873
1808
|
await sharedLock1.acquireWriter();
|
|
1809
|
+
await sharedLock1.releaseWriterOrFail();
|
|
1874
1810
|
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1875
1811
|
ttl,
|
|
1876
1812
|
limit,
|
|
1877
1813
|
});
|
|
1878
|
-
const result = await sharedLock2.
|
|
1879
|
-
|
|
1880
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1881
|
-
});
|
|
1882
|
-
expect(result).toBe(false);
|
|
1814
|
+
const result = await sharedLock2.acquireWriter();
|
|
1815
|
+
expect(result).toBe(true);
|
|
1883
1816
|
});
|
|
1884
|
-
test("Should
|
|
1817
|
+
test("Should be reacquirable when key is unexpired and released by same owner", async () => {
|
|
1885
1818
|
const key = "a";
|
|
1886
|
-
const limit = 4;
|
|
1887
1819
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1820
|
+
const limit = 4;
|
|
1888
1821
|
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1889
|
-
limit,
|
|
1890
1822
|
ttl,
|
|
1823
|
+
limit,
|
|
1891
1824
|
});
|
|
1892
1825
|
await sharedLock1.acquireWriter();
|
|
1826
|
+
await sharedLock1.releaseWriterOrFail();
|
|
1893
1827
|
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1894
|
-
limit,
|
|
1895
1828
|
ttl,
|
|
1829
|
+
limit,
|
|
1896
1830
|
});
|
|
1897
|
-
const result = await sharedLock2.
|
|
1898
|
-
|
|
1899
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1900
|
-
});
|
|
1901
|
-
expect(result).toBe(false);
|
|
1831
|
+
const result = await sharedLock2.acquireWriter();
|
|
1832
|
+
expect(result).toBe(true);
|
|
1902
1833
|
});
|
|
1903
|
-
test("Should
|
|
1834
|
+
test("Should throw FailedReleaseWriterLockError when key is acquired as reader", async () => {
|
|
1904
1835
|
const key = "a";
|
|
1905
1836
|
const limit = 2;
|
|
1906
|
-
const ttl =
|
|
1837
|
+
const ttl = TimeSpan.fromSeconds(10);
|
|
1907
1838
|
const sharedLock = sharedLockProvider.create(key, {
|
|
1908
|
-
limit,
|
|
1909
1839
|
ttl,
|
|
1840
|
+
limit,
|
|
1910
1841
|
});
|
|
1911
1842
|
await sharedLock.acquireReader();
|
|
1912
|
-
const result =
|
|
1913
|
-
|
|
1914
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1915
|
-
});
|
|
1916
|
-
expect(result).toBe(false);
|
|
1843
|
+
const result = sharedLock.releaseWriterOrFail();
|
|
1844
|
+
await expect(result).rejects.toBeInstanceOf(FailedReleaseWriterLockError);
|
|
1917
1845
|
});
|
|
1918
1846
|
test("Should not update state when key is acquired as reader", async () => {
|
|
1919
1847
|
const key = "a";
|
|
1920
1848
|
const limit = 3;
|
|
1921
1849
|
const ttl = null;
|
|
1922
1850
|
const sharedLock = sharedLockProvider.create(key, {
|
|
1923
|
-
limit,
|
|
1924
1851
|
ttl,
|
|
1852
|
+
limit,
|
|
1925
1853
|
});
|
|
1926
1854
|
await sharedLock.acquireReader();
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1855
|
+
try {
|
|
1856
|
+
await sharedLock.releaseWriterOrFail();
|
|
1857
|
+
}
|
|
1858
|
+
catch {
|
|
1859
|
+
/* EMPTY */
|
|
1860
|
+
}
|
|
1931
1861
|
const state = await sharedLock.getState();
|
|
1932
1862
|
expect(state).toEqual({
|
|
1933
1863
|
type: SHARED_LOCK_STATE.READER_ACQUIRED,
|
|
@@ -1938,28 +1868,38 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
1938
1868
|
acquiredSlots: [sharedLock.id],
|
|
1939
1869
|
});
|
|
1940
1870
|
});
|
|
1941
|
-
|
|
1871
|
+
});
|
|
1872
|
+
describe("method: refreshWriter", () => {
|
|
1873
|
+
test("Should return false when key doesnt exists", async () => {
|
|
1942
1874
|
const key = "a";
|
|
1943
|
-
const ttl = TimeSpan.fromMilliseconds(
|
|
1875
|
+
const ttl = TimeSpan.fromMilliseconds(25);
|
|
1876
|
+
const limit = 4;
|
|
1877
|
+
const sharedLock = sharedLockProvider.create(key, {
|
|
1878
|
+
ttl,
|
|
1879
|
+
limit,
|
|
1880
|
+
});
|
|
1881
|
+
const newTtl = TimeSpan.fromMinutes(1);
|
|
1882
|
+
const result = await sharedLock.refreshWriter(newTtl);
|
|
1883
|
+
expect(result).toBe(false);
|
|
1884
|
+
});
|
|
1885
|
+
test("Should return false when key is unexpireable and refreshed by different owner", async () => {
|
|
1886
|
+
const key = "a";
|
|
1887
|
+
const ttl = null;
|
|
1944
1888
|
const limit = 4;
|
|
1945
1889
|
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1946
1890
|
ttl,
|
|
1947
1891
|
limit,
|
|
1948
1892
|
});
|
|
1949
1893
|
await sharedLock1.acquireWriter();
|
|
1950
|
-
const
|
|
1951
|
-
await sharedLockProvider.addListener(SHARED_LOCK_EVENTS.UNAVAILABLE, handlerFn);
|
|
1894
|
+
const newTtl = TimeSpan.fromMinutes(1);
|
|
1952
1895
|
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1953
1896
|
ttl,
|
|
1954
1897
|
limit,
|
|
1955
1898
|
});
|
|
1956
|
-
await sharedLock2.
|
|
1957
|
-
|
|
1958
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1959
|
-
});
|
|
1960
|
-
expect(handlerFn.mock.calls.length).toBeGreaterThan(1);
|
|
1899
|
+
const result = await sharedLock2.refreshWriter(newTtl);
|
|
1900
|
+
expect(result).toBe(false);
|
|
1961
1901
|
});
|
|
1962
|
-
test("Should
|
|
1902
|
+
test("Should return false when key is unexpired and refreshed by different owner", async () => {
|
|
1963
1903
|
const key = "a";
|
|
1964
1904
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1965
1905
|
const limit = 4;
|
|
@@ -1967,85 +1907,80 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
1967
1907
|
ttl,
|
|
1968
1908
|
limit,
|
|
1969
1909
|
});
|
|
1970
|
-
await sharedLock1.
|
|
1971
|
-
const
|
|
1972
|
-
await sharedLockProvider.addListener(SHARED_LOCK_EVENTS.UNAVAILABLE, handlerFn);
|
|
1910
|
+
await sharedLock1.acquireWriter();
|
|
1911
|
+
const newTtl = TimeSpan.fromMinutes(1);
|
|
1973
1912
|
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1974
1913
|
ttl,
|
|
1975
1914
|
limit,
|
|
1976
1915
|
});
|
|
1977
|
-
await sharedLock2.
|
|
1978
|
-
|
|
1979
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1980
|
-
});
|
|
1981
|
-
expect(handlerFn.mock.calls.length).toBeGreaterThan(1);
|
|
1916
|
+
const result = await sharedLock2.refreshWriter(newTtl);
|
|
1917
|
+
expect(result).toBe(false);
|
|
1982
1918
|
});
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1919
|
+
test("Should return false when key is expired and refreshed by different owner", {
|
|
1920
|
+
retry: 10,
|
|
1921
|
+
}, async () => {
|
|
1986
1922
|
const key = "a";
|
|
1987
|
-
const ttl =
|
|
1923
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1988
1924
|
const limit = 4;
|
|
1989
|
-
const
|
|
1990
|
-
|
|
1925
|
+
const sharedLock1 = sharedLockProvider.create(key, {
|
|
1926
|
+
ttl,
|
|
1991
1927
|
limit,
|
|
1928
|
+
});
|
|
1929
|
+
await sharedLock1.acquireWriter();
|
|
1930
|
+
await delay(ttl);
|
|
1931
|
+
const newTtl = TimeSpan.fromMinutes(1);
|
|
1932
|
+
const sharedLock2 = sharedLockProvider.create(key, {
|
|
1992
1933
|
ttl,
|
|
1993
|
-
|
|
1994
|
-
.acquireWriterBlockingOrFail({
|
|
1995
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
1996
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
1934
|
+
limit,
|
|
1997
1935
|
});
|
|
1998
|
-
await
|
|
1936
|
+
const result = await sharedLock2.refreshWriter(newTtl);
|
|
1937
|
+
expect(result).toBe(false);
|
|
1999
1938
|
});
|
|
2000
|
-
test("Should
|
|
1939
|
+
test("Should return false when key is expired and refreshed by same owner", {
|
|
2001
1940
|
retry: 10,
|
|
2002
1941
|
}, async () => {
|
|
2003
1942
|
const key = "a";
|
|
2004
|
-
const limit = 4;
|
|
2005
1943
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1944
|
+
const limit = 4;
|
|
2006
1945
|
const sharedLock = sharedLockProvider.create(key, {
|
|
2007
|
-
limit,
|
|
2008
1946
|
ttl,
|
|
1947
|
+
limit,
|
|
2009
1948
|
});
|
|
2010
1949
|
await sharedLock.acquireWriter();
|
|
2011
1950
|
await delay(ttl);
|
|
2012
|
-
const
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
});
|
|
2016
|
-
await expect(result).resolves.toBeUndefined();
|
|
1951
|
+
const newTtl = TimeSpan.fromMinutes(1);
|
|
1952
|
+
const result = await sharedLock.refreshWriter(newTtl);
|
|
1953
|
+
expect(result).toBe(false);
|
|
2017
1954
|
});
|
|
2018
|
-
test("Should
|
|
1955
|
+
test("Should return false when key is unexpireable and refreshed by same owner", async () => {
|
|
2019
1956
|
const key = "a";
|
|
2020
|
-
const limit = 4;
|
|
2021
1957
|
const ttl = null;
|
|
1958
|
+
const limit = 4;
|
|
2022
1959
|
const sharedLock = sharedLockProvider.create(key, {
|
|
2023
1960
|
ttl,
|
|
2024
1961
|
limit,
|
|
2025
1962
|
});
|
|
2026
1963
|
await sharedLock.acquireWriter();
|
|
2027
|
-
const
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
});
|
|
2031
|
-
await expect(result).resolves.toBeUndefined();
|
|
1964
|
+
const newTtl = TimeSpan.fromMinutes(1);
|
|
1965
|
+
const result = await sharedLock.refreshWriter(newTtl);
|
|
1966
|
+
expect(result).toBe(false);
|
|
2032
1967
|
});
|
|
2033
|
-
test("Should
|
|
1968
|
+
test("Should return true when key is unexpired and refreshed by same owner", async () => {
|
|
2034
1969
|
const key = "a";
|
|
2035
|
-
const limit = 4;
|
|
2036
1970
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
1971
|
+
const limit = 4;
|
|
2037
1972
|
const sharedLock = sharedLockProvider.create(key, {
|
|
2038
1973
|
ttl,
|
|
2039
1974
|
limit,
|
|
2040
1975
|
});
|
|
2041
1976
|
await sharedLock.acquireWriter();
|
|
2042
|
-
const
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
});
|
|
2046
|
-
await expect(result).resolves.toBeUndefined();
|
|
1977
|
+
const newTtl = TimeSpan.fromMinutes(1);
|
|
1978
|
+
const result = await sharedLock.refreshWriter(newTtl);
|
|
1979
|
+
expect(result).toBe(true);
|
|
2047
1980
|
});
|
|
2048
|
-
test("Should
|
|
1981
|
+
test("Should not update expiration when key is unexpireable and refreshed by same owner", {
|
|
1982
|
+
retry: 10,
|
|
1983
|
+
}, async () => {
|
|
2049
1984
|
const key = "a";
|
|
2050
1985
|
const ttl = null;
|
|
2051
1986
|
const limit = 4;
|
|
@@ -2054,68 +1989,64 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
2054
1989
|
limit,
|
|
2055
1990
|
});
|
|
2056
1991
|
await sharedLock1.acquireWriter();
|
|
1992
|
+
const newTtl = TimeSpan.fromMilliseconds(50);
|
|
1993
|
+
await sharedLock1.refreshWriter(newTtl);
|
|
1994
|
+
await delay(newTtl);
|
|
2057
1995
|
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2058
1996
|
ttl,
|
|
2059
1997
|
limit,
|
|
2060
1998
|
});
|
|
2061
|
-
const result = sharedLock2.
|
|
2062
|
-
|
|
2063
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
2064
|
-
});
|
|
2065
|
-
await expect(result).rejects.toBeInstanceOf(FailedAcquireWriterLockError);
|
|
1999
|
+
const result = await sharedLock2.acquireWriter();
|
|
2000
|
+
expect(result).toBe(false);
|
|
2066
2001
|
});
|
|
2067
|
-
test("Should
|
|
2002
|
+
test("Should update expiration when key is unexpired and refreshed by same owner", {
|
|
2003
|
+
retry: 10,
|
|
2004
|
+
}, async () => {
|
|
2068
2005
|
const key = "a";
|
|
2069
|
-
const limit = 4;
|
|
2070
2006
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2007
|
+
const limit = 4;
|
|
2071
2008
|
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2072
|
-
limit,
|
|
2073
2009
|
ttl,
|
|
2010
|
+
limit,
|
|
2074
2011
|
});
|
|
2075
2012
|
await sharedLock1.acquireWriter();
|
|
2013
|
+
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
2014
|
+
await sharedLock1.refreshWriter(newTtl);
|
|
2015
|
+
await delay(newTtl.divide(2));
|
|
2076
2016
|
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2077
|
-
limit,
|
|
2078
2017
|
ttl,
|
|
2018
|
+
limit,
|
|
2079
2019
|
});
|
|
2080
|
-
const
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2020
|
+
const result1 = await sharedLock2.acquireWriter();
|
|
2021
|
+
expect(result1).toBe(false);
|
|
2022
|
+
await delay(newTtl.divide(2));
|
|
2023
|
+
const result2 = await sharedLock2.acquireWriter();
|
|
2024
|
+
expect(result2).toBe(true);
|
|
2085
2025
|
});
|
|
2086
|
-
test("Should
|
|
2026
|
+
test("Should return false when key is acquired as reader", async () => {
|
|
2087
2027
|
const key = "a";
|
|
2088
2028
|
const limit = 2;
|
|
2089
|
-
const ttl =
|
|
2029
|
+
const ttl = TimeSpan.fromSeconds(10);
|
|
2090
2030
|
const sharedLock = sharedLockProvider.create(key, {
|
|
2091
|
-
limit,
|
|
2092
2031
|
ttl,
|
|
2032
|
+
limit,
|
|
2093
2033
|
});
|
|
2094
2034
|
await sharedLock.acquireReader();
|
|
2095
|
-
const
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
});
|
|
2099
|
-
await expect(result).rejects.toBeInstanceOf(FailedAcquireWriterLockError);
|
|
2035
|
+
const newTtl = TimeSpan.fromSeconds(20);
|
|
2036
|
+
const result = await sharedLock.refreshWriter(newTtl);
|
|
2037
|
+
expect(result).toBe(false);
|
|
2100
2038
|
});
|
|
2101
2039
|
test("Should not update state when key is acquired as reader", async () => {
|
|
2102
2040
|
const key = "a";
|
|
2103
2041
|
const limit = 3;
|
|
2104
2042
|
const ttl = null;
|
|
2105
2043
|
const sharedLock = sharedLockProvider.create(key, {
|
|
2106
|
-
limit,
|
|
2107
2044
|
ttl,
|
|
2045
|
+
limit,
|
|
2108
2046
|
});
|
|
2109
2047
|
await sharedLock.acquireReader();
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
2113
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
2114
|
-
});
|
|
2115
|
-
}
|
|
2116
|
-
catch {
|
|
2117
|
-
/* EMPTY */
|
|
2118
|
-
}
|
|
2048
|
+
const newTtl = TimeSpan.fromSeconds(20);
|
|
2049
|
+
await sharedLock.refreshWriter(newTtl);
|
|
2119
2050
|
const state = await sharedLock.getState();
|
|
2120
2051
|
expect(state).toEqual({
|
|
2121
2052
|
type: SHARED_LOCK_STATE.READER_ACQUIRED,
|
|
@@ -2126,72 +2057,21 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
2126
2057
|
acquiredSlots: [sharedLock.id],
|
|
2127
2058
|
});
|
|
2128
2059
|
});
|
|
2129
|
-
test("Should retry acquire the shared lock when blocked by a writer", async () => {
|
|
2130
|
-
const key = "a";
|
|
2131
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2132
|
-
const limit = 4;
|
|
2133
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2134
|
-
ttl,
|
|
2135
|
-
limit,
|
|
2136
|
-
});
|
|
2137
|
-
await sharedLock1.acquireWriter();
|
|
2138
|
-
const handlerFn = vi.fn(() => { });
|
|
2139
|
-
await sharedLockProvider.addListener(SHARED_LOCK_EVENTS.UNAVAILABLE, handlerFn);
|
|
2140
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2141
|
-
ttl,
|
|
2142
|
-
limit,
|
|
2143
|
-
});
|
|
2144
|
-
try {
|
|
2145
|
-
await sharedLock2.acquireWriterBlockingOrFail({
|
|
2146
|
-
time: TimeSpan.fromMilliseconds(55),
|
|
2147
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
2148
|
-
});
|
|
2149
|
-
}
|
|
2150
|
-
catch {
|
|
2151
|
-
/* EMPTY */
|
|
2152
|
-
}
|
|
2153
|
-
expect(handlerFn.mock.calls.length).toBeGreaterThan(1);
|
|
2154
|
-
});
|
|
2155
|
-
test("Should retry acquire the shared lock when blocked by a reader", async () => {
|
|
2156
|
-
const key = "a";
|
|
2157
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2158
|
-
const limit = 4;
|
|
2159
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2160
|
-
ttl,
|
|
2161
|
-
limit,
|
|
2162
|
-
});
|
|
2163
|
-
await sharedLock1.acquireReader();
|
|
2164
|
-
const handlerFn = vi.fn(() => { });
|
|
2165
|
-
await sharedLockProvider.addListener(SHARED_LOCK_EVENTS.UNAVAILABLE, handlerFn);
|
|
2166
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2167
|
-
ttl,
|
|
2168
|
-
limit,
|
|
2169
|
-
});
|
|
2170
|
-
try {
|
|
2171
|
-
await sharedLock2.acquireWriterBlockingOrFail({
|
|
2172
|
-
time: TimeSpan.fromMilliseconds(55),
|
|
2173
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
2174
|
-
});
|
|
2175
|
-
}
|
|
2176
|
-
catch {
|
|
2177
|
-
/* EMPTY */
|
|
2178
|
-
}
|
|
2179
|
-
expect(handlerFn.mock.calls.length).toBeGreaterThan(1);
|
|
2180
|
-
});
|
|
2181
2060
|
});
|
|
2182
|
-
describe("method:
|
|
2183
|
-
test("Should
|
|
2061
|
+
describe("method: refreshWriterOrFail", () => {
|
|
2062
|
+
test("Should throw FailedRefreshWriterLockError when key doesnt exists", async () => {
|
|
2184
2063
|
const key = "a";
|
|
2185
|
-
const ttl =
|
|
2064
|
+
const ttl = TimeSpan.fromMilliseconds(25);
|
|
2186
2065
|
const limit = 4;
|
|
2187
2066
|
const sharedLock = sharedLockProvider.create(key, {
|
|
2188
2067
|
ttl,
|
|
2189
2068
|
limit,
|
|
2190
2069
|
});
|
|
2191
|
-
const
|
|
2192
|
-
|
|
2070
|
+
const newTtl = TimeSpan.fromMinutes(1);
|
|
2071
|
+
const result = sharedLock.refreshWriterOrFail(newTtl);
|
|
2072
|
+
await expect(result).rejects.toBeInstanceOf(FailedRefreshWriterLockError);
|
|
2193
2073
|
});
|
|
2194
|
-
test("Should
|
|
2074
|
+
test("Should throw FailedRefreshWriterLockError when key is unexpireable and refreshed by different owner", async () => {
|
|
2195
2075
|
const key = "a";
|
|
2196
2076
|
const ttl = null;
|
|
2197
2077
|
const limit = 4;
|
|
@@ -2200,30 +2080,32 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
2200
2080
|
limit,
|
|
2201
2081
|
});
|
|
2202
2082
|
await sharedLock1.acquireWriter();
|
|
2083
|
+
const newTtl = TimeSpan.fromMinutes(1);
|
|
2203
2084
|
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2204
2085
|
ttl,
|
|
2205
2086
|
limit,
|
|
2206
2087
|
});
|
|
2207
|
-
const result =
|
|
2208
|
-
expect(result).
|
|
2088
|
+
const result = sharedLock2.refreshWriterOrFail(newTtl);
|
|
2089
|
+
await expect(result).rejects.toBeInstanceOf(FailedRefreshWriterLockError);
|
|
2209
2090
|
});
|
|
2210
|
-
test("Should
|
|
2091
|
+
test("Should throw FailedRefreshWriterLockError when key is unexpired and refreshed by different owner", async () => {
|
|
2211
2092
|
const key = "a";
|
|
2212
2093
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2213
2094
|
const limit = 4;
|
|
2214
2095
|
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2215
|
-
limit,
|
|
2216
2096
|
ttl,
|
|
2097
|
+
limit,
|
|
2217
2098
|
});
|
|
2218
2099
|
await sharedLock1.acquireWriter();
|
|
2100
|
+
const newTtl = TimeSpan.fromMinutes(1);
|
|
2219
2101
|
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2220
|
-
limit,
|
|
2221
2102
|
ttl,
|
|
2103
|
+
limit,
|
|
2222
2104
|
});
|
|
2223
|
-
const result =
|
|
2224
|
-
expect(result).
|
|
2105
|
+
const result = sharedLock2.refreshWriterOrFail(newTtl);
|
|
2106
|
+
await expect(result).rejects.toBeInstanceOf(FailedRefreshWriterLockError);
|
|
2225
2107
|
});
|
|
2226
|
-
test("Should
|
|
2108
|
+
test("Should throw FailedRefreshWriterLockError when key is expired and refreshed by different owner", {
|
|
2227
2109
|
retry: 10,
|
|
2228
2110
|
}, async () => {
|
|
2229
2111
|
const key = "a";
|
|
@@ -2234,15 +2116,16 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
2234
2116
|
limit,
|
|
2235
2117
|
});
|
|
2236
2118
|
await sharedLock1.acquireWriter();
|
|
2119
|
+
await delay(ttl);
|
|
2120
|
+
const newTtl = TimeSpan.fromMinutes(1);
|
|
2237
2121
|
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2238
2122
|
ttl,
|
|
2239
2123
|
limit,
|
|
2240
2124
|
});
|
|
2241
|
-
const result =
|
|
2242
|
-
await
|
|
2243
|
-
expect(result).toBe(false);
|
|
2125
|
+
const result = sharedLock2.refreshWriterOrFail(newTtl);
|
|
2126
|
+
await expect(result).rejects.toBeInstanceOf(FailedRefreshWriterLockError);
|
|
2244
2127
|
});
|
|
2245
|
-
test("Should
|
|
2128
|
+
test("Should throw FailedRefreshWriterLockError when key is expired and refreshed by same owner", {
|
|
2246
2129
|
retry: 10,
|
|
2247
2130
|
}, async () => {
|
|
2248
2131
|
const key = "a";
|
|
@@ -2254,10 +2137,11 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
2254
2137
|
});
|
|
2255
2138
|
await sharedLock.acquireWriter();
|
|
2256
2139
|
await delay(ttl);
|
|
2257
|
-
const
|
|
2258
|
-
|
|
2140
|
+
const newTtl = TimeSpan.fromMinutes(1);
|
|
2141
|
+
const result = sharedLock.refreshWriterOrFail(newTtl);
|
|
2142
|
+
await expect(result).rejects.toBeInstanceOf(FailedRefreshWriterLockError);
|
|
2259
2143
|
});
|
|
2260
|
-
test("Should
|
|
2144
|
+
test("Should throw FailedRefreshWriterLockError when key is unexpireable and refreshed by same owner", async () => {
|
|
2261
2145
|
const key = "a";
|
|
2262
2146
|
const ttl = null;
|
|
2263
2147
|
const limit = 4;
|
|
@@ -2266,10 +2150,11 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
2266
2150
|
limit,
|
|
2267
2151
|
});
|
|
2268
2152
|
await sharedLock.acquireWriter();
|
|
2269
|
-
const
|
|
2270
|
-
|
|
2153
|
+
const newTtl = TimeSpan.fromMinutes(1);
|
|
2154
|
+
const result = sharedLock.refreshWriterOrFail(newTtl);
|
|
2155
|
+
await expect(result).rejects.toBeInstanceOf(FailedRefreshWriterLockError);
|
|
2271
2156
|
});
|
|
2272
|
-
test("Should
|
|
2157
|
+
test("Should not throw error when key is unexpired and refreshed by same owner", async () => {
|
|
2273
2158
|
const key = "a";
|
|
2274
2159
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2275
2160
|
const limit = 4;
|
|
@@ -2278,10 +2163,13 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
2278
2163
|
limit,
|
|
2279
2164
|
});
|
|
2280
2165
|
await sharedLock.acquireWriter();
|
|
2281
|
-
const
|
|
2282
|
-
|
|
2166
|
+
const newTtl = TimeSpan.fromMinutes(1);
|
|
2167
|
+
const result = sharedLock.refreshWriterOrFail(newTtl);
|
|
2168
|
+
await expect(result).resolves.toBeUndefined();
|
|
2283
2169
|
});
|
|
2284
|
-
test("Should not
|
|
2170
|
+
test("Should not update expiration when key is unexpireable and refreshed by same owner", {
|
|
2171
|
+
retry: 10,
|
|
2172
|
+
}, async () => {
|
|
2285
2173
|
const key = "a";
|
|
2286
2174
|
const ttl = null;
|
|
2287
2175
|
const limit = 4;
|
|
@@ -2290,15 +2178,24 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
2290
2178
|
limit,
|
|
2291
2179
|
});
|
|
2292
2180
|
await sharedLock1.acquireWriter();
|
|
2181
|
+
const newTtl = TimeSpan.fromMilliseconds(50);
|
|
2182
|
+
try {
|
|
2183
|
+
await sharedLock1.refreshWriterOrFail(newTtl);
|
|
2184
|
+
}
|
|
2185
|
+
catch {
|
|
2186
|
+
/* EMPTY */
|
|
2187
|
+
}
|
|
2188
|
+
await delay(newTtl);
|
|
2293
2189
|
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2294
2190
|
ttl,
|
|
2295
2191
|
limit,
|
|
2296
2192
|
});
|
|
2297
|
-
await sharedLock2.releaseWriter();
|
|
2298
2193
|
const result = await sharedLock2.acquireWriter();
|
|
2299
2194
|
expect(result).toBe(false);
|
|
2300
2195
|
});
|
|
2301
|
-
test("Should
|
|
2196
|
+
test("Should update expiration when key is unexpired and refreshed by same owner", {
|
|
2197
|
+
retry: 10,
|
|
2198
|
+
}, async () => {
|
|
2302
2199
|
const key = "a";
|
|
2303
2200
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2304
2201
|
const limit = 4;
|
|
@@ -2307,59 +2204,36 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
2307
2204
|
limit,
|
|
2308
2205
|
});
|
|
2309
2206
|
await sharedLock1.acquireWriter();
|
|
2207
|
+
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
2208
|
+
try {
|
|
2209
|
+
await sharedLock1.refreshWriterOrFail(newTtl);
|
|
2210
|
+
}
|
|
2211
|
+
catch {
|
|
2212
|
+
/* EMPTY */
|
|
2213
|
+
}
|
|
2214
|
+
await delay(newTtl.divide(2));
|
|
2310
2215
|
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2311
2216
|
ttl,
|
|
2312
2217
|
limit,
|
|
2313
2218
|
});
|
|
2314
|
-
await sharedLock2.
|
|
2315
|
-
|
|
2316
|
-
|
|
2219
|
+
const result1 = await sharedLock2.acquireWriter();
|
|
2220
|
+
expect(result1).toBe(false);
|
|
2221
|
+
await delay(newTtl.divide(2));
|
|
2222
|
+
const result2 = await sharedLock2.acquireWriter();
|
|
2223
|
+
expect(result2).toBe(true);
|
|
2317
2224
|
});
|
|
2318
|
-
test("Should
|
|
2225
|
+
test("Should throw FailedRefreshWriterLockError when key is acquired as reader", async () => {
|
|
2319
2226
|
const key = "a";
|
|
2320
|
-
const
|
|
2321
|
-
const
|
|
2322
|
-
const
|
|
2323
|
-
ttl,
|
|
2324
|
-
limit,
|
|
2325
|
-
});
|
|
2326
|
-
await sharedLock1.acquireWriter();
|
|
2327
|
-
await sharedLock1.releaseWriter();
|
|
2328
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2329
|
-
ttl,
|
|
2330
|
-
limit,
|
|
2331
|
-
});
|
|
2332
|
-
const result = await sharedLock2.acquireWriter();
|
|
2333
|
-
expect(result).toBe(true);
|
|
2334
|
-
});
|
|
2335
|
-
test("Should be reacquirable when key is unexpired and released by same owner", async () => {
|
|
2336
|
-
const key = "a";
|
|
2337
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2338
|
-
const limit = 4;
|
|
2339
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2340
|
-
ttl,
|
|
2341
|
-
limit,
|
|
2342
|
-
});
|
|
2343
|
-
await sharedLock1.acquireWriter();
|
|
2344
|
-
await sharedLock1.releaseWriter();
|
|
2345
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2346
|
-
ttl,
|
|
2347
|
-
limit,
|
|
2348
|
-
});
|
|
2349
|
-
const result = await sharedLock2.acquireWriter();
|
|
2350
|
-
expect(result).toBe(true);
|
|
2351
|
-
});
|
|
2352
|
-
test("Should return false when key is acquired as reader", async () => {
|
|
2353
|
-
const key = "a";
|
|
2354
|
-
const limit = 2;
|
|
2355
|
-
const ttl = TimeSpan.fromSeconds(10);
|
|
2356
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
2227
|
+
const limit = 2;
|
|
2228
|
+
const ttl = TimeSpan.fromSeconds(10);
|
|
2229
|
+
const sharedLock = sharedLockProvider.create(key, {
|
|
2357
2230
|
ttl,
|
|
2358
2231
|
limit,
|
|
2359
2232
|
});
|
|
2360
2233
|
await sharedLock.acquireReader();
|
|
2361
|
-
const
|
|
2362
|
-
|
|
2234
|
+
const newTtl = TimeSpan.fromSeconds(20);
|
|
2235
|
+
const result = sharedLock.refreshWriterOrFail(newTtl);
|
|
2236
|
+
await expect(result).rejects.toBeInstanceOf(FailedRefreshWriterLockError);
|
|
2363
2237
|
});
|
|
2364
2238
|
test("Should not update state when key is acquired as reader", async () => {
|
|
2365
2239
|
const key = "a";
|
|
@@ -2370,7 +2244,13 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
2370
2244
|
limit,
|
|
2371
2245
|
});
|
|
2372
2246
|
await sharedLock.acquireReader();
|
|
2373
|
-
|
|
2247
|
+
const newTtl = TimeSpan.fromSeconds(20);
|
|
2248
|
+
try {
|
|
2249
|
+
await sharedLock.refreshWriterOrFail(newTtl);
|
|
2250
|
+
}
|
|
2251
|
+
catch {
|
|
2252
|
+
/* EMPTY */
|
|
2253
|
+
}
|
|
2374
2254
|
const state = await sharedLock.getState();
|
|
2375
2255
|
expect(state).toEqual({
|
|
2376
2256
|
type: SHARED_LOCK_STATE.READER_ACQUIRED,
|
|
@@ -2382,8 +2262,8 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
2382
2262
|
});
|
|
2383
2263
|
});
|
|
2384
2264
|
});
|
|
2385
|
-
describe("method:
|
|
2386
|
-
test("Should
|
|
2265
|
+
describe("method: forceReleaseWriter", () => {
|
|
2266
|
+
test("Should return false when key doesnt exists", async () => {
|
|
2387
2267
|
const key = "a";
|
|
2388
2268
|
const ttl = null;
|
|
2389
2269
|
const limit = 4;
|
|
@@ -2391,61 +2271,10 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
2391
2271
|
ttl,
|
|
2392
2272
|
limit,
|
|
2393
2273
|
});
|
|
2394
|
-
const result = sharedLock.
|
|
2395
|
-
|
|
2396
|
-
});
|
|
2397
|
-
test("Should throw FailedReleaseWriterLockError when key is unexpireable and released by different owner", async () => {
|
|
2398
|
-
const key = "a";
|
|
2399
|
-
const ttl = null;
|
|
2400
|
-
const limit = 4;
|
|
2401
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2402
|
-
ttl,
|
|
2403
|
-
limit,
|
|
2404
|
-
});
|
|
2405
|
-
await sharedLock1.acquireWriter();
|
|
2406
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2407
|
-
ttl,
|
|
2408
|
-
limit,
|
|
2409
|
-
});
|
|
2410
|
-
const result = sharedLock2.releaseWriterOrFail();
|
|
2411
|
-
await expect(result).rejects.toBeInstanceOf(FailedReleaseWriterLockError);
|
|
2412
|
-
});
|
|
2413
|
-
test("Should throw FailedReleaseWriterLockError when key is unexpired and released by different owner", async () => {
|
|
2414
|
-
const key = "a";
|
|
2415
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2416
|
-
const limit = 4;
|
|
2417
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2418
|
-
limit,
|
|
2419
|
-
ttl,
|
|
2420
|
-
});
|
|
2421
|
-
await sharedLock1.acquireWriter();
|
|
2422
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2423
|
-
limit,
|
|
2424
|
-
ttl,
|
|
2425
|
-
});
|
|
2426
|
-
const result = sharedLock2.releaseWriterOrFail();
|
|
2427
|
-
await expect(result).rejects.toBeInstanceOf(FailedReleaseWriterLockError);
|
|
2428
|
-
});
|
|
2429
|
-
test("Should throw FailedReleaseWriterLockError when key is expired and released by different owner", {
|
|
2430
|
-
retry: 10,
|
|
2431
|
-
}, async () => {
|
|
2432
|
-
const key = "a";
|
|
2433
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2434
|
-
const limit = 4;
|
|
2435
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2436
|
-
ttl,
|
|
2437
|
-
limit,
|
|
2438
|
-
});
|
|
2439
|
-
await sharedLock1.acquireWriter();
|
|
2440
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2441
|
-
ttl,
|
|
2442
|
-
limit,
|
|
2443
|
-
});
|
|
2444
|
-
const result = sharedLock2.releaseWriterOrFail();
|
|
2445
|
-
await delay(ttl);
|
|
2446
|
-
await expect(result).rejects.toBeInstanceOf(FailedReleaseWriterLockError);
|
|
2274
|
+
const result = await sharedLock.forceReleaseWriter();
|
|
2275
|
+
expect(result).toBe(false);
|
|
2447
2276
|
});
|
|
2448
|
-
test("Should
|
|
2277
|
+
test("Should return false when key is expired", {
|
|
2449
2278
|
retry: 10,
|
|
2450
2279
|
}, async () => {
|
|
2451
2280
|
const key = "a";
|
|
@@ -2457,22 +2286,10 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
2457
2286
|
});
|
|
2458
2287
|
await sharedLock.acquireWriter();
|
|
2459
2288
|
await delay(ttl);
|
|
2460
|
-
const result = sharedLock.
|
|
2461
|
-
|
|
2462
|
-
});
|
|
2463
|
-
test("Should not throw error when key is unexpireable and released by same owner", async () => {
|
|
2464
|
-
const key = "a";
|
|
2465
|
-
const ttl = null;
|
|
2466
|
-
const limit = 4;
|
|
2467
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
2468
|
-
ttl,
|
|
2469
|
-
limit,
|
|
2470
|
-
});
|
|
2471
|
-
await sharedLock.acquireWriter();
|
|
2472
|
-
const result = sharedLock.releaseWriterOrFail();
|
|
2473
|
-
await expect(result).resolves.toBeUndefined();
|
|
2289
|
+
const result = await sharedLock.forceReleaseWriter();
|
|
2290
|
+
expect(result).toBe(false);
|
|
2474
2291
|
});
|
|
2475
|
-
test("Should
|
|
2292
|
+
test("Should return true when key is uenxpired", async () => {
|
|
2476
2293
|
const key = "a";
|
|
2477
2294
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2478
2295
|
const limit = 4;
|
|
@@ -2481,139 +2298,22 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
2481
2298
|
limit,
|
|
2482
2299
|
});
|
|
2483
2300
|
await sharedLock.acquireWriter();
|
|
2484
|
-
const result = sharedLock.
|
|
2485
|
-
await expect(result).resolves.toBeUndefined();
|
|
2486
|
-
});
|
|
2487
|
-
test("Should not be reacquirable when key is unexpireable and released by different owner", async () => {
|
|
2488
|
-
const key = "a";
|
|
2489
|
-
const ttl = null;
|
|
2490
|
-
const limit = 4;
|
|
2491
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2492
|
-
ttl,
|
|
2493
|
-
limit,
|
|
2494
|
-
});
|
|
2495
|
-
await sharedLock1.acquireWriter();
|
|
2496
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2497
|
-
ttl,
|
|
2498
|
-
limit,
|
|
2499
|
-
});
|
|
2500
|
-
try {
|
|
2501
|
-
await sharedLock2.releaseWriterOrFail();
|
|
2502
|
-
}
|
|
2503
|
-
catch {
|
|
2504
|
-
/* EMPTY */
|
|
2505
|
-
}
|
|
2506
|
-
const result = await sharedLock2.acquireWriter();
|
|
2507
|
-
expect(result).toBe(false);
|
|
2508
|
-
});
|
|
2509
|
-
test("Should not be reacquirable when key is unexpired and released by different owner", async () => {
|
|
2510
|
-
const key = "a";
|
|
2511
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2512
|
-
const limit = 4;
|
|
2513
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2514
|
-
ttl,
|
|
2515
|
-
limit,
|
|
2516
|
-
});
|
|
2517
|
-
await sharedLock1.acquireWriter();
|
|
2518
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2519
|
-
ttl,
|
|
2520
|
-
limit,
|
|
2521
|
-
});
|
|
2522
|
-
try {
|
|
2523
|
-
await sharedLock2.releaseWriterOrFail();
|
|
2524
|
-
}
|
|
2525
|
-
catch {
|
|
2526
|
-
/* EMPTY */
|
|
2527
|
-
}
|
|
2528
|
-
const result = await sharedLock2.acquireWriter();
|
|
2529
|
-
expect(result).toBe(false);
|
|
2530
|
-
});
|
|
2531
|
-
test("Should be reacquirable when key is unexpireable and released by same owner", async () => {
|
|
2532
|
-
const key = "a";
|
|
2533
|
-
const ttl = null;
|
|
2534
|
-
const limit = 4;
|
|
2535
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2536
|
-
ttl,
|
|
2537
|
-
limit,
|
|
2538
|
-
});
|
|
2539
|
-
await sharedLock1.acquireWriter();
|
|
2540
|
-
await sharedLock1.releaseWriterOrFail();
|
|
2541
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2542
|
-
ttl,
|
|
2543
|
-
limit,
|
|
2544
|
-
});
|
|
2545
|
-
const result = await sharedLock2.acquireWriter();
|
|
2546
|
-
expect(result).toBe(true);
|
|
2547
|
-
});
|
|
2548
|
-
test("Should be reacquirable when key is unexpired and released by same owner", async () => {
|
|
2549
|
-
const key = "a";
|
|
2550
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2551
|
-
const limit = 4;
|
|
2552
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2553
|
-
ttl,
|
|
2554
|
-
limit,
|
|
2555
|
-
});
|
|
2556
|
-
await sharedLock1.acquireWriter();
|
|
2557
|
-
await sharedLock1.releaseWriterOrFail();
|
|
2558
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2559
|
-
ttl,
|
|
2560
|
-
limit,
|
|
2561
|
-
});
|
|
2562
|
-
const result = await sharedLock2.acquireWriter();
|
|
2301
|
+
const result = await sharedLock.forceReleaseWriter();
|
|
2563
2302
|
expect(result).toBe(true);
|
|
2564
2303
|
});
|
|
2565
|
-
test("Should
|
|
2566
|
-
const key = "a";
|
|
2567
|
-
const limit = 2;
|
|
2568
|
-
const ttl = TimeSpan.fromSeconds(10);
|
|
2569
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
2570
|
-
ttl,
|
|
2571
|
-
limit,
|
|
2572
|
-
});
|
|
2573
|
-
await sharedLock.acquireReader();
|
|
2574
|
-
const result = sharedLock.releaseWriterOrFail();
|
|
2575
|
-
await expect(result).rejects.toBeInstanceOf(FailedReleaseWriterLockError);
|
|
2576
|
-
});
|
|
2577
|
-
test("Should not update state when key is acquired as reader", async () => {
|
|
2304
|
+
test("Should return true when key is unexpireable", async () => {
|
|
2578
2305
|
const key = "a";
|
|
2579
|
-
const limit = 3;
|
|
2580
2306
|
const ttl = null;
|
|
2581
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
2582
|
-
ttl,
|
|
2583
|
-
limit,
|
|
2584
|
-
});
|
|
2585
|
-
await sharedLock.acquireReader();
|
|
2586
|
-
try {
|
|
2587
|
-
await sharedLock.releaseWriterOrFail();
|
|
2588
|
-
}
|
|
2589
|
-
catch {
|
|
2590
|
-
/* EMPTY */
|
|
2591
|
-
}
|
|
2592
|
-
const state = await sharedLock.getState();
|
|
2593
|
-
expect(state).toEqual({
|
|
2594
|
-
type: SHARED_LOCK_STATE.READER_ACQUIRED,
|
|
2595
|
-
limit,
|
|
2596
|
-
remainingTime: null,
|
|
2597
|
-
freeSlotsCount: 2,
|
|
2598
|
-
acquiredSlotsCount: 1,
|
|
2599
|
-
acquiredSlots: [sharedLock.id],
|
|
2600
|
-
});
|
|
2601
|
-
});
|
|
2602
|
-
});
|
|
2603
|
-
describe("method: refreshWriter", () => {
|
|
2604
|
-
test("Should return false when key doesnt exists", async () => {
|
|
2605
|
-
const key = "a";
|
|
2606
|
-
const ttl = TimeSpan.fromMilliseconds(25);
|
|
2607
2307
|
const limit = 4;
|
|
2608
2308
|
const sharedLock = sharedLockProvider.create(key, {
|
|
2609
2309
|
ttl,
|
|
2610
2310
|
limit,
|
|
2611
2311
|
});
|
|
2612
|
-
|
|
2613
|
-
const result = await sharedLock.
|
|
2614
|
-
expect(result).toBe(
|
|
2312
|
+
await sharedLock.acquireWriter();
|
|
2313
|
+
const result = await sharedLock.forceReleaseWriter();
|
|
2314
|
+
expect(result).toBe(true);
|
|
2615
2315
|
});
|
|
2616
|
-
test("Should
|
|
2316
|
+
test("Should be reacquirable when key is force released", async () => {
|
|
2617
2317
|
const key = "a";
|
|
2618
2318
|
const ttl = null;
|
|
2619
2319
|
const limit = 4;
|
|
@@ -2622,1147 +2322,49 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
2622
2322
|
limit,
|
|
2623
2323
|
});
|
|
2624
2324
|
await sharedLock1.acquireWriter();
|
|
2625
|
-
|
|
2325
|
+
await sharedLock1.forceReleaseWriter();
|
|
2626
2326
|
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2627
2327
|
ttl,
|
|
2628
2328
|
limit,
|
|
2629
2329
|
});
|
|
2630
|
-
const result = await sharedLock2.
|
|
2631
|
-
expect(result).toBe(
|
|
2632
|
-
});
|
|
2633
|
-
test("Should return false when key is unexpired and refreshed by different owner", async () => {
|
|
2634
|
-
const key = "a";
|
|
2635
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2636
|
-
const limit = 4;
|
|
2637
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2638
|
-
ttl,
|
|
2639
|
-
limit,
|
|
2640
|
-
});
|
|
2641
|
-
await sharedLock1.acquireWriter();
|
|
2642
|
-
const newTtl = TimeSpan.fromMinutes(1);
|
|
2643
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2644
|
-
ttl,
|
|
2645
|
-
limit,
|
|
2646
|
-
});
|
|
2647
|
-
const result = await sharedLock2.refreshWriter(newTtl);
|
|
2648
|
-
expect(result).toBe(false);
|
|
2649
|
-
});
|
|
2650
|
-
test("Should return false when key is expired and refreshed by different owner", {
|
|
2651
|
-
retry: 10,
|
|
2652
|
-
}, async () => {
|
|
2653
|
-
const key = "a";
|
|
2654
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2655
|
-
const limit = 4;
|
|
2656
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2657
|
-
ttl,
|
|
2658
|
-
limit,
|
|
2659
|
-
});
|
|
2660
|
-
await sharedLock1.acquireWriter();
|
|
2661
|
-
await delay(ttl);
|
|
2662
|
-
const newTtl = TimeSpan.fromMinutes(1);
|
|
2663
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2664
|
-
ttl,
|
|
2665
|
-
limit,
|
|
2666
|
-
});
|
|
2667
|
-
const result = await sharedLock2.refreshWriter(newTtl);
|
|
2668
|
-
expect(result).toBe(false);
|
|
2669
|
-
});
|
|
2670
|
-
test("Should return false when key is expired and refreshed by same owner", {
|
|
2671
|
-
retry: 10,
|
|
2672
|
-
}, async () => {
|
|
2673
|
-
const key = "a";
|
|
2674
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2675
|
-
const limit = 4;
|
|
2676
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
2677
|
-
ttl,
|
|
2678
|
-
limit,
|
|
2679
|
-
});
|
|
2680
|
-
await sharedLock.acquireWriter();
|
|
2681
|
-
await delay(ttl);
|
|
2682
|
-
const newTtl = TimeSpan.fromMinutes(1);
|
|
2683
|
-
const result = await sharedLock.refreshWriter(newTtl);
|
|
2684
|
-
expect(result).toBe(false);
|
|
2685
|
-
});
|
|
2686
|
-
test("Should return false when key is unexpireable and refreshed by same owner", async () => {
|
|
2687
|
-
const key = "a";
|
|
2688
|
-
const ttl = null;
|
|
2689
|
-
const limit = 4;
|
|
2690
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
2691
|
-
ttl,
|
|
2692
|
-
limit,
|
|
2693
|
-
});
|
|
2694
|
-
await sharedLock.acquireWriter();
|
|
2695
|
-
const newTtl = TimeSpan.fromMinutes(1);
|
|
2696
|
-
const result = await sharedLock.refreshWriter(newTtl);
|
|
2697
|
-
expect(result).toBe(false);
|
|
2698
|
-
});
|
|
2699
|
-
test("Should return true when key is unexpired and refreshed by same owner", async () => {
|
|
2700
|
-
const key = "a";
|
|
2701
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2702
|
-
const limit = 4;
|
|
2703
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
2704
|
-
ttl,
|
|
2705
|
-
limit,
|
|
2706
|
-
});
|
|
2707
|
-
await sharedLock.acquireWriter();
|
|
2708
|
-
const newTtl = TimeSpan.fromMinutes(1);
|
|
2709
|
-
const result = await sharedLock.refreshWriter(newTtl);
|
|
2710
|
-
expect(result).toBe(true);
|
|
2711
|
-
});
|
|
2712
|
-
test("Should not update expiration when key is unexpireable and refreshed by same owner", {
|
|
2713
|
-
retry: 10,
|
|
2714
|
-
}, async () => {
|
|
2715
|
-
const key = "a";
|
|
2716
|
-
const ttl = null;
|
|
2717
|
-
const limit = 4;
|
|
2718
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2719
|
-
ttl,
|
|
2720
|
-
limit,
|
|
2721
|
-
});
|
|
2722
|
-
await sharedLock1.acquireWriter();
|
|
2723
|
-
const newTtl = TimeSpan.fromMilliseconds(50);
|
|
2724
|
-
await sharedLock1.refreshWriter(newTtl);
|
|
2725
|
-
await delay(newTtl);
|
|
2726
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2727
|
-
ttl,
|
|
2728
|
-
limit,
|
|
2729
|
-
});
|
|
2730
|
-
const result = await sharedLock2.acquireWriter();
|
|
2731
|
-
expect(result).toBe(false);
|
|
2732
|
-
});
|
|
2733
|
-
test("Should update expiration when key is unexpired and refreshed by same owner", {
|
|
2734
|
-
retry: 10,
|
|
2735
|
-
}, async () => {
|
|
2736
|
-
const key = "a";
|
|
2737
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2738
|
-
const limit = 4;
|
|
2739
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2740
|
-
ttl,
|
|
2741
|
-
limit,
|
|
2742
|
-
});
|
|
2743
|
-
await sharedLock1.acquireWriter();
|
|
2744
|
-
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
2745
|
-
await sharedLock1.refreshWriter(newTtl);
|
|
2746
|
-
await delay(newTtl.divide(2));
|
|
2747
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2748
|
-
ttl,
|
|
2749
|
-
limit,
|
|
2750
|
-
});
|
|
2751
|
-
const result1 = await sharedLock2.acquireWriter();
|
|
2752
|
-
expect(result1).toBe(false);
|
|
2753
|
-
await delay(newTtl.divide(2));
|
|
2754
|
-
const result2 = await sharedLock2.acquireWriter();
|
|
2755
|
-
expect(result2).toBe(true);
|
|
2756
|
-
});
|
|
2757
|
-
test("Should return false when key is acquired as reader", async () => {
|
|
2758
|
-
const key = "a";
|
|
2759
|
-
const limit = 2;
|
|
2760
|
-
const ttl = TimeSpan.fromSeconds(10);
|
|
2761
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
2762
|
-
ttl,
|
|
2763
|
-
limit,
|
|
2764
|
-
});
|
|
2765
|
-
await sharedLock.acquireReader();
|
|
2766
|
-
const newTtl = TimeSpan.fromSeconds(20);
|
|
2767
|
-
const result = await sharedLock.refreshWriter(newTtl);
|
|
2768
|
-
expect(result).toBe(false);
|
|
2769
|
-
});
|
|
2770
|
-
test("Should not update state when key is acquired as reader", async () => {
|
|
2771
|
-
const key = "a";
|
|
2772
|
-
const limit = 3;
|
|
2773
|
-
const ttl = null;
|
|
2774
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
2775
|
-
ttl,
|
|
2776
|
-
limit,
|
|
2777
|
-
});
|
|
2778
|
-
await sharedLock.acquireReader();
|
|
2779
|
-
const newTtl = TimeSpan.fromSeconds(20);
|
|
2780
|
-
await sharedLock.refreshWriter(newTtl);
|
|
2781
|
-
const state = await sharedLock.getState();
|
|
2782
|
-
expect(state).toEqual({
|
|
2783
|
-
type: SHARED_LOCK_STATE.READER_ACQUIRED,
|
|
2784
|
-
limit,
|
|
2785
|
-
remainingTime: null,
|
|
2786
|
-
freeSlotsCount: 2,
|
|
2787
|
-
acquiredSlotsCount: 1,
|
|
2788
|
-
acquiredSlots: [sharedLock.id],
|
|
2789
|
-
});
|
|
2790
|
-
});
|
|
2791
|
-
});
|
|
2792
|
-
describe("method: refreshWriterOrFail", () => {
|
|
2793
|
-
test("Should throw FailedRefreshWriterLockError when key doesnt exists", async () => {
|
|
2794
|
-
const key = "a";
|
|
2795
|
-
const ttl = TimeSpan.fromMilliseconds(25);
|
|
2796
|
-
const limit = 4;
|
|
2797
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
2798
|
-
ttl,
|
|
2799
|
-
limit,
|
|
2800
|
-
});
|
|
2801
|
-
const newTtl = TimeSpan.fromMinutes(1);
|
|
2802
|
-
const result = sharedLock.refreshWriterOrFail(newTtl);
|
|
2803
|
-
await expect(result).rejects.toBeInstanceOf(FailedRefreshWriterLockError);
|
|
2804
|
-
});
|
|
2805
|
-
test("Should throw FailedRefreshWriterLockError when key is unexpireable and refreshed by different owner", async () => {
|
|
2806
|
-
const key = "a";
|
|
2807
|
-
const ttl = null;
|
|
2808
|
-
const limit = 4;
|
|
2809
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2810
|
-
ttl,
|
|
2811
|
-
limit,
|
|
2812
|
-
});
|
|
2813
|
-
await sharedLock1.acquireWriter();
|
|
2814
|
-
const newTtl = TimeSpan.fromMinutes(1);
|
|
2815
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2816
|
-
ttl,
|
|
2817
|
-
limit,
|
|
2818
|
-
});
|
|
2819
|
-
const result = sharedLock2.refreshWriterOrFail(newTtl);
|
|
2820
|
-
await expect(result).rejects.toBeInstanceOf(FailedRefreshWriterLockError);
|
|
2821
|
-
});
|
|
2822
|
-
test("Should throw FailedRefreshWriterLockError when key is unexpired and refreshed by different owner", async () => {
|
|
2823
|
-
const key = "a";
|
|
2824
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2825
|
-
const limit = 4;
|
|
2826
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2827
|
-
ttl,
|
|
2828
|
-
limit,
|
|
2829
|
-
});
|
|
2830
|
-
await sharedLock1.acquireWriter();
|
|
2831
|
-
const newTtl = TimeSpan.fromMinutes(1);
|
|
2832
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2833
|
-
ttl,
|
|
2834
|
-
limit,
|
|
2835
|
-
});
|
|
2836
|
-
const result = sharedLock2.refreshWriterOrFail(newTtl);
|
|
2837
|
-
await expect(result).rejects.toBeInstanceOf(FailedRefreshWriterLockError);
|
|
2838
|
-
});
|
|
2839
|
-
test("Should throw FailedRefreshWriterLockError when key is expired and refreshed by different owner", {
|
|
2840
|
-
retry: 10,
|
|
2841
|
-
}, async () => {
|
|
2842
|
-
const key = "a";
|
|
2843
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2844
|
-
const limit = 4;
|
|
2845
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2846
|
-
ttl,
|
|
2847
|
-
limit,
|
|
2848
|
-
});
|
|
2849
|
-
await sharedLock1.acquireWriter();
|
|
2850
|
-
await delay(ttl);
|
|
2851
|
-
const newTtl = TimeSpan.fromMinutes(1);
|
|
2852
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2853
|
-
ttl,
|
|
2854
|
-
limit,
|
|
2855
|
-
});
|
|
2856
|
-
const result = sharedLock2.refreshWriterOrFail(newTtl);
|
|
2857
|
-
await expect(result).rejects.toBeInstanceOf(FailedRefreshWriterLockError);
|
|
2858
|
-
});
|
|
2859
|
-
test("Should throw FailedRefreshWriterLockError when key is expired and refreshed by same owner", {
|
|
2860
|
-
retry: 10,
|
|
2861
|
-
}, async () => {
|
|
2862
|
-
const key = "a";
|
|
2863
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2864
|
-
const limit = 4;
|
|
2865
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
2866
|
-
ttl,
|
|
2867
|
-
limit,
|
|
2868
|
-
});
|
|
2869
|
-
await sharedLock.acquireWriter();
|
|
2870
|
-
await delay(ttl);
|
|
2871
|
-
const newTtl = TimeSpan.fromMinutes(1);
|
|
2872
|
-
const result = sharedLock.refreshWriterOrFail(newTtl);
|
|
2873
|
-
await expect(result).rejects.toBeInstanceOf(FailedRefreshWriterLockError);
|
|
2874
|
-
});
|
|
2875
|
-
test("Should throw FailedRefreshWriterLockError when key is unexpireable and refreshed by same owner", async () => {
|
|
2876
|
-
const key = "a";
|
|
2877
|
-
const ttl = null;
|
|
2878
|
-
const limit = 4;
|
|
2879
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
2880
|
-
ttl,
|
|
2881
|
-
limit,
|
|
2882
|
-
});
|
|
2883
|
-
await sharedLock.acquireWriter();
|
|
2884
|
-
const newTtl = TimeSpan.fromMinutes(1);
|
|
2885
|
-
const result = sharedLock.refreshWriterOrFail(newTtl);
|
|
2886
|
-
await expect(result).rejects.toBeInstanceOf(FailedRefreshWriterLockError);
|
|
2887
|
-
});
|
|
2888
|
-
test("Should not throw error when key is unexpired and refreshed by same owner", async () => {
|
|
2889
|
-
const key = "a";
|
|
2890
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2891
|
-
const limit = 4;
|
|
2892
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
2893
|
-
ttl,
|
|
2894
|
-
limit,
|
|
2895
|
-
});
|
|
2896
|
-
await sharedLock.acquireWriter();
|
|
2897
|
-
const newTtl = TimeSpan.fromMinutes(1);
|
|
2898
|
-
const result = sharedLock.refreshWriterOrFail(newTtl);
|
|
2899
|
-
await expect(result).resolves.toBeUndefined();
|
|
2900
|
-
});
|
|
2901
|
-
test("Should not update expiration when key is unexpireable and refreshed by same owner", {
|
|
2902
|
-
retry: 10,
|
|
2903
|
-
}, async () => {
|
|
2904
|
-
const key = "a";
|
|
2905
|
-
const ttl = null;
|
|
2906
|
-
const limit = 4;
|
|
2907
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2908
|
-
ttl,
|
|
2909
|
-
limit,
|
|
2910
|
-
});
|
|
2911
|
-
await sharedLock1.acquireWriter();
|
|
2912
|
-
const newTtl = TimeSpan.fromMilliseconds(50);
|
|
2913
|
-
try {
|
|
2914
|
-
await sharedLock1.refreshWriterOrFail(newTtl);
|
|
2915
|
-
}
|
|
2916
|
-
catch {
|
|
2917
|
-
/* EMPTY */
|
|
2918
|
-
}
|
|
2919
|
-
await delay(newTtl);
|
|
2920
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2921
|
-
ttl,
|
|
2922
|
-
limit,
|
|
2923
|
-
});
|
|
2924
|
-
const result = await sharedLock2.acquireWriter();
|
|
2925
|
-
expect(result).toBe(false);
|
|
2926
|
-
});
|
|
2927
|
-
test("Should update expiration when key is unexpired and refreshed by same owner", {
|
|
2928
|
-
retry: 10,
|
|
2929
|
-
}, async () => {
|
|
2930
|
-
const key = "a";
|
|
2931
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
2932
|
-
const limit = 4;
|
|
2933
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
2934
|
-
ttl,
|
|
2935
|
-
limit,
|
|
2936
|
-
});
|
|
2937
|
-
await sharedLock1.acquireWriter();
|
|
2938
|
-
const newTtl = TimeSpan.fromMilliseconds(100);
|
|
2939
|
-
try {
|
|
2940
|
-
await sharedLock1.refreshWriterOrFail(newTtl);
|
|
2941
|
-
}
|
|
2942
|
-
catch {
|
|
2943
|
-
/* EMPTY */
|
|
2944
|
-
}
|
|
2945
|
-
await delay(newTtl.divide(2));
|
|
2946
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
2947
|
-
ttl,
|
|
2948
|
-
limit,
|
|
2949
|
-
});
|
|
2950
|
-
const result1 = await sharedLock2.acquireWriter();
|
|
2951
|
-
expect(result1).toBe(false);
|
|
2952
|
-
await delay(newTtl.divide(2));
|
|
2953
|
-
const result2 = await sharedLock2.acquireWriter();
|
|
2954
|
-
expect(result2).toBe(true);
|
|
2955
|
-
});
|
|
2956
|
-
test("Should throw FailedRefreshWriterLockError when key is acquired as reader", async () => {
|
|
2957
|
-
const key = "a";
|
|
2958
|
-
const limit = 2;
|
|
2959
|
-
const ttl = TimeSpan.fromSeconds(10);
|
|
2960
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
2961
|
-
ttl,
|
|
2962
|
-
limit,
|
|
2963
|
-
});
|
|
2964
|
-
await sharedLock.acquireReader();
|
|
2965
|
-
const newTtl = TimeSpan.fromSeconds(20);
|
|
2966
|
-
const result = sharedLock.refreshWriterOrFail(newTtl);
|
|
2967
|
-
await expect(result).rejects.toBeInstanceOf(FailedRefreshWriterLockError);
|
|
2968
|
-
});
|
|
2969
|
-
test("Should not update state when key is acquired as reader", async () => {
|
|
2970
|
-
const key = "a";
|
|
2971
|
-
const limit = 3;
|
|
2972
|
-
const ttl = null;
|
|
2973
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
2974
|
-
ttl,
|
|
2975
|
-
limit,
|
|
2976
|
-
});
|
|
2977
|
-
await sharedLock.acquireReader();
|
|
2978
|
-
const newTtl = TimeSpan.fromSeconds(20);
|
|
2979
|
-
try {
|
|
2980
|
-
await sharedLock.refreshWriterOrFail(newTtl);
|
|
2981
|
-
}
|
|
2982
|
-
catch {
|
|
2983
|
-
/* EMPTY */
|
|
2984
|
-
}
|
|
2985
|
-
const state = await sharedLock.getState();
|
|
2986
|
-
expect(state).toEqual({
|
|
2987
|
-
type: SHARED_LOCK_STATE.READER_ACQUIRED,
|
|
2988
|
-
limit,
|
|
2989
|
-
remainingTime: null,
|
|
2990
|
-
freeSlotsCount: 2,
|
|
2991
|
-
acquiredSlotsCount: 1,
|
|
2992
|
-
acquiredSlots: [sharedLock.id],
|
|
2993
|
-
});
|
|
2994
|
-
});
|
|
2995
|
-
});
|
|
2996
|
-
describe("method: forceReleaseWriter", () => {
|
|
2997
|
-
test("Should return false when key doesnt exists", async () => {
|
|
2998
|
-
const key = "a";
|
|
2999
|
-
const ttl = null;
|
|
3000
|
-
const limit = 4;
|
|
3001
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3002
|
-
ttl,
|
|
3003
|
-
limit,
|
|
3004
|
-
});
|
|
3005
|
-
const result = await sharedLock.forceReleaseWriter();
|
|
3006
|
-
expect(result).toBe(false);
|
|
3007
|
-
});
|
|
3008
|
-
test("Should return false when key is expired", {
|
|
3009
|
-
retry: 10,
|
|
3010
|
-
}, async () => {
|
|
3011
|
-
const key = "a";
|
|
3012
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3013
|
-
const limit = 4;
|
|
3014
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3015
|
-
ttl,
|
|
3016
|
-
limit,
|
|
3017
|
-
});
|
|
3018
|
-
await sharedLock.acquireWriter();
|
|
3019
|
-
await delay(ttl);
|
|
3020
|
-
const result = await sharedLock.forceReleaseWriter();
|
|
3021
|
-
expect(result).toBe(false);
|
|
3022
|
-
});
|
|
3023
|
-
test("Should return true when key is uenxpired", async () => {
|
|
3024
|
-
const key = "a";
|
|
3025
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3026
|
-
const limit = 4;
|
|
3027
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3028
|
-
ttl,
|
|
3029
|
-
limit,
|
|
3030
|
-
});
|
|
3031
|
-
await sharedLock.acquireWriter();
|
|
3032
|
-
const result = await sharedLock.forceReleaseWriter();
|
|
3033
|
-
expect(result).toBe(true);
|
|
3034
|
-
});
|
|
3035
|
-
test("Should return true when key is unexpireable", async () => {
|
|
3036
|
-
const key = "a";
|
|
3037
|
-
const ttl = null;
|
|
3038
|
-
const limit = 4;
|
|
3039
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3040
|
-
ttl,
|
|
3041
|
-
limit,
|
|
3042
|
-
});
|
|
3043
|
-
await sharedLock.acquireWriter();
|
|
3044
|
-
const result = await sharedLock.forceReleaseWriter();
|
|
3045
|
-
expect(result).toBe(true);
|
|
3046
|
-
});
|
|
3047
|
-
test("Should be reacquirable when key is force released", async () => {
|
|
3048
|
-
const key = "a";
|
|
3049
|
-
const ttl = null;
|
|
3050
|
-
const limit = 4;
|
|
3051
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
3052
|
-
ttl,
|
|
3053
|
-
limit,
|
|
3054
|
-
});
|
|
3055
|
-
await sharedLock1.acquireWriter();
|
|
3056
|
-
await sharedLock1.forceReleaseWriter();
|
|
3057
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
3058
|
-
ttl,
|
|
3059
|
-
limit,
|
|
3060
|
-
});
|
|
3061
|
-
const result = await sharedLock2.acquireWriter();
|
|
3062
|
-
expect(result).toBe(true);
|
|
3063
|
-
});
|
|
3064
|
-
test("Should return false when key is acquired as reader", async () => {
|
|
3065
|
-
const key = "a";
|
|
3066
|
-
const limit = 2;
|
|
3067
|
-
const ttl = TimeSpan.fromSeconds(10);
|
|
3068
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3069
|
-
ttl,
|
|
3070
|
-
limit,
|
|
3071
|
-
});
|
|
3072
|
-
await sharedLock.acquireReader();
|
|
3073
|
-
const result = await sharedLock.forceReleaseWriter();
|
|
3074
|
-
expect(result).toBe(false);
|
|
3075
|
-
});
|
|
3076
|
-
test("Should not update state when key is acquired as reader", async () => {
|
|
3077
|
-
const key = "a";
|
|
3078
|
-
const limit = 3;
|
|
3079
|
-
const ttl = null;
|
|
3080
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3081
|
-
ttl,
|
|
3082
|
-
limit,
|
|
3083
|
-
});
|
|
3084
|
-
await sharedLock.acquireReader();
|
|
3085
|
-
await sharedLock.forceReleaseWriter();
|
|
3086
|
-
const state = await sharedLock.getState();
|
|
3087
|
-
expect(state).toEqual({
|
|
3088
|
-
type: SHARED_LOCK_STATE.READER_ACQUIRED,
|
|
3089
|
-
limit,
|
|
3090
|
-
remainingTime: null,
|
|
3091
|
-
freeSlotsCount: 2,
|
|
3092
|
-
acquiredSlotsCount: 1,
|
|
3093
|
-
acquiredSlots: [sharedLock.id],
|
|
3094
|
-
});
|
|
3095
|
-
});
|
|
3096
|
-
});
|
|
3097
|
-
describe("method: runReader", () => {
|
|
3098
|
-
test("Should call acquire method", async () => {
|
|
3099
|
-
const key = "a";
|
|
3100
|
-
const ttl = null;
|
|
3101
|
-
const limit = 1;
|
|
3102
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3103
|
-
ttl,
|
|
3104
|
-
limit,
|
|
3105
|
-
});
|
|
3106
|
-
const acquireSpy = vi.spyOn(sharedLock, "acquireReader");
|
|
3107
|
-
await sharedLock.runReader(() => {
|
|
3108
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3109
|
-
});
|
|
3110
|
-
expect(acquireSpy).toHaveBeenCalledTimes(1);
|
|
3111
|
-
});
|
|
3112
|
-
test("Should call acquire before release method", async () => {
|
|
3113
|
-
const key = "a";
|
|
3114
|
-
const ttl = null;
|
|
3115
|
-
const limit = 1;
|
|
3116
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3117
|
-
ttl,
|
|
3118
|
-
limit,
|
|
3119
|
-
});
|
|
3120
|
-
const acquireSpy = vi.spyOn(sharedLock, "acquireReader");
|
|
3121
|
-
const releaseSpy = vi.spyOn(sharedLock, "releaseReader");
|
|
3122
|
-
await sharedLock.runReader(() => {
|
|
3123
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3124
|
-
});
|
|
3125
|
-
expect(acquireSpy).toHaveBeenCalledBefore(releaseSpy);
|
|
3126
|
-
});
|
|
3127
|
-
test("Should call release method", async () => {
|
|
3128
|
-
const key = "a";
|
|
3129
|
-
const ttl = null;
|
|
3130
|
-
const limit = 1;
|
|
3131
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3132
|
-
ttl,
|
|
3133
|
-
limit,
|
|
3134
|
-
});
|
|
3135
|
-
const releaseSpy = vi.spyOn(sharedLock, "releaseReader");
|
|
3136
|
-
await sharedLock.runReader(() => {
|
|
3137
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3138
|
-
});
|
|
3139
|
-
expect(releaseSpy).toHaveBeenCalledTimes(1);
|
|
3140
|
-
});
|
|
3141
|
-
test("Should call release after acquire method", async () => {
|
|
3142
|
-
const key = "a";
|
|
3143
|
-
const ttl = null;
|
|
3144
|
-
const limit = 1;
|
|
3145
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3146
|
-
ttl,
|
|
3147
|
-
limit,
|
|
3148
|
-
});
|
|
3149
|
-
const releaseSpy = vi.spyOn(sharedLock, "releaseReader");
|
|
3150
|
-
const acquireSpy = vi.spyOn(sharedLock, "acquireReader");
|
|
3151
|
-
await sharedLock.runReader(() => {
|
|
3152
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3153
|
-
});
|
|
3154
|
-
expect(releaseSpy).toHaveBeenCalledAfter(acquireSpy);
|
|
3155
|
-
});
|
|
3156
|
-
test("Should call release when an error is thrown", async () => {
|
|
3157
|
-
const key = "a";
|
|
3158
|
-
const ttl = null;
|
|
3159
|
-
const limit = 1;
|
|
3160
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3161
|
-
ttl,
|
|
3162
|
-
limit,
|
|
3163
|
-
});
|
|
3164
|
-
const releaseSpy = vi.spyOn(sharedLock, "releaseReader");
|
|
3165
|
-
try {
|
|
3166
|
-
await sharedLock.runReader(() => {
|
|
3167
|
-
return Promise.reject(new Error());
|
|
3168
|
-
});
|
|
3169
|
-
}
|
|
3170
|
-
catch {
|
|
3171
|
-
/* EMPTY */
|
|
3172
|
-
}
|
|
3173
|
-
expect(releaseSpy).toHaveBeenCalledTimes(1);
|
|
3174
|
-
});
|
|
3175
|
-
test("Should propagate thrown error", async () => {
|
|
3176
|
-
const key = "a";
|
|
3177
|
-
const ttl = null;
|
|
3178
|
-
const limit = 1;
|
|
3179
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3180
|
-
ttl,
|
|
3181
|
-
limit,
|
|
3182
|
-
});
|
|
3183
|
-
class CustomError extends Error {
|
|
3184
|
-
}
|
|
3185
|
-
const error = sharedLock.runReader(() => {
|
|
3186
|
-
return Promise.reject(new CustomError());
|
|
3187
|
-
});
|
|
3188
|
-
await expect(error).rejects.toBeInstanceOf(CustomError);
|
|
3189
|
-
});
|
|
3190
|
-
test("Should call handler function when key doesnt exists", async () => {
|
|
3191
|
-
const key = "a";
|
|
3192
|
-
const ttl = null;
|
|
3193
|
-
const limit = 1;
|
|
3194
|
-
const handlerFn = vi.fn(() => {
|
|
3195
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3196
|
-
});
|
|
3197
|
-
await sharedLockProvider
|
|
3198
|
-
.create(key, {
|
|
3199
|
-
ttl,
|
|
3200
|
-
limit,
|
|
3201
|
-
})
|
|
3202
|
-
.runReader(handlerFn);
|
|
3203
|
-
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3204
|
-
});
|
|
3205
|
-
test("Should call handler function when key doesnt exists", async () => {
|
|
3206
|
-
const key = "a";
|
|
3207
|
-
const ttl = null;
|
|
3208
|
-
const limit = 1;
|
|
3209
|
-
const handlerFn = vi.fn(() => {
|
|
3210
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3211
|
-
});
|
|
3212
|
-
await sharedLockProvider
|
|
3213
|
-
.create(key, {
|
|
3214
|
-
ttl,
|
|
3215
|
-
limit,
|
|
3216
|
-
})
|
|
3217
|
-
.runReader(handlerFn);
|
|
3218
|
-
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3219
|
-
});
|
|
3220
|
-
test("Should call handler function when slot is expired", {
|
|
3221
|
-
retry: 10,
|
|
3222
|
-
}, async () => {
|
|
3223
|
-
const key = "a";
|
|
3224
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3225
|
-
const limit = 1;
|
|
3226
|
-
await sharedLockProvider
|
|
3227
|
-
.create(key, {
|
|
3228
|
-
ttl,
|
|
3229
|
-
limit,
|
|
3230
|
-
})
|
|
3231
|
-
.acquireReader();
|
|
3232
|
-
await delay(ttl);
|
|
3233
|
-
const handlerFn = vi.fn(() => {
|
|
3234
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3235
|
-
});
|
|
3236
|
-
await sharedLockProvider
|
|
3237
|
-
.create(key, {
|
|
3238
|
-
ttl,
|
|
3239
|
-
limit,
|
|
3240
|
-
})
|
|
3241
|
-
.runReader(handlerFn);
|
|
3242
|
-
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3243
|
-
});
|
|
3244
|
-
test("Should not call handler function when slot is unexpireable", async () => {
|
|
3245
|
-
const key = "a";
|
|
3246
|
-
const ttl = null;
|
|
3247
|
-
const limit = 1;
|
|
3248
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3249
|
-
ttl,
|
|
3250
|
-
limit,
|
|
3251
|
-
});
|
|
3252
|
-
await sharedLock.acquireReader();
|
|
3253
|
-
const handlerFn = vi.fn(() => {
|
|
3254
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3255
|
-
});
|
|
3256
|
-
await sharedLock.runReader(handlerFn);
|
|
3257
|
-
expect(handlerFn).not.toHaveBeenCalled();
|
|
3258
|
-
});
|
|
3259
|
-
test("Should not call handler function when slot is unexpired", async () => {
|
|
3260
|
-
const key = "a";
|
|
3261
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3262
|
-
const limit = 1;
|
|
3263
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3264
|
-
ttl,
|
|
3265
|
-
limit,
|
|
3266
|
-
});
|
|
3267
|
-
await sharedLock.acquireReader();
|
|
3268
|
-
const handlerFn = vi.fn(() => {
|
|
3269
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3270
|
-
});
|
|
3271
|
-
await sharedLock.runReader(handlerFn);
|
|
3272
|
-
expect(handlerFn).not.toHaveBeenCalled();
|
|
3273
|
-
});
|
|
3274
|
-
test("Should not call handler function when slot is unexpireable", async () => {
|
|
3275
|
-
const key = "a";
|
|
3276
|
-
const ttl = null;
|
|
3277
|
-
const limit = 1;
|
|
3278
|
-
await sharedLockProvider
|
|
3279
|
-
.create(key, {
|
|
3280
|
-
ttl,
|
|
3281
|
-
limit,
|
|
3282
|
-
})
|
|
3283
|
-
.acquireReader();
|
|
3284
|
-
const handlerFn = vi.fn(() => {
|
|
3285
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3286
|
-
});
|
|
3287
|
-
await sharedLockProvider
|
|
3288
|
-
.create(key, {
|
|
3289
|
-
ttl,
|
|
3290
|
-
limit,
|
|
3291
|
-
})
|
|
3292
|
-
.runReader(handlerFn);
|
|
3293
|
-
expect(handlerFn).not.toHaveBeenCalled();
|
|
3294
|
-
});
|
|
3295
|
-
test("Should not call handler function when slot is unexpired", async () => {
|
|
3296
|
-
const key = "a";
|
|
3297
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3298
|
-
const limit = 1;
|
|
3299
|
-
await sharedLockProvider
|
|
3300
|
-
.create(key, {
|
|
3301
|
-
ttl,
|
|
3302
|
-
limit,
|
|
3303
|
-
})
|
|
3304
|
-
.acquireReader();
|
|
3305
|
-
const handlerFn = vi.fn(() => {
|
|
3306
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3307
|
-
});
|
|
3308
|
-
await sharedLockProvider
|
|
3309
|
-
.create(key, {
|
|
3310
|
-
ttl,
|
|
3311
|
-
limit,
|
|
3312
|
-
})
|
|
3313
|
-
.runReader(handlerFn);
|
|
3314
|
-
expect(handlerFn).not.toHaveBeenCalled();
|
|
3315
|
-
});
|
|
3316
|
-
test("Should return value when key doesnt exists", async () => {
|
|
3317
|
-
const key = "a";
|
|
3318
|
-
const ttl = null;
|
|
3319
|
-
const limit = 1;
|
|
3320
|
-
const result = await sharedLockProvider
|
|
3321
|
-
.create(key, {
|
|
3322
|
-
ttl,
|
|
3323
|
-
limit,
|
|
3324
|
-
})
|
|
3325
|
-
.runReader(() => {
|
|
3326
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3327
|
-
});
|
|
3328
|
-
expect(result).toEqual(resultSuccess(RETURN_VALUE));
|
|
3329
|
-
});
|
|
3330
|
-
test("Should return value when slot is expired", {
|
|
3331
|
-
retry: 10,
|
|
3332
|
-
}, async () => {
|
|
3333
|
-
const key = "a";
|
|
3334
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3335
|
-
const limit = 1;
|
|
3336
|
-
await sharedLockProvider
|
|
3337
|
-
.create(key, {
|
|
3338
|
-
ttl,
|
|
3339
|
-
limit,
|
|
3340
|
-
})
|
|
3341
|
-
.acquireReader();
|
|
3342
|
-
await delay(ttl);
|
|
3343
|
-
const result = await sharedLockProvider
|
|
3344
|
-
.create(key, {
|
|
3345
|
-
ttl,
|
|
3346
|
-
limit,
|
|
3347
|
-
})
|
|
3348
|
-
.runReader(() => {
|
|
3349
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3350
|
-
});
|
|
3351
|
-
expect(result).toEqual(resultSuccess(RETURN_VALUE));
|
|
3352
|
-
});
|
|
3353
|
-
test("Should return ResultFailure<LimitReachedReaderSemaphoreError> when slot is unexpireable", async () => {
|
|
3354
|
-
const key = "a";
|
|
3355
|
-
const ttl = null;
|
|
3356
|
-
const limit = 1;
|
|
3357
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3358
|
-
ttl,
|
|
3359
|
-
limit,
|
|
3360
|
-
});
|
|
3361
|
-
await sharedLock.acquireReader();
|
|
3362
|
-
const result = await sharedLock.runReader(() => {
|
|
3363
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3364
|
-
});
|
|
3365
|
-
expect(result).toEqual(expect.objectContaining({
|
|
3366
|
-
type: RESULT.FAILURE,
|
|
3367
|
-
error: expect.any(LimitReachedReaderSemaphoreError),
|
|
3368
|
-
}));
|
|
3369
|
-
});
|
|
3370
|
-
test("Should return ResultFailure<LimitReachedReaderSemaphoreError> when slot is unexpired", async () => {
|
|
3371
|
-
const key = "a";
|
|
3372
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3373
|
-
const limit = 1;
|
|
3374
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3375
|
-
ttl,
|
|
3376
|
-
limit,
|
|
3377
|
-
});
|
|
3378
|
-
await sharedLock.acquireReader();
|
|
3379
|
-
const result = await sharedLock.runReader(() => {
|
|
3380
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3381
|
-
});
|
|
3382
|
-
expect(result).toEqual(expect.objectContaining({
|
|
3383
|
-
type: RESULT.FAILURE,
|
|
3384
|
-
error: expect.any(LimitReachedReaderSemaphoreError),
|
|
3385
|
-
}));
|
|
3386
|
-
});
|
|
3387
|
-
test("Should return ResultFailure<LimitReachedReaderSemaphoreError> when slot is unexpireable", async () => {
|
|
3388
|
-
const key = "a";
|
|
3389
|
-
const ttl = null;
|
|
3390
|
-
const limit = 1;
|
|
3391
|
-
await sharedLockProvider
|
|
3392
|
-
.create(key, {
|
|
3393
|
-
ttl,
|
|
3394
|
-
limit,
|
|
3395
|
-
})
|
|
3396
|
-
.acquireReader();
|
|
3397
|
-
const result = await sharedLockProvider
|
|
3398
|
-
.create(key, {
|
|
3399
|
-
ttl,
|
|
3400
|
-
limit,
|
|
3401
|
-
})
|
|
3402
|
-
.runReader(() => {
|
|
3403
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3404
|
-
});
|
|
3405
|
-
expect(result).toEqual(expect.objectContaining({
|
|
3406
|
-
type: RESULT.FAILURE,
|
|
3407
|
-
error: expect.any(LimitReachedReaderSemaphoreError),
|
|
3408
|
-
}));
|
|
3409
|
-
});
|
|
3410
|
-
test("Should return ResultFailure<LimitReachedReaderSemaphoreError> when slot is unexpired", async () => {
|
|
3411
|
-
const key = "a";
|
|
3412
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3413
|
-
const limit = 1;
|
|
3414
|
-
await sharedLockProvider
|
|
3415
|
-
.create(key, {
|
|
3416
|
-
ttl,
|
|
3417
|
-
limit,
|
|
3418
|
-
})
|
|
3419
|
-
.acquireReader();
|
|
3420
|
-
const result = await sharedLockProvider
|
|
3421
|
-
.create(key, {
|
|
3422
|
-
ttl,
|
|
3423
|
-
limit,
|
|
3424
|
-
})
|
|
3425
|
-
.runReader(() => {
|
|
3426
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3427
|
-
});
|
|
3428
|
-
expect(result).toEqual(expect.objectContaining({
|
|
3429
|
-
type: RESULT.FAILURE,
|
|
3430
|
-
error: expect.any(LimitReachedReaderSemaphoreError),
|
|
3431
|
-
}));
|
|
3432
|
-
});
|
|
3433
|
-
});
|
|
3434
|
-
describe("method: runReaderOrFail", () => {
|
|
3435
|
-
test("Should call acquireReaderOrFail method", async () => {
|
|
3436
|
-
const key = "a";
|
|
3437
|
-
const ttl = null;
|
|
3438
|
-
const limit = 1;
|
|
3439
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3440
|
-
ttl,
|
|
3441
|
-
limit,
|
|
3442
|
-
});
|
|
3443
|
-
const acquireReaderOrFailSpy = vi.spyOn(sharedLock, "acquireReaderOrFail");
|
|
3444
|
-
await sharedLock.runReaderOrFail(() => {
|
|
3445
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3446
|
-
});
|
|
3447
|
-
expect(acquireReaderOrFailSpy).toHaveBeenCalledTimes(1);
|
|
3448
|
-
});
|
|
3449
|
-
test("Should call acquireReaderOrFail before release method", async () => {
|
|
3450
|
-
const key = "a";
|
|
3451
|
-
const ttl = null;
|
|
3452
|
-
const limit = 1;
|
|
3453
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3454
|
-
ttl,
|
|
3455
|
-
limit,
|
|
3456
|
-
});
|
|
3457
|
-
const acquireReaderOrFailSpy = vi.spyOn(sharedLock, "acquireReaderOrFail");
|
|
3458
|
-
const releaseSpy = vi.spyOn(sharedLock, "releaseReader");
|
|
3459
|
-
await sharedLock.runReaderOrFail(() => {
|
|
3460
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3461
|
-
});
|
|
3462
|
-
expect(acquireReaderOrFailSpy).toHaveBeenCalledBefore(releaseSpy);
|
|
3463
|
-
});
|
|
3464
|
-
test("Should call release method", async () => {
|
|
3465
|
-
const key = "a";
|
|
3466
|
-
const ttl = null;
|
|
3467
|
-
const limit = 1;
|
|
3468
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3469
|
-
ttl,
|
|
3470
|
-
limit,
|
|
3471
|
-
});
|
|
3472
|
-
const releaseSpy = vi.spyOn(sharedLock, "releaseReader");
|
|
3473
|
-
await sharedLock.runReaderOrFail(() => {
|
|
3474
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3475
|
-
});
|
|
3476
|
-
expect(releaseSpy).toHaveBeenCalledTimes(1);
|
|
3477
|
-
});
|
|
3478
|
-
test("Should call release after acquireReaderOrFail method", async () => {
|
|
3479
|
-
const key = "a";
|
|
3480
|
-
const ttl = null;
|
|
3481
|
-
const limit = 1;
|
|
3482
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3483
|
-
ttl,
|
|
3484
|
-
limit,
|
|
3485
|
-
});
|
|
3486
|
-
const releaseSpy = vi.spyOn(sharedLock, "releaseReader");
|
|
3487
|
-
const acquireReaderOrFailSpy = vi.spyOn(sharedLock, "acquireReaderOrFail");
|
|
3488
|
-
await sharedLock.runReaderOrFail(() => {
|
|
3489
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3490
|
-
});
|
|
3491
|
-
expect(releaseSpy).toHaveBeenCalledAfter(acquireReaderOrFailSpy);
|
|
3492
|
-
});
|
|
3493
|
-
test("Should call release when an error is thrown", async () => {
|
|
3494
|
-
const key = "a";
|
|
3495
|
-
const ttl = null;
|
|
3496
|
-
const limit = 1;
|
|
3497
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3498
|
-
ttl,
|
|
3499
|
-
limit,
|
|
3500
|
-
});
|
|
3501
|
-
const releaseSpy = vi.spyOn(sharedLock, "releaseReader");
|
|
3502
|
-
try {
|
|
3503
|
-
await sharedLock.runReaderOrFail(() => {
|
|
3504
|
-
return Promise.reject(new Error());
|
|
3505
|
-
});
|
|
3506
|
-
}
|
|
3507
|
-
catch {
|
|
3508
|
-
/* EMPTY */
|
|
3509
|
-
}
|
|
3510
|
-
expect(releaseSpy).toHaveBeenCalledTimes(1);
|
|
3511
|
-
});
|
|
3512
|
-
test("Should propagate thrown error", async () => {
|
|
3513
|
-
const key = "a";
|
|
3514
|
-
const ttl = null;
|
|
3515
|
-
const limit = 1;
|
|
3516
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3517
|
-
ttl,
|
|
3518
|
-
limit,
|
|
3519
|
-
});
|
|
3520
|
-
class CustomError extends Error {
|
|
3521
|
-
}
|
|
3522
|
-
const error = sharedLock.runReaderOrFail(() => {
|
|
3523
|
-
return Promise.reject(new CustomError());
|
|
3524
|
-
});
|
|
3525
|
-
await expect(error).rejects.toBeInstanceOf(CustomError);
|
|
3526
|
-
});
|
|
3527
|
-
test("Should call handler function when key doesnt exists", async () => {
|
|
3528
|
-
const key = "a";
|
|
3529
|
-
const ttl = null;
|
|
3530
|
-
const limit = 1;
|
|
3531
|
-
const handlerFn = vi.fn(() => {
|
|
3532
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3533
|
-
});
|
|
3534
|
-
await sharedLockProvider
|
|
3535
|
-
.create(key, {
|
|
3536
|
-
ttl,
|
|
3537
|
-
limit,
|
|
3538
|
-
})
|
|
3539
|
-
.runReaderOrFail(handlerFn);
|
|
3540
|
-
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3541
|
-
});
|
|
3542
|
-
test("Should call handler function when slot is expired", {
|
|
3543
|
-
retry: 10,
|
|
3544
|
-
}, async () => {
|
|
3545
|
-
const key = "a";
|
|
3546
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3547
|
-
const limit = 1;
|
|
3548
|
-
await sharedLockProvider
|
|
3549
|
-
.create(key, {
|
|
3550
|
-
ttl,
|
|
3551
|
-
limit,
|
|
3552
|
-
})
|
|
3553
|
-
.acquireReader();
|
|
3554
|
-
await delay(ttl);
|
|
3555
|
-
const handlerFn = vi.fn(() => {
|
|
3556
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3557
|
-
});
|
|
3558
|
-
await sharedLockProvider
|
|
3559
|
-
.create(key, {
|
|
3560
|
-
ttl,
|
|
3561
|
-
limit,
|
|
3562
|
-
})
|
|
3563
|
-
.runReaderOrFail(handlerFn);
|
|
3564
|
-
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3565
|
-
});
|
|
3566
|
-
test("Should not call handler function when slot is unexpireable", async () => {
|
|
3567
|
-
const key = "a";
|
|
3568
|
-
const ttl = null;
|
|
3569
|
-
const limit = 1;
|
|
3570
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3571
|
-
ttl,
|
|
3572
|
-
limit,
|
|
3573
|
-
});
|
|
3574
|
-
await sharedLock.acquireReader();
|
|
3575
|
-
const handlerFn = vi.fn(() => {
|
|
3576
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3577
|
-
});
|
|
3578
|
-
try {
|
|
3579
|
-
await sharedLock.runReaderOrFail(handlerFn);
|
|
3580
|
-
}
|
|
3581
|
-
catch {
|
|
3582
|
-
/* EMPTY */
|
|
3583
|
-
}
|
|
3584
|
-
expect(handlerFn).not.toHaveBeenCalled();
|
|
3585
|
-
});
|
|
3586
|
-
test("Should not call handler function when slot is unexpired", async () => {
|
|
3587
|
-
const key = "a";
|
|
3588
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3589
|
-
const limit = 1;
|
|
3590
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3591
|
-
ttl,
|
|
3592
|
-
limit,
|
|
3593
|
-
});
|
|
3594
|
-
await sharedLock.acquireReader();
|
|
3595
|
-
const handlerFn = vi.fn(() => {
|
|
3596
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3597
|
-
});
|
|
3598
|
-
try {
|
|
3599
|
-
await sharedLock.runReaderOrFail(handlerFn);
|
|
3600
|
-
}
|
|
3601
|
-
catch {
|
|
3602
|
-
/* EMPTY */
|
|
3603
|
-
}
|
|
3604
|
-
expect(handlerFn).not.toHaveBeenCalled();
|
|
3605
|
-
});
|
|
3606
|
-
test("Should not call handler function when slot is unexpireable", async () => {
|
|
3607
|
-
const key = "a";
|
|
3608
|
-
const ttl = null;
|
|
3609
|
-
const limit = 1;
|
|
3610
|
-
await sharedLockProvider
|
|
3611
|
-
.create(key, {
|
|
3612
|
-
ttl,
|
|
3613
|
-
limit,
|
|
3614
|
-
})
|
|
3615
|
-
.acquireReader();
|
|
3616
|
-
const handlerFn = vi.fn(() => {
|
|
3617
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3618
|
-
});
|
|
3619
|
-
try {
|
|
3620
|
-
await sharedLockProvider
|
|
3621
|
-
.create(key, {
|
|
3622
|
-
ttl,
|
|
3623
|
-
limit,
|
|
3624
|
-
})
|
|
3625
|
-
.runReaderOrFail(handlerFn);
|
|
3626
|
-
}
|
|
3627
|
-
catch {
|
|
3628
|
-
/* EMPTY */
|
|
3629
|
-
}
|
|
3630
|
-
expect(handlerFn).not.toHaveBeenCalled();
|
|
3631
|
-
});
|
|
3632
|
-
test("Should not call handler function when slot is unexpired", async () => {
|
|
3633
|
-
const key = "a";
|
|
3634
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3635
|
-
const limit = 1;
|
|
3636
|
-
await sharedLockProvider
|
|
3637
|
-
.create(key, {
|
|
3638
|
-
ttl,
|
|
3639
|
-
limit,
|
|
3640
|
-
})
|
|
3641
|
-
.acquireReader();
|
|
3642
|
-
const handlerFn = vi.fn(() => {
|
|
3643
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3644
|
-
});
|
|
3645
|
-
try {
|
|
3646
|
-
await sharedLockProvider
|
|
3647
|
-
.create(key, {
|
|
3648
|
-
ttl,
|
|
3649
|
-
limit,
|
|
3650
|
-
})
|
|
3651
|
-
.runReaderOrFail(handlerFn);
|
|
3652
|
-
}
|
|
3653
|
-
catch {
|
|
3654
|
-
/* EMPTY */
|
|
3655
|
-
}
|
|
3656
|
-
expect(handlerFn).not.toHaveBeenCalled();
|
|
3657
|
-
});
|
|
3658
|
-
test("Should return value when key doesnt exists", async () => {
|
|
3659
|
-
const key = "a";
|
|
3660
|
-
const ttl = null;
|
|
3661
|
-
const limit = 1;
|
|
3662
|
-
const result = await sharedLockProvider
|
|
3663
|
-
.create(key, {
|
|
3664
|
-
ttl,
|
|
3665
|
-
limit,
|
|
3666
|
-
})
|
|
3667
|
-
.runReaderOrFail(() => {
|
|
3668
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3669
|
-
});
|
|
3670
|
-
expect(result).toBe(RETURN_VALUE);
|
|
3671
|
-
});
|
|
3672
|
-
test("Should return value when slot is expired", {
|
|
3673
|
-
retry: 10,
|
|
3674
|
-
}, async () => {
|
|
3675
|
-
const key = "a";
|
|
3676
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
3677
|
-
const limit = 1;
|
|
3678
|
-
await sharedLockProvider
|
|
3679
|
-
.create(key, {
|
|
3680
|
-
ttl,
|
|
3681
|
-
limit,
|
|
3682
|
-
})
|
|
3683
|
-
.acquireReader();
|
|
3684
|
-
await delay(ttl);
|
|
3685
|
-
const result = await sharedLockProvider
|
|
3686
|
-
.create(key, {
|
|
3687
|
-
ttl,
|
|
3688
|
-
limit,
|
|
3689
|
-
})
|
|
3690
|
-
.runReaderOrFail(() => {
|
|
3691
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3692
|
-
});
|
|
3693
|
-
expect(result).toBe(RETURN_VALUE);
|
|
3694
|
-
});
|
|
3695
|
-
test("Should throw LimitReachedReaderSemaphoreError when slot is unexpireable", async () => {
|
|
3696
|
-
const key = "a";
|
|
3697
|
-
const ttl = null;
|
|
3698
|
-
const limit = 1;
|
|
3699
|
-
const sharedLock = sharedLockProvider.create(key, {
|
|
3700
|
-
ttl,
|
|
3701
|
-
limit,
|
|
3702
|
-
});
|
|
3703
|
-
await sharedLock.acquireReader();
|
|
3704
|
-
const result = sharedLock.runReaderOrFail(() => {
|
|
3705
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3706
|
-
});
|
|
3707
|
-
await expect(result).rejects.toBeInstanceOf(LimitReachedReaderSemaphoreError);
|
|
2330
|
+
const result = await sharedLock2.acquireWriter();
|
|
2331
|
+
expect(result).toBe(true);
|
|
3708
2332
|
});
|
|
3709
|
-
test("Should
|
|
2333
|
+
test("Should return false when key is acquired as reader", async () => {
|
|
3710
2334
|
const key = "a";
|
|
3711
|
-
const
|
|
3712
|
-
const
|
|
2335
|
+
const limit = 2;
|
|
2336
|
+
const ttl = TimeSpan.fromSeconds(10);
|
|
3713
2337
|
const sharedLock = sharedLockProvider.create(key, {
|
|
3714
2338
|
ttl,
|
|
3715
2339
|
limit,
|
|
3716
2340
|
});
|
|
3717
2341
|
await sharedLock.acquireReader();
|
|
3718
|
-
const result = sharedLock.
|
|
3719
|
-
|
|
3720
|
-
});
|
|
3721
|
-
await expect(result).rejects.toBeInstanceOf(LimitReachedReaderSemaphoreError);
|
|
2342
|
+
const result = await sharedLock.forceReleaseWriter();
|
|
2343
|
+
expect(result).toBe(false);
|
|
3722
2344
|
});
|
|
3723
|
-
test("Should
|
|
2345
|
+
test("Should not update state when key is acquired as reader", async () => {
|
|
3724
2346
|
const key = "a";
|
|
2347
|
+
const limit = 3;
|
|
3725
2348
|
const ttl = null;
|
|
3726
|
-
const
|
|
3727
|
-
await sharedLockProvider
|
|
3728
|
-
.create(key, {
|
|
3729
|
-
ttl,
|
|
3730
|
-
limit,
|
|
3731
|
-
})
|
|
3732
|
-
.acquireReader();
|
|
3733
|
-
const result = sharedLockProvider
|
|
3734
|
-
.create(key, {
|
|
2349
|
+
const sharedLock = sharedLockProvider.create(key, {
|
|
3735
2350
|
ttl,
|
|
3736
2351
|
limit,
|
|
3737
|
-
})
|
|
3738
|
-
.runReaderOrFail(() => {
|
|
3739
|
-
return Promise.resolve(RETURN_VALUE);
|
|
3740
2352
|
});
|
|
3741
|
-
await
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
const limit = 1;
|
|
3747
|
-
await sharedLockProvider
|
|
3748
|
-
.create(key, {
|
|
3749
|
-
ttl,
|
|
3750
|
-
limit,
|
|
3751
|
-
})
|
|
3752
|
-
.acquireReader();
|
|
3753
|
-
const result = sharedLockProvider
|
|
3754
|
-
.create(key, {
|
|
3755
|
-
ttl,
|
|
2353
|
+
await sharedLock.acquireReader();
|
|
2354
|
+
await sharedLock.forceReleaseWriter();
|
|
2355
|
+
const state = await sharedLock.getState();
|
|
2356
|
+
expect(state).toEqual({
|
|
2357
|
+
type: SHARED_LOCK_STATE.READER_ACQUIRED,
|
|
3756
2358
|
limit,
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
2359
|
+
remainingTime: null,
|
|
2360
|
+
freeSlotsCount: 2,
|
|
2361
|
+
acquiredSlotsCount: 1,
|
|
2362
|
+
acquiredSlots: [sharedLock.id],
|
|
3760
2363
|
});
|
|
3761
|
-
await expect(result).rejects.toBeInstanceOf(LimitReachedReaderSemaphoreError);
|
|
3762
2364
|
});
|
|
3763
2365
|
});
|
|
3764
|
-
describe("method:
|
|
3765
|
-
test("Should call
|
|
2366
|
+
describe("method: runReaderOrFail", () => {
|
|
2367
|
+
test("Should call acquireReaderOrFail method", async () => {
|
|
3766
2368
|
const key = "a";
|
|
3767
2369
|
const ttl = null;
|
|
3768
2370
|
const limit = 1;
|
|
@@ -3770,16 +2372,13 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
3770
2372
|
ttl,
|
|
3771
2373
|
limit,
|
|
3772
2374
|
});
|
|
3773
|
-
const
|
|
3774
|
-
await sharedLock.
|
|
2375
|
+
const acquireReaderOrFailSpy = vi.spyOn(sharedLock, "acquireReaderOrFail");
|
|
2376
|
+
await sharedLock.runReaderOrFail(() => {
|
|
3775
2377
|
return Promise.resolve(RETURN_VALUE);
|
|
3776
|
-
}, {
|
|
3777
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
3778
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
3779
2378
|
});
|
|
3780
|
-
expect(
|
|
2379
|
+
expect(acquireReaderOrFailSpy).toHaveBeenCalledTimes(1);
|
|
3781
2380
|
});
|
|
3782
|
-
test("Should call
|
|
2381
|
+
test("Should call acquireReaderOrFail before release method", async () => {
|
|
3783
2382
|
const key = "a";
|
|
3784
2383
|
const ttl = null;
|
|
3785
2384
|
const limit = 1;
|
|
@@ -3787,15 +2386,12 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
3787
2386
|
ttl,
|
|
3788
2387
|
limit,
|
|
3789
2388
|
});
|
|
3790
|
-
const
|
|
2389
|
+
const acquireReaderOrFailSpy = vi.spyOn(sharedLock, "acquireReaderOrFail");
|
|
3791
2390
|
const releaseSpy = vi.spyOn(sharedLock, "releaseReader");
|
|
3792
|
-
await sharedLock.
|
|
2391
|
+
await sharedLock.runReaderOrFail(() => {
|
|
3793
2392
|
return Promise.resolve(RETURN_VALUE);
|
|
3794
|
-
}, {
|
|
3795
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
3796
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
3797
2393
|
});
|
|
3798
|
-
expect(
|
|
2394
|
+
expect(acquireReaderOrFailSpy).toHaveBeenCalledBefore(releaseSpy);
|
|
3799
2395
|
});
|
|
3800
2396
|
test("Should call release method", async () => {
|
|
3801
2397
|
const key = "a";
|
|
@@ -3806,15 +2402,12 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
3806
2402
|
limit,
|
|
3807
2403
|
});
|
|
3808
2404
|
const releaseSpy = vi.spyOn(sharedLock, "releaseReader");
|
|
3809
|
-
await sharedLock.
|
|
2405
|
+
await sharedLock.runReaderOrFail(() => {
|
|
3810
2406
|
return Promise.resolve(RETURN_VALUE);
|
|
3811
|
-
}, {
|
|
3812
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
3813
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
3814
2407
|
});
|
|
3815
2408
|
expect(releaseSpy).toHaveBeenCalledTimes(1);
|
|
3816
2409
|
});
|
|
3817
|
-
test("Should call release after
|
|
2410
|
+
test("Should call release after acquireReaderOrFail method", async () => {
|
|
3818
2411
|
const key = "a";
|
|
3819
2412
|
const ttl = null;
|
|
3820
2413
|
const limit = 1;
|
|
@@ -3823,14 +2416,11 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
3823
2416
|
limit,
|
|
3824
2417
|
});
|
|
3825
2418
|
const releaseSpy = vi.spyOn(sharedLock, "releaseReader");
|
|
3826
|
-
const
|
|
3827
|
-
await sharedLock.
|
|
2419
|
+
const acquireReaderOrFailSpy = vi.spyOn(sharedLock, "acquireReaderOrFail");
|
|
2420
|
+
await sharedLock.runReaderOrFail(() => {
|
|
3828
2421
|
return Promise.resolve(RETURN_VALUE);
|
|
3829
|
-
}, {
|
|
3830
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
3831
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
3832
2422
|
});
|
|
3833
|
-
expect(releaseSpy).toHaveBeenCalledAfter(
|
|
2423
|
+
expect(releaseSpy).toHaveBeenCalledAfter(acquireReaderOrFailSpy);
|
|
3834
2424
|
});
|
|
3835
2425
|
test("Should call release when an error is thrown", async () => {
|
|
3836
2426
|
const key = "a";
|
|
@@ -3842,11 +2432,8 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
3842
2432
|
});
|
|
3843
2433
|
const releaseSpy = vi.spyOn(sharedLock, "releaseReader");
|
|
3844
2434
|
try {
|
|
3845
|
-
await sharedLock.
|
|
2435
|
+
await sharedLock.runReaderOrFail(() => {
|
|
3846
2436
|
return Promise.reject(new Error());
|
|
3847
|
-
}, {
|
|
3848
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
3849
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
3850
2437
|
});
|
|
3851
2438
|
}
|
|
3852
2439
|
catch {
|
|
@@ -3864,11 +2451,8 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
3864
2451
|
});
|
|
3865
2452
|
class CustomError extends Error {
|
|
3866
2453
|
}
|
|
3867
|
-
const error = sharedLock.
|
|
2454
|
+
const error = sharedLock.runReaderOrFail(() => {
|
|
3868
2455
|
return Promise.reject(new CustomError());
|
|
3869
|
-
}, {
|
|
3870
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
3871
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
3872
2456
|
});
|
|
3873
2457
|
await expect(error).rejects.toBeInstanceOf(CustomError);
|
|
3874
2458
|
});
|
|
@@ -3884,10 +2468,7 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
3884
2468
|
ttl,
|
|
3885
2469
|
limit,
|
|
3886
2470
|
})
|
|
3887
|
-
.
|
|
3888
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
3889
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
3890
|
-
});
|
|
2471
|
+
.runReaderOrFail(handlerFn);
|
|
3891
2472
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3892
2473
|
});
|
|
3893
2474
|
test("Should call handler function when slot is expired", {
|
|
@@ -3911,10 +2492,7 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
3911
2492
|
ttl,
|
|
3912
2493
|
limit,
|
|
3913
2494
|
})
|
|
3914
|
-
.
|
|
3915
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
3916
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
3917
|
-
});
|
|
2495
|
+
.runReaderOrFail(handlerFn);
|
|
3918
2496
|
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
3919
2497
|
});
|
|
3920
2498
|
test("Should not call handler function when slot is unexpireable", async () => {
|
|
@@ -3929,10 +2507,12 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
3929
2507
|
const handlerFn = vi.fn(() => {
|
|
3930
2508
|
return Promise.resolve(RETURN_VALUE);
|
|
3931
2509
|
});
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
2510
|
+
try {
|
|
2511
|
+
await sharedLock.runReaderOrFail(handlerFn);
|
|
2512
|
+
}
|
|
2513
|
+
catch {
|
|
2514
|
+
/* EMPTY */
|
|
2515
|
+
}
|
|
3936
2516
|
expect(handlerFn).not.toHaveBeenCalled();
|
|
3937
2517
|
});
|
|
3938
2518
|
test("Should not call handler function when slot is unexpired", async () => {
|
|
@@ -3947,10 +2527,12 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
3947
2527
|
const handlerFn = vi.fn(() => {
|
|
3948
2528
|
return Promise.resolve(RETURN_VALUE);
|
|
3949
2529
|
});
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
2530
|
+
try {
|
|
2531
|
+
await sharedLock.runReaderOrFail(handlerFn);
|
|
2532
|
+
}
|
|
2533
|
+
catch {
|
|
2534
|
+
/* EMPTY */
|
|
2535
|
+
}
|
|
3954
2536
|
expect(handlerFn).not.toHaveBeenCalled();
|
|
3955
2537
|
});
|
|
3956
2538
|
test("Should not call handler function when slot is unexpireable", async () => {
|
|
@@ -3966,15 +2548,17 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
3966
2548
|
const handlerFn = vi.fn(() => {
|
|
3967
2549
|
return Promise.resolve(RETURN_VALUE);
|
|
3968
2550
|
});
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
2551
|
+
try {
|
|
2552
|
+
await sharedLockProvider
|
|
2553
|
+
.create(key, {
|
|
2554
|
+
ttl,
|
|
2555
|
+
limit,
|
|
2556
|
+
})
|
|
2557
|
+
.runReaderOrFail(handlerFn);
|
|
2558
|
+
}
|
|
2559
|
+
catch {
|
|
2560
|
+
/* EMPTY */
|
|
2561
|
+
}
|
|
3978
2562
|
expect(handlerFn).not.toHaveBeenCalled();
|
|
3979
2563
|
});
|
|
3980
2564
|
test("Should not call handler function when slot is unexpired", async () => {
|
|
@@ -3990,15 +2574,17 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
3990
2574
|
const handlerFn = vi.fn(() => {
|
|
3991
2575
|
return Promise.resolve(RETURN_VALUE);
|
|
3992
2576
|
});
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
2577
|
+
try {
|
|
2578
|
+
await sharedLockProvider
|
|
2579
|
+
.create(key, {
|
|
2580
|
+
ttl,
|
|
2581
|
+
limit,
|
|
2582
|
+
})
|
|
2583
|
+
.runReaderOrFail(handlerFn);
|
|
2584
|
+
}
|
|
2585
|
+
catch {
|
|
2586
|
+
/* EMPTY */
|
|
2587
|
+
}
|
|
4002
2588
|
expect(handlerFn).not.toHaveBeenCalled();
|
|
4003
2589
|
});
|
|
4004
2590
|
test("Should return value when key doesnt exists", async () => {
|
|
@@ -4010,13 +2596,10 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
4010
2596
|
ttl,
|
|
4011
2597
|
limit,
|
|
4012
2598
|
})
|
|
4013
|
-
.
|
|
2599
|
+
.runReaderOrFail(() => {
|
|
4014
2600
|
return Promise.resolve(RETURN_VALUE);
|
|
4015
|
-
}, {
|
|
4016
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
4017
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
4018
2601
|
});
|
|
4019
|
-
expect(result).
|
|
2602
|
+
expect(result).toBe(RETURN_VALUE);
|
|
4020
2603
|
});
|
|
4021
2604
|
test("Should return value when slot is expired", {
|
|
4022
2605
|
retry: 10,
|
|
@@ -4036,15 +2619,12 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
4036
2619
|
ttl,
|
|
4037
2620
|
limit,
|
|
4038
2621
|
})
|
|
4039
|
-
.
|
|
2622
|
+
.runReaderOrFail(() => {
|
|
4040
2623
|
return Promise.resolve(RETURN_VALUE);
|
|
4041
|
-
}, {
|
|
4042
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
4043
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
4044
2624
|
});
|
|
4045
|
-
expect(result).
|
|
2625
|
+
expect(result).toBe(RETURN_VALUE);
|
|
4046
2626
|
});
|
|
4047
|
-
test("Should
|
|
2627
|
+
test("Should throw LimitReachedReaderSemaphoreError when slot is unexpireable", async () => {
|
|
4048
2628
|
const key = "a";
|
|
4049
2629
|
const ttl = null;
|
|
4050
2630
|
const limit = 1;
|
|
@@ -4053,18 +2633,12 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
4053
2633
|
limit,
|
|
4054
2634
|
});
|
|
4055
2635
|
await sharedLock.acquireReader();
|
|
4056
|
-
const result =
|
|
2636
|
+
const result = sharedLock.runReaderOrFail(() => {
|
|
4057
2637
|
return Promise.resolve(RETURN_VALUE);
|
|
4058
|
-
}, {
|
|
4059
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
4060
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
4061
2638
|
});
|
|
4062
|
-
expect(result).
|
|
4063
|
-
type: RESULT.FAILURE,
|
|
4064
|
-
error: expect.any(LimitReachedReaderSemaphoreError),
|
|
4065
|
-
}));
|
|
2639
|
+
await expect(result).rejects.toBeInstanceOf(LimitReachedReaderSemaphoreError);
|
|
4066
2640
|
});
|
|
4067
|
-
test("Should
|
|
2641
|
+
test("Should throw LimitReachedReaderSemaphoreError when slot is unexpired", async () => {
|
|
4068
2642
|
const key = "a";
|
|
4069
2643
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
4070
2644
|
const limit = 1;
|
|
@@ -4073,18 +2647,12 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
4073
2647
|
limit,
|
|
4074
2648
|
});
|
|
4075
2649
|
await sharedLock.acquireReader();
|
|
4076
|
-
const result =
|
|
2650
|
+
const result = sharedLock.runReaderOrFail(() => {
|
|
4077
2651
|
return Promise.resolve(RETURN_VALUE);
|
|
4078
|
-
}, {
|
|
4079
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
4080
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
4081
2652
|
});
|
|
4082
|
-
expect(result).
|
|
4083
|
-
type: RESULT.FAILURE,
|
|
4084
|
-
error: expect.any(LimitReachedReaderSemaphoreError),
|
|
4085
|
-
}));
|
|
2653
|
+
await expect(result).rejects.toBeInstanceOf(LimitReachedReaderSemaphoreError);
|
|
4086
2654
|
});
|
|
4087
|
-
test("Should
|
|
2655
|
+
test("Should throw LimitReachedReaderSemaphoreError when slot is unexpireable", async () => {
|
|
4088
2656
|
const key = "a";
|
|
4089
2657
|
const ttl = null;
|
|
4090
2658
|
const limit = 1;
|
|
@@ -4094,23 +2662,17 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
4094
2662
|
limit,
|
|
4095
2663
|
})
|
|
4096
2664
|
.acquireReader();
|
|
4097
|
-
const result =
|
|
2665
|
+
const result = sharedLockProvider
|
|
4098
2666
|
.create(key, {
|
|
4099
2667
|
ttl,
|
|
4100
2668
|
limit,
|
|
4101
2669
|
})
|
|
4102
|
-
.
|
|
2670
|
+
.runReaderOrFail(() => {
|
|
4103
2671
|
return Promise.resolve(RETURN_VALUE);
|
|
4104
|
-
}, {
|
|
4105
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
4106
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
4107
2672
|
});
|
|
4108
|
-
expect(result).
|
|
4109
|
-
type: RESULT.FAILURE,
|
|
4110
|
-
error: expect.any(LimitReachedReaderSemaphoreError),
|
|
4111
|
-
}));
|
|
2673
|
+
await expect(result).rejects.toBeInstanceOf(LimitReachedReaderSemaphoreError);
|
|
4112
2674
|
});
|
|
4113
|
-
test("Should
|
|
2675
|
+
test("Should throw LimitReachedReaderSemaphoreError when slot is unexpired", async () => {
|
|
4114
2676
|
const key = "a";
|
|
4115
2677
|
const ttl = TimeSpan.fromMilliseconds(50);
|
|
4116
2678
|
const limit = 1;
|
|
@@ -4120,67 +2682,15 @@ export function sharedLockProviderTestSuite(settings) {
|
|
|
4120
2682
|
limit,
|
|
4121
2683
|
})
|
|
4122
2684
|
.acquireReader();
|
|
4123
|
-
const result =
|
|
2685
|
+
const result = sharedLockProvider
|
|
4124
2686
|
.create(key, {
|
|
4125
2687
|
ttl,
|
|
4126
2688
|
limit,
|
|
4127
2689
|
})
|
|
4128
|
-
.
|
|
4129
|
-
return Promise.resolve(RETURN_VALUE);
|
|
4130
|
-
}, {
|
|
4131
|
-
time: TimeSpan.fromMilliseconds(5),
|
|
4132
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
4133
|
-
});
|
|
4134
|
-
expect(result).toEqual(expect.objectContaining({
|
|
4135
|
-
type: RESULT.FAILURE,
|
|
4136
|
-
error: expect.any(LimitReachedReaderSemaphoreError),
|
|
4137
|
-
}));
|
|
4138
|
-
});
|
|
4139
|
-
test("Should retry acquire the shared lock when blocked by a writer", async () => {
|
|
4140
|
-
const key = "a";
|
|
4141
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
4142
|
-
const limit = 4;
|
|
4143
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
4144
|
-
ttl,
|
|
4145
|
-
limit,
|
|
4146
|
-
});
|
|
4147
|
-
await sharedLock1.acquireWriter();
|
|
4148
|
-
const handlerFn = vi.fn(() => { });
|
|
4149
|
-
await sharedLockProvider.addListener(SHARED_LOCK_EVENTS.UNAVAILABLE, handlerFn);
|
|
4150
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
4151
|
-
ttl,
|
|
4152
|
-
limit,
|
|
4153
|
-
});
|
|
4154
|
-
await sharedLock2.runReaderBlocking(() => {
|
|
4155
|
-
return Promise.resolve(RETURN_VALUE);
|
|
4156
|
-
}, {
|
|
4157
|
-
time: TimeSpan.fromMilliseconds(55),
|
|
4158
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
4159
|
-
});
|
|
4160
|
-
expect(handlerFn.mock.calls.length).toBeGreaterThan(1);
|
|
4161
|
-
});
|
|
4162
|
-
test("Should retry acquire the shared lock when blocked by a reader", async () => {
|
|
4163
|
-
const key = "a";
|
|
4164
|
-
const ttl = TimeSpan.fromMilliseconds(50);
|
|
4165
|
-
const limit = 1;
|
|
4166
|
-
const sharedLock1 = sharedLockProvider.create(key, {
|
|
4167
|
-
ttl,
|
|
4168
|
-
limit,
|
|
4169
|
-
});
|
|
4170
|
-
await sharedLock1.acquireReader();
|
|
4171
|
-
const handlerFn = vi.fn(() => { });
|
|
4172
|
-
await sharedLockProvider.addListener(SHARED_LOCK_EVENTS.UNAVAILABLE, handlerFn);
|
|
4173
|
-
const sharedLock2 = sharedLockProvider.create(key, {
|
|
4174
|
-
ttl,
|
|
4175
|
-
limit,
|
|
4176
|
-
});
|
|
4177
|
-
await sharedLock2.runReaderBlocking(() => {
|
|
2690
|
+
.runReaderOrFail(() => {
|
|
4178
2691
|
return Promise.resolve(RETURN_VALUE);
|
|
4179
|
-
}, {
|
|
4180
|
-
time: TimeSpan.fromMilliseconds(55),
|
|
4181
|
-
interval: TimeSpan.fromMilliseconds(5),
|
|
4182
2692
|
});
|
|
4183
|
-
expect(
|
|
2693
|
+
await expect(result).rejects.toBeInstanceOf(LimitReachedReaderSemaphoreError);
|
|
4184
2694
|
});
|
|
4185
2695
|
});
|
|
4186
2696
|
describe("method: runReaderBlockingOrFail", () => {
|