@daiso-tech/core 0.33.0 → 0.35.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 +66 -45
- package/dist/async/_module-exports.d.ts +1 -1
- package/dist/async/_module-exports.js +1 -1
- package/dist/async/_module-exports.js.map +1 -1
- package/dist/async/async.errors.d.ts +27 -19
- package/dist/async/async.errors.js +33 -20
- package/dist/async/async.errors.js.map +1 -1
- package/dist/async/backof-policies/_shared.d.ts +6 -2
- package/dist/async/backof-policies/_shared.js +1 -0
- package/dist/async/backof-policies/_shared.js.map +1 -1
- package/dist/async/backof-policies/constant-backoff-policy/constant-backoff-policy.d.ts +2 -2
- package/dist/async/backof-policies/constant-backoff-policy/constant-backoff-policy.js +1 -1
- package/dist/async/backof-policies/exponential-backoff-policy/exponential-backoff-policy.d.ts +2 -2
- package/dist/async/backof-policies/exponential-backoff-policy/exponential-backoff-policy.js +1 -1
- package/dist/async/backof-policies/linear-backoff-policy/linear-backoff-policy.d.ts +2 -2
- package/dist/async/backof-policies/linear-backoff-policy/linear-backoff-policy.js +1 -1
- package/dist/async/backof-policies/polynomial-backoff-policy/polynomial-backoff-policy.d.ts +2 -2
- package/dist/async/backof-policies/polynomial-backoff-policy/polynomial-backoff-policy.js +1 -1
- package/dist/async/middlewares/_module.d.ts +8 -0
- package/dist/async/middlewares/_module.js +9 -0
- package/dist/async/middlewares/_module.js.map +1 -0
- package/dist/async/middlewares/_shared.d.ts +10 -0
- package/dist/async/middlewares/_shared.js +5 -0
- package/dist/async/middlewares/_shared.js.map +1 -0
- package/dist/async/middlewares/bulkhead/_module.d.ts +1 -0
- package/dist/async/middlewares/bulkhead/_module.js +2 -0
- package/dist/async/middlewares/bulkhead/_module.js.map +1 -0
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.d.ts +80 -0
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.js +46 -0
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.js.map +1 -0
- package/dist/async/middlewares/dynamic/_module.d.ts +1 -0
- package/dist/async/middlewares/dynamic/_module.js +2 -0
- package/dist/async/middlewares/dynamic/_module.js.map +1 -0
- package/dist/async/middlewares/dynamic/dynamic.middleware.d.ts +34 -0
- package/dist/async/middlewares/dynamic/dynamic.middleware.js +36 -0
- package/dist/async/middlewares/dynamic/dynamic.middleware.js.map +1 -0
- package/dist/async/middlewares/fallback/_module.d.ts +1 -0
- package/dist/async/middlewares/fallback/_module.js +2 -0
- package/dist/async/middlewares/fallback/_module.js.map +1 -0
- package/dist/async/middlewares/fallback/fallback.middleware.d.ts +78 -0
- package/dist/async/middlewares/fallback/fallback.middleware.js +52 -0
- package/dist/async/middlewares/fallback/fallback.middleware.js.map +1 -0
- package/dist/async/middlewares/hedging/_module.d.ts +2 -0
- package/dist/async/middlewares/hedging/_module.js +3 -0
- package/dist/async/middlewares/hedging/_module.js.map +1 -0
- package/dist/async/middlewares/hedging/_shared.d.ts +93 -0
- package/dist/async/middlewares/hedging/_shared.js +5 -0
- package/dist/async/middlewares/hedging/_shared.js.map +1 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/_module.d.ts +1 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/_module.js +2 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/_module.js.map +1 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.d.ts +51 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.js +138 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.js.map +1 -0
- package/dist/async/middlewares/hedging/sequential-hedging/_module.d.ts +1 -0
- package/dist/async/middlewares/hedging/sequential-hedging/_module.js +2 -0
- package/dist/async/middlewares/hedging/sequential-hedging/_module.js.map +1 -0
- package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.d.ts +51 -0
- package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.js +104 -0
- package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.js.map +1 -0
- package/dist/async/middlewares/observe/_module.d.ts +1 -0
- package/dist/async/middlewares/observe/_module.js +2 -0
- package/dist/async/middlewares/observe/_module.js.map +1 -0
- package/dist/async/middlewares/observe/observe.middleware.d.ts +130 -0
- package/dist/async/middlewares/observe/observe.middleware.js +80 -0
- package/dist/async/middlewares/observe/observe.middleware.js.map +1 -0
- package/dist/async/middlewares/retry/_module.d.ts +1 -0
- package/dist/async/middlewares/retry/_module.js +2 -0
- package/dist/async/middlewares/retry/_module.js.map +1 -0
- package/dist/async/middlewares/retry/retry.middleware.d.ts +117 -0
- package/dist/async/middlewares/retry/retry.middleware.js +82 -0
- package/dist/async/middlewares/retry/retry.middleware.js.map +1 -0
- package/dist/async/middlewares/timeout/_module.d.ts +1 -0
- package/dist/async/middlewares/timeout/_module.js +2 -0
- package/dist/async/middlewares/timeout/_module.js.map +1 -0
- package/dist/async/middlewares/timeout/timeout.middleware.d.ts +83 -0
- package/dist/async/middlewares/timeout/timeout.middleware.js +60 -0
- package/dist/async/middlewares/timeout/timeout.middleware.js.map +1 -0
- package/dist/async/utilities/_module.d.ts +3 -4
- package/dist/async/utilities/_module.js +3 -4
- package/dist/async/utilities/_module.js.map +1 -1
- package/dist/async/utilities/abort-and-fail/_module.d.ts +1 -0
- package/dist/async/utilities/abort-and-fail/_module.js +2 -0
- package/dist/async/utilities/abort-and-fail/_module.js.map +1 -0
- package/dist/async/utilities/abort-and-fail/abort-and-fail.d.ts +7 -0
- package/dist/async/utilities/{abort → abort-and-fail}/abort-and-fail.js +6 -6
- package/dist/async/utilities/abort-and-fail/abort-and-fail.js.map +1 -0
- package/dist/async/utilities/lazy-promise/lazy-promise.d.ts +37 -194
- package/dist/async/utilities/lazy-promise/lazy-promise.js +62 -359
- package/dist/async/utilities/lazy-promise/lazy-promise.js.map +1 -1
- package/dist/async/utilities/promise-queue/_module.d.ts +1 -0
- package/dist/async/utilities/promise-queue/_module.js +2 -0
- package/dist/async/utilities/promise-queue/_module.js.map +1 -0
- package/dist/async/utilities/promise-queue/promise-queue.d.ts +32 -0
- package/dist/async/utilities/promise-queue/promise-queue.js +107 -0
- package/dist/async/utilities/promise-queue/promise-queue.js.map +1 -0
- package/dist/async/utilities/timeout-and-fail/_module.d.ts +1 -0
- package/dist/async/utilities/timeout-and-fail/_module.js +2 -0
- package/dist/async/utilities/timeout-and-fail/_module.js.map +1 -0
- package/dist/async/utilities/timeout-and-fail/timeout-and-fail.d.ts +7 -0
- package/dist/async/utilities/timeout-and-fail/timeout-and-fail.js +19 -0
- package/dist/async/utilities/timeout-and-fail/timeout-and-fail.js.map +1 -0
- package/dist/cache/contracts/cache-adapter.contract.d.ts +14 -14
- package/dist/cache/contracts/cache-factory.contract.d.ts +3 -3
- package/dist/cache/contracts/cache.contract.d.ts +73 -73
- package/dist/cache/contracts/cache.errors.d.ts +7 -7
- package/dist/cache/contracts/cache.errors.js +7 -7
- package/dist/cache/contracts/cache.events.d.ts +54 -58
- package/dist/cache/contracts/cache.events.js +6 -104
- package/dist/cache/contracts/cache.events.js.map +1 -1
- package/dist/cache/contracts/database-cache-adapter.contract.d.ts +16 -16
- package/dist/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.d.ts +3 -3
- package/dist/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.js +2 -2
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.d.ts +3 -9
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js +3 -9
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.d.ts +4 -4
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js +3 -3
- 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 -2
- 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 +2 -2
- package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.d.ts +3 -3
- package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.js +2 -2
- package/dist/cache/implementations/derivables/cache/cache.d.ts +26 -27
- package/dist/cache/implementations/derivables/cache/cache.js +102 -91
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +5 -4
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +2 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.d.ts +3 -3
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js +2 -2
- package/dist/cache/implementations/test-utilities/cache.test-suite.d.ts +3 -3
- package/dist/cache/implementations/test-utilities/cache.test-suite.js +140 -149
- 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 +3 -3
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js +2 -2
- package/dist/collection/contracts/_shared/compartor.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/cross-join-result.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/ensure-map.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/ensure-record.type.d.ts +1 -1
- package/dist/collection/contracts/_shared/foreach.type.d.ts +2 -2
- package/dist/collection/contracts/_shared/map.type.d.ts +2 -2
- package/dist/collection/contracts/_shared/modifier.type.d.ts +2 -2
- package/dist/collection/contracts/_shared/predicate.type.d.ts +7 -7
- package/dist/collection/contracts/_shared/reduce.type.d.ts +2 -2
- package/dist/collection/contracts/_shared/tap.type.d.ts +2 -2
- package/dist/collection/contracts/_shared/transform.type.d.ts +2 -2
- package/dist/collection/contracts/async-collection.contract.d.ts +109 -198
- package/dist/collection/contracts/collection.contract.d.ts +103 -103
- package/dist/collection/contracts/collection.errors.d.ts +11 -11
- package/dist/collection/contracts/collection.errors.js +11 -11
- package/dist/collection/implementations/_shared.d.ts +8 -8
- package/dist/collection/implementations/_shared.js +8 -8
- package/dist/collection/implementations/async-iterable-collection/_shared/_module.d.ts +0 -4
- package/dist/collection/implementations/async-iterable-collection/_shared/_module.js +0 -4
- package/dist/collection/implementations/async-iterable-collection/_shared/_module.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-cross-join-iterable.js +21 -19
- package/dist/collection/implementations/async-iterable-collection/_shared/async-cross-join-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.d.ts +15 -19
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +15 -30
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/cross-join-iterable.d.ts +3 -3
- package/dist/collection/implementations/iterable-collection/_shared/cross-join-iterable.js +18 -20
- package/dist/collection/implementations/iterable-collection/_shared/cross-join-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/iterable-collection.d.ts +11 -12
- package/dist/collection/implementations/iterable-collection/iterable-collection.js +11 -12
- package/dist/collection/implementations/iterable-collection/iterable-collection.js.map +1 -1
- package/dist/collection/implementations/list-collection/list-collection.d.ts +11 -11
- package/dist/collection/implementations/list-collection/list-collection.js +24 -30
- package/dist/collection/implementations/list-collection/list-collection.js.map +1 -1
- package/dist/event-bus/contracts/_module-exports.d.ts +0 -1
- package/dist/event-bus/contracts/_module-exports.js +0 -1
- package/dist/event-bus/contracts/_module-exports.js.map +1 -1
- package/dist/event-bus/contracts/event-bus-adapter.contract.d.ts +13 -8
- package/dist/event-bus/contracts/event-bus-factory.contract.d.ts +6 -7
- package/dist/event-bus/contracts/event-bus-factory.contract.js.map +1 -1
- package/dist/event-bus/contracts/event-bus.contract.d.ts +30 -41
- package/dist/event-bus/contracts/event-bus.errors.d.ts +8 -8
- package/dist/event-bus/contracts/event-bus.errors.js +8 -8
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.d.ts +3 -3
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js +3 -3
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.d.ts +2 -2
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.js +2 -2
- 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 +2 -2
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +15 -15
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +32 -32
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.d.ts +17 -10
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +13 -6
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.d.ts +3 -5
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js +15 -22
- 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 +3 -5
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js +189 -209
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js.map +1 -1
- package/dist/lock/contracts/database-lock-adapter.contract.d.ts +9 -9
- package/dist/lock/contracts/lock-adapter.contract.d.ts +7 -7
- package/dist/lock/contracts/lock-provider-factory.contract.d.ts +4 -4
- package/dist/lock/contracts/lock-provider.contract.d.ts +14 -14
- package/dist/lock/contracts/lock.contract.d.ts +22 -22
- package/dist/lock/contracts/lock.errors.d.ts +10 -10
- package/dist/lock/contracts/lock.errors.js +10 -10
- package/dist/lock/contracts/lock.events.d.ts +45 -54
- package/dist/lock/contracts/lock.events.js +9 -91
- package/dist/lock/contracts/lock.events.js.map +1 -1
- package/dist/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.d.ts +5 -5
- package/dist/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.js +4 -4
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.d.ts +3 -3
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +3 -3
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.d.ts +5 -5
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +4 -4
- 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 -2
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.d.ts +3 -3
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +3 -3
- package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.d.ts +5 -5
- package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.js +4 -4
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +33 -33
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +30 -30
- 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 +2 -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 +3 -3
- package/dist/lock/implementations/derivables/lock-provider/lock.js +77 -58
- package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +5 -4
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +2 -1
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.d.ts +3 -3
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js +2 -2
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.d.ts +3 -3
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js +2 -2
- 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 +214 -214
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
- package/dist/serde/contracts/deserializer.contract.d.ts +2 -2
- package/dist/serde/contracts/flexible-serde-adapter.contract.d.ts +4 -4
- package/dist/serde/contracts/flexible-serde.contract.d.ts +8 -19
- package/dist/serde/contracts/serde.contract.d.ts +2 -2
- package/dist/serde/contracts/serde.errors.d.ts +4 -4
- package/dist/serde/contracts/serde.errors.js +4 -4
- package/dist/serde/contracts/serializable.contract.d.ts +2 -2
- package/dist/serde/contracts/serializer.contract.d.ts +2 -2
- package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.d.ts +2 -2
- package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.js +2 -2
- 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 +1 -1
- package/dist/serde/implementations/derivables/serde.d.ts +4 -35
- package/dist/serde/implementations/derivables/serde.js +2 -47
- package/dist/serde/implementations/derivables/serde.js.map +1 -1
- package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.d.ts +3 -3
- package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.js +2 -2
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.d.ts +3 -3
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.js +2 -2
- package/dist/utilities/classes/_module.d.ts +1 -1
- package/dist/utilities/classes/_module.js +1 -1
- package/dist/utilities/classes/_module.js.map +1 -1
- package/dist/utilities/classes/hooks/_module.d.ts +3 -0
- package/dist/utilities/classes/hooks/_module.js +4 -0
- package/dist/utilities/classes/hooks/_module.js.map +1 -0
- package/dist/utilities/classes/hooks/async-hooks.d.ts +209 -0
- package/dist/utilities/classes/hooks/async-hooks.js +145 -0
- package/dist/utilities/classes/hooks/async-hooks.js.map +1 -0
- package/dist/utilities/classes/hooks/hooks.d.ts +139 -0
- package/dist/utilities/classes/hooks/hooks.js +116 -0
- package/dist/utilities/classes/hooks/hooks.js.map +1 -0
- package/dist/utilities/classes/hooks/types.d.ts +9 -0
- package/dist/utilities/classes/hooks/types.js +5 -0
- package/dist/utilities/classes/hooks/types.js.map +1 -0
- package/dist/utilities/classes/key-prefixer/key-prefixer.d.ts +3 -3
- package/dist/utilities/classes/key-prefixer/key-prefixer.js +4 -4
- package/dist/utilities/classes/key-prefixer/key-prefixer.js.map +1 -1
- package/dist/utilities/classes/time-span/time-span.d.ts +5 -5
- package/dist/utilities/classes/time-span/time-span.js +5 -5
- package/dist/utilities/contracts/_module.d.ts +0 -1
- package/dist/utilities/contracts/_module.js +0 -1
- package/dist/utilities/contracts/_module.js.map +1 -1
- package/dist/utilities/contracts/deinitizable.contract.d.ts +1 -1
- package/dist/utilities/contracts/initizable.contract.d.ts +1 -1
- package/dist/utilities/contracts/prunable.contract.d.ts +1 -1
- package/dist/utilities/contracts/serialized-error.contract.d.ts +1 -1
- package/dist/utilities/contracts/sqlite-database.contract.d.ts +2 -2
- package/dist/utilities/errors.d.ts +5 -5
- package/dist/utilities/errors.js +5 -5
- package/dist/utilities/functions/factory.js +3 -3
- package/dist/utilities/functions/factory.js.map +1 -1
- package/dist/utilities/functions/invokable.d.ts +9 -5
- package/dist/utilities/functions/invokable.js +12 -2
- package/dist/utilities/functions/invokable.js.map +1 -1
- package/dist/utilities/functions/lazy.d.ts +5 -0
- package/dist/utilities/functions/lazy.js +12 -3
- package/dist/utilities/functions/lazy.js.map +1 -1
- package/dist/utilities/types/async-iterable-value.type.d.ts +1 -1
- package/dist/utilities/types/at-least-one.type.d.ts +1 -1
- package/dist/utilities/types/factory.type.d.ts +8 -8
- package/dist/utilities/types/invokable.type.d.ts +3 -3
- package/dist/utilities/types/items.type.d.ts +1 -1
- package/dist/utilities/types/lazy.type.d.ts +5 -5
- package/dist/utilities/types/none-func.type.d.ts +1 -1
- package/dist/utilities/types/one-or-more.type.d.ts +1 -1
- package/dist/utilities/types/promiseable.type.d.ts +1 -1
- package/dist/utilities/types/result.type.d.ts +1 -1
- package/package.json +22 -2
- package/dist/async/async.events.d.ts +0 -105
- package/dist/async/async.events.js +0 -82
- package/dist/async/async.events.js.map +0 -1
- package/dist/async/utilities/abort/_module.d.ts +0 -2
- package/dist/async/utilities/abort/_module.js +0 -3
- package/dist/async/utilities/abort/_module.js.map +0 -1
- package/dist/async/utilities/abort/abort-and-fail.d.ts +0 -4
- package/dist/async/utilities/abort/abort-and-fail.js.map +0 -1
- package/dist/async/utilities/abort/abort.d.ts +0 -9
- package/dist/async/utilities/abort/abort.js +0 -18
- package/dist/async/utilities/abort/abort.js.map +0 -1
- package/dist/async/utilities/delay/_module.d.ts +0 -1
- package/dist/async/utilities/delay/_module.js +0 -2
- package/dist/async/utilities/delay/_module.js.map +0 -1
- package/dist/async/utilities/delay/delay.d.ts +0 -10
- package/dist/async/utilities/delay/delay.js +0 -34
- package/dist/async/utilities/delay/delay.js.map +0 -1
- package/dist/async/utilities/retry/_module.d.ts +0 -2
- package/dist/async/utilities/retry/_module.js +0 -3
- package/dist/async/utilities/retry/_module.js.map +0 -1
- package/dist/async/utilities/retry/retry-or-fail.d.ts +0 -29
- package/dist/async/utilities/retry/retry-or-fail.js +0 -39
- package/dist/async/utilities/retry/retry-or-fail.js.map +0 -1
- package/dist/async/utilities/retry/retry.d.ts +0 -10
- package/dist/async/utilities/retry/retry.js +0 -21
- package/dist/async/utilities/retry/retry.js.map +0 -1
- package/dist/async/utilities/timeout/_module.d.ts +0 -2
- package/dist/async/utilities/timeout/_module.js +0 -3
- package/dist/async/utilities/timeout/_module.js.map +0 -1
- package/dist/async/utilities/timeout/timeout-and-fail.d.ts +0 -5
- package/dist/async/utilities/timeout/timeout-and-fail.js +0 -28
- package/dist/async/utilities/timeout/timeout-and-fail.js.map +0 -1
- package/dist/async/utilities/timeout/timeout.d.ts +0 -10
- package/dist/async/utilities/timeout/timeout.js +0 -21
- package/dist/async/utilities/timeout/timeout.js.map +0 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-delay-iterable.d.ts +0 -13
- package/dist/collection/implementations/async-iterable-collection/_shared/async-delay-iterable.js +0 -30
- package/dist/collection/implementations/async-iterable-collection/_shared/async-delay-iterable.js.map +0 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-retry-iterable.d.ts +0 -13
- package/dist/collection/implementations/async-iterable-collection/_shared/async-retry-iterable.js +0 -36
- package/dist/collection/implementations/async-iterable-collection/_shared/async-retry-iterable.js.map +0 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-abort-iterable.d.ts +0 -9
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-abort-iterable.js +0 -39
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-abort-iterable.js.map +0 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-timeout-iterable.d.ts +0 -13
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-timeout-iterable.js +0 -52
- package/dist/collection/implementations/async-iterable-collection/_shared/async-take-until-timeout-iterable.js.map +0 -1
- package/dist/event-bus/contracts/_shared.d.ts +0 -12
- package/dist/event-bus/contracts/_shared.js +0 -15
- package/dist/event-bus/contracts/_shared.js.map +0 -1
- package/dist/utilities/classes/sync-event-bus/_module.d.ts +0 -1
- package/dist/utilities/classes/sync-event-bus/_module.js +0 -2
- package/dist/utilities/classes/sync-event-bus/_module.js.map +0 -1
- package/dist/utilities/classes/sync-event-bus/sync-event-bus.d.ts +0 -16
- package/dist/utilities/classes/sync-event-bus/sync-event-bus.js +0 -53
- package/dist/utilities/classes/sync-event-bus/sync-event-bus.js.map +0 -1
- package/dist/utilities/contracts/sync-event-bus-listenable.d.ts +0 -13
- package/dist/utilities/contracts/sync-event-bus-listenable.js +0 -5
- package/dist/utilities/contracts/sync-event-bus-listenable.js.map +0 -1
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
* @module Lock
|
|
3
3
|
*/
|
|
4
4
|
import {} from "vitest";
|
|
5
|
-
import {
|
|
5
|
+
import { KeyAlreadyAcquiredLockError, UnownedRefreshLockError, UnownedReleaseLockError, LOCK_EVENTS, } from "../../../lock/contracts/_module-exports.js";
|
|
6
6
|
import {} from "../../../utilities/_module-exports.js";
|
|
7
7
|
import { TimeSpan } from "../../../utilities/_module-exports.js";
|
|
8
8
|
import { LazyPromise } from "../../../async/_module-exports.js";
|
|
9
9
|
import { NoOpSerdeAdapter } from "../../../serde/implementations/adapters/_module-exports.js";
|
|
10
10
|
import { Serde } from "../../../serde/implementations/derivables/_module-exports.js";
|
|
11
11
|
/**
|
|
12
|
-
* The
|
|
12
|
+
* The `lockProviderTestSuite` function simplifies the process of testing your custom implementation of {@link ILock | `ILock`} with `vitest`.
|
|
13
13
|
*
|
|
14
|
-
* IMPORT_PATH:
|
|
14
|
+
* IMPORT_PATH: `"@daiso-tech/core/lock/test-utilities"`
|
|
15
15
|
* @group Utilities
|
|
16
16
|
* @example
|
|
17
17
|
* ```ts
|
|
@@ -200,7 +200,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
200
200
|
});
|
|
201
201
|
await lock.acquire();
|
|
202
202
|
let index = 0;
|
|
203
|
-
await lockProvider.addListener(
|
|
203
|
+
await lockProvider.addListener(LOCK_EVENTS.NOT_AVAILABLE, (_event) => {
|
|
204
204
|
index++;
|
|
205
205
|
});
|
|
206
206
|
await lock.runBlocking(async () => {
|
|
@@ -267,7 +267,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
267
267
|
});
|
|
268
268
|
await lock.acquire();
|
|
269
269
|
let index = 0;
|
|
270
|
-
await lockProvider.addListener(
|
|
270
|
+
await lockProvider.addListener(LOCK_EVENTS.NOT_AVAILABLE, (_event) => {
|
|
271
271
|
index++;
|
|
272
272
|
});
|
|
273
273
|
try {
|
|
@@ -417,7 +417,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
417
417
|
});
|
|
418
418
|
await lock.acquire();
|
|
419
419
|
let index = 0;
|
|
420
|
-
await lockProvider.addListener(
|
|
420
|
+
await lockProvider.addListener(LOCK_EVENTS.NOT_AVAILABLE, (_event) => {
|
|
421
421
|
index++;
|
|
422
422
|
});
|
|
423
423
|
await lock.acquireBlocking({
|
|
@@ -494,7 +494,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
494
494
|
});
|
|
495
495
|
await lock.acquire();
|
|
496
496
|
let index = 0;
|
|
497
|
-
await lockProvider.addListener(
|
|
497
|
+
await lockProvider.addListener(LOCK_EVENTS.NOT_AVAILABLE, (_event) => {
|
|
498
498
|
index++;
|
|
499
499
|
});
|
|
500
500
|
try {
|
|
@@ -896,9 +896,9 @@ export function lockProviderTestSuite(settings) {
|
|
|
896
896
|
});
|
|
897
897
|
});
|
|
898
898
|
describe("Event tests:", () => {
|
|
899
|
-
describe("
|
|
899
|
+
describe("class: Lock", () => {
|
|
900
900
|
describe("method: run", () => {
|
|
901
|
-
test("Should dispatch
|
|
901
|
+
test("Should dispatch AcquiredLockEvent when lock is not acquired", async () => {
|
|
902
902
|
const key = "a";
|
|
903
903
|
const owner = "b";
|
|
904
904
|
const lock = lockProvider.create(key, {
|
|
@@ -906,19 +906,19 @@ export function lockProviderTestSuite(settings) {
|
|
|
906
906
|
ttl: TTL,
|
|
907
907
|
});
|
|
908
908
|
let event_ = null;
|
|
909
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
909
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.ACQUIRED, (event) => {
|
|
910
910
|
event_ = event;
|
|
911
911
|
});
|
|
912
912
|
await lock.run(async () => {
|
|
913
913
|
await LazyPromise.delay(DELAY_TIME);
|
|
914
914
|
});
|
|
915
915
|
await LazyPromise.delay(DELAY_TIME);
|
|
916
|
-
expect(event_?.
|
|
917
|
-
expect(event_?.
|
|
918
|
-
expect(event_?.
|
|
916
|
+
expect(event_?.key).toBe("a");
|
|
917
|
+
expect(event_?.owner).toBe(owner);
|
|
918
|
+
expect(event_?.ttl?.toMilliseconds()).toBe(TTL.toMilliseconds());
|
|
919
919
|
await unsubscribe();
|
|
920
920
|
});
|
|
921
|
-
test("Should dispatch
|
|
921
|
+
test("Should dispatch ReleasedLockEvent when lock is not acquired", async () => {
|
|
922
922
|
const key = "a";
|
|
923
923
|
const owner = "b";
|
|
924
924
|
const lock = lockProvider.create(key, {
|
|
@@ -926,18 +926,18 @@ export function lockProviderTestSuite(settings) {
|
|
|
926
926
|
ttl: TTL,
|
|
927
927
|
});
|
|
928
928
|
let event_ = null;
|
|
929
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
929
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.RELEASED, (event) => {
|
|
930
930
|
event_ = event;
|
|
931
931
|
});
|
|
932
932
|
await lock.run(async () => {
|
|
933
933
|
await LazyPromise.delay(DELAY_TIME);
|
|
934
934
|
});
|
|
935
935
|
await LazyPromise.delay(DELAY_TIME);
|
|
936
|
-
expect(event_?.
|
|
937
|
-
expect(event_?.
|
|
936
|
+
expect(event_?.key).toBe(key);
|
|
937
|
+
expect(event_?.owner).toBe(owner);
|
|
938
938
|
await unsubscribe();
|
|
939
939
|
});
|
|
940
|
-
test("Should dispatch
|
|
940
|
+
test("Should dispatch NotAvailableLockEvent when lock is acquired", async () => {
|
|
941
941
|
const key = "a";
|
|
942
942
|
const owner = "b";
|
|
943
943
|
const lock = lockProvider.create(key, {
|
|
@@ -945,20 +945,20 @@ export function lockProviderTestSuite(settings) {
|
|
|
945
945
|
});
|
|
946
946
|
let event_ = null;
|
|
947
947
|
await lock.acquire();
|
|
948
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
948
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.NOT_AVAILABLE, (event) => {
|
|
949
949
|
event_ = event;
|
|
950
950
|
});
|
|
951
951
|
await lock.run(async () => {
|
|
952
952
|
await LazyPromise.delay(DELAY_TIME);
|
|
953
953
|
});
|
|
954
954
|
await LazyPromise.delay(DELAY_TIME);
|
|
955
|
-
expect(event_?.
|
|
956
|
-
expect(event_?.
|
|
955
|
+
expect(event_?.key).toBe("a");
|
|
956
|
+
expect(event_?.owner).toBe(owner);
|
|
957
957
|
await unsubscribe();
|
|
958
958
|
});
|
|
959
959
|
});
|
|
960
960
|
describe("method: runBlocking", () => {
|
|
961
|
-
test("Should dispatch
|
|
961
|
+
test("Should dispatch AcquiredLockEvent when lock is not acquired", async () => {
|
|
962
962
|
const key = "a";
|
|
963
963
|
const owner = "b";
|
|
964
964
|
const lock = lockProvider.create(key, {
|
|
@@ -966,7 +966,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
966
966
|
ttl: TTL,
|
|
967
967
|
});
|
|
968
968
|
let event_ = null;
|
|
969
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
969
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.ACQUIRED, (event) => {
|
|
970
970
|
event_ = event;
|
|
971
971
|
});
|
|
972
972
|
await lock.runBlocking(async () => {
|
|
@@ -976,12 +976,12 @@ export function lockProviderTestSuite(settings) {
|
|
|
976
976
|
interval: TimeSpan.fromMilliseconds(5),
|
|
977
977
|
});
|
|
978
978
|
await LazyPromise.delay(DELAY_TIME);
|
|
979
|
-
expect(event_?.
|
|
980
|
-
expect(event_?.
|
|
981
|
-
expect(event_?.
|
|
979
|
+
expect(event_?.key).toBe("a");
|
|
980
|
+
expect(event_?.owner).toBe(owner);
|
|
981
|
+
expect(event_?.ttl?.toMilliseconds()).toBe(TTL.toMilliseconds());
|
|
982
982
|
await unsubscribe();
|
|
983
983
|
});
|
|
984
|
-
test("Should dispatch
|
|
984
|
+
test("Should dispatch ReleasedLockEvent when lock is not acquired", async () => {
|
|
985
985
|
const key = "a";
|
|
986
986
|
const owner = "b";
|
|
987
987
|
const lock = lockProvider.create(key, {
|
|
@@ -989,7 +989,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
989
989
|
ttl: TTL,
|
|
990
990
|
});
|
|
991
991
|
let event_ = null;
|
|
992
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
992
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.RELEASED, (event) => {
|
|
993
993
|
event_ = event;
|
|
994
994
|
});
|
|
995
995
|
await lock.runBlocking(async () => {
|
|
@@ -999,11 +999,11 @@ export function lockProviderTestSuite(settings) {
|
|
|
999
999
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1000
1000
|
});
|
|
1001
1001
|
await LazyPromise.delay(DELAY_TIME);
|
|
1002
|
-
expect(event_?.
|
|
1003
|
-
expect(event_?.
|
|
1002
|
+
expect(event_?.key).toBe(key);
|
|
1003
|
+
expect(event_?.owner).toBe(owner);
|
|
1004
1004
|
await unsubscribe();
|
|
1005
1005
|
});
|
|
1006
|
-
test("Should dispatch
|
|
1006
|
+
test("Should dispatch NotAvailableLockEvent when lock is acquired", async () => {
|
|
1007
1007
|
const key = "a";
|
|
1008
1008
|
const owner = "b";
|
|
1009
1009
|
const lock = lockProvider.create(key, {
|
|
@@ -1011,7 +1011,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
1011
1011
|
});
|
|
1012
1012
|
let event_ = null;
|
|
1013
1013
|
await lock.acquire();
|
|
1014
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1014
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.NOT_AVAILABLE, (event) => {
|
|
1015
1015
|
event_ = event;
|
|
1016
1016
|
});
|
|
1017
1017
|
await lock.runBlocking(async () => {
|
|
@@ -1021,13 +1021,13 @@ export function lockProviderTestSuite(settings) {
|
|
|
1021
1021
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1022
1022
|
});
|
|
1023
1023
|
await LazyPromise.delay(DELAY_TIME);
|
|
1024
|
-
expect(event_?.
|
|
1025
|
-
expect(event_?.
|
|
1024
|
+
expect(event_?.key).toBe("a");
|
|
1025
|
+
expect(event_?.owner).toBe(owner);
|
|
1026
1026
|
await unsubscribe();
|
|
1027
1027
|
});
|
|
1028
1028
|
});
|
|
1029
1029
|
describe("method: runOrFail", () => {
|
|
1030
|
-
test("Should dispatch
|
|
1030
|
+
test("Should dispatch AcquiredLockEvent when lock is not acquired", async () => {
|
|
1031
1031
|
const key = "a";
|
|
1032
1032
|
const owner = "b";
|
|
1033
1033
|
const lock = lockProvider.create(key, {
|
|
@@ -1035,19 +1035,19 @@ export function lockProviderTestSuite(settings) {
|
|
|
1035
1035
|
ttl: TTL,
|
|
1036
1036
|
});
|
|
1037
1037
|
let event_ = null;
|
|
1038
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1038
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.ACQUIRED, (event) => {
|
|
1039
1039
|
event_ = event;
|
|
1040
1040
|
});
|
|
1041
1041
|
await lock.runOrFail(async () => {
|
|
1042
1042
|
await LazyPromise.delay(DELAY_TIME);
|
|
1043
1043
|
});
|
|
1044
1044
|
await LazyPromise.delay(DELAY_TIME);
|
|
1045
|
-
expect(event_?.
|
|
1046
|
-
expect(event_?.
|
|
1047
|
-
expect(event_?.
|
|
1045
|
+
expect(event_?.key).toBe("a");
|
|
1046
|
+
expect(event_?.owner).toBe(owner);
|
|
1047
|
+
expect(event_?.ttl?.toMilliseconds()).toBe(TTL.toMilliseconds());
|
|
1048
1048
|
await unsubscribe();
|
|
1049
1049
|
});
|
|
1050
|
-
test("Should dispatch
|
|
1050
|
+
test("Should dispatch ReleasedLockEvent when lock is not acquired", async () => {
|
|
1051
1051
|
const key = "a";
|
|
1052
1052
|
const owner = "b";
|
|
1053
1053
|
const lock = lockProvider.create(key, {
|
|
@@ -1055,18 +1055,18 @@ export function lockProviderTestSuite(settings) {
|
|
|
1055
1055
|
ttl: TTL,
|
|
1056
1056
|
});
|
|
1057
1057
|
let event_ = null;
|
|
1058
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1058
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.RELEASED, (event) => {
|
|
1059
1059
|
event_ = event;
|
|
1060
1060
|
});
|
|
1061
1061
|
await lock.runOrFail(async () => {
|
|
1062
1062
|
await LazyPromise.delay(DELAY_TIME);
|
|
1063
1063
|
});
|
|
1064
1064
|
await LazyPromise.delay(DELAY_TIME);
|
|
1065
|
-
expect(event_?.
|
|
1066
|
-
expect(event_?.
|
|
1065
|
+
expect(event_?.key).toBe(key);
|
|
1066
|
+
expect(event_?.owner).toBe(owner);
|
|
1067
1067
|
await unsubscribe();
|
|
1068
1068
|
});
|
|
1069
|
-
test("Should dispatch
|
|
1069
|
+
test("Should dispatch NotAvailableLockEvent when lock is acquired", async () => {
|
|
1070
1070
|
const key = "a";
|
|
1071
1071
|
const owner = "b";
|
|
1072
1072
|
const lock = lockProvider.create(key, {
|
|
@@ -1074,7 +1074,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
1074
1074
|
});
|
|
1075
1075
|
let event_ = null;
|
|
1076
1076
|
await lock.acquire();
|
|
1077
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1077
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.NOT_AVAILABLE, (event) => {
|
|
1078
1078
|
event_ = event;
|
|
1079
1079
|
});
|
|
1080
1080
|
try {
|
|
@@ -1086,13 +1086,13 @@ export function lockProviderTestSuite(settings) {
|
|
|
1086
1086
|
catch {
|
|
1087
1087
|
/* Empty */
|
|
1088
1088
|
}
|
|
1089
|
-
expect(event_?.
|
|
1090
|
-
expect(event_?.
|
|
1089
|
+
expect(event_?.key).toBe("a");
|
|
1090
|
+
expect(event_?.owner).toBe(owner);
|
|
1091
1091
|
await unsubscribe();
|
|
1092
1092
|
});
|
|
1093
1093
|
});
|
|
1094
1094
|
describe("method: acquire", () => {
|
|
1095
|
-
test("Should dispatch
|
|
1095
|
+
test("Should dispatch AcquiredLockEvent when lock is not acquired", async () => {
|
|
1096
1096
|
const key = "a";
|
|
1097
1097
|
const owner = "b";
|
|
1098
1098
|
const lock = lockProvider.create(key, {
|
|
@@ -1100,17 +1100,17 @@ export function lockProviderTestSuite(settings) {
|
|
|
1100
1100
|
ttl: TTL,
|
|
1101
1101
|
});
|
|
1102
1102
|
let event_ = null;
|
|
1103
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1103
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.ACQUIRED, (event) => {
|
|
1104
1104
|
event_ = event;
|
|
1105
1105
|
});
|
|
1106
1106
|
await lock.acquire();
|
|
1107
1107
|
await LazyPromise.delay(DELAY_TIME);
|
|
1108
|
-
expect(event_?.
|
|
1109
|
-
expect(event_?.
|
|
1110
|
-
expect(event_?.
|
|
1108
|
+
expect(event_?.key).toBe("a");
|
|
1109
|
+
expect(event_?.owner).toBe(owner);
|
|
1110
|
+
expect(event_?.ttl?.toMilliseconds()).toBe(TTL.toMilliseconds());
|
|
1111
1111
|
await unsubscribe();
|
|
1112
1112
|
});
|
|
1113
|
-
test("Should dispatch
|
|
1113
|
+
test("Should dispatch NotAvailableLockEvent when lock is acquired", async () => {
|
|
1114
1114
|
const key = "a";
|
|
1115
1115
|
const owner = "b";
|
|
1116
1116
|
const lock = lockProvider.create(key, {
|
|
@@ -1118,18 +1118,18 @@ export function lockProviderTestSuite(settings) {
|
|
|
1118
1118
|
});
|
|
1119
1119
|
let event_ = null;
|
|
1120
1120
|
await lock.acquire();
|
|
1121
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1121
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.NOT_AVAILABLE, (event) => {
|
|
1122
1122
|
event_ = event;
|
|
1123
1123
|
});
|
|
1124
1124
|
await lock.acquire();
|
|
1125
1125
|
await LazyPromise.delay(DELAY_TIME);
|
|
1126
|
-
expect(event_?.
|
|
1127
|
-
expect(event_?.
|
|
1126
|
+
expect(event_?.key).toBe("a");
|
|
1127
|
+
expect(event_?.owner).toBe(owner);
|
|
1128
1128
|
await unsubscribe();
|
|
1129
1129
|
});
|
|
1130
1130
|
});
|
|
1131
1131
|
describe("method: acquireBlocking", () => {
|
|
1132
|
-
test("Should dispatch
|
|
1132
|
+
test("Should dispatch AcquiredLockEvent when lock is not acquired", async () => {
|
|
1133
1133
|
const key = "a";
|
|
1134
1134
|
const owner = "b";
|
|
1135
1135
|
const lock = lockProvider.create(key, {
|
|
@@ -1137,7 +1137,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
1137
1137
|
ttl: TTL,
|
|
1138
1138
|
});
|
|
1139
1139
|
let event_ = null;
|
|
1140
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1140
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.ACQUIRED, (event) => {
|
|
1141
1141
|
event_ = event;
|
|
1142
1142
|
});
|
|
1143
1143
|
await lock.acquireBlocking({
|
|
@@ -1145,12 +1145,12 @@ export function lockProviderTestSuite(settings) {
|
|
|
1145
1145
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1146
1146
|
});
|
|
1147
1147
|
await LazyPromise.delay(DELAY_TIME);
|
|
1148
|
-
expect(event_?.
|
|
1149
|
-
expect(event_?.
|
|
1150
|
-
expect(event_?.
|
|
1148
|
+
expect(event_?.key).toBe("a");
|
|
1149
|
+
expect(event_?.owner).toBe(owner);
|
|
1150
|
+
expect(event_?.ttl?.toMilliseconds()).toBe(TTL.toMilliseconds());
|
|
1151
1151
|
await unsubscribe();
|
|
1152
1152
|
});
|
|
1153
|
-
test("Should dispatch
|
|
1153
|
+
test("Should dispatch NotAvailableLockEvent when lock is acquired", async () => {
|
|
1154
1154
|
const key = "a";
|
|
1155
1155
|
const owner = "b";
|
|
1156
1156
|
const lock = lockProvider.create(key, {
|
|
@@ -1161,7 +1161,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
1161
1161
|
time: TimeSpan.fromMilliseconds(5),
|
|
1162
1162
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1163
1163
|
});
|
|
1164
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1164
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.NOT_AVAILABLE, (event) => {
|
|
1165
1165
|
event_ = event;
|
|
1166
1166
|
});
|
|
1167
1167
|
await lock.acquireBlocking({
|
|
@@ -1169,13 +1169,13 @@ export function lockProviderTestSuite(settings) {
|
|
|
1169
1169
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1170
1170
|
});
|
|
1171
1171
|
await LazyPromise.delay(DELAY_TIME);
|
|
1172
|
-
expect(event_?.
|
|
1173
|
-
expect(event_?.
|
|
1172
|
+
expect(event_?.key).toBe("a");
|
|
1173
|
+
expect(event_?.owner).toBe(owner);
|
|
1174
1174
|
await unsubscribe();
|
|
1175
1175
|
});
|
|
1176
1176
|
});
|
|
1177
1177
|
describe("method: acquireOrFail", () => {
|
|
1178
|
-
test("Should dispatch
|
|
1178
|
+
test("Should dispatch AcquiredLockEvent when lock is not acquired", async () => {
|
|
1179
1179
|
const key = "a";
|
|
1180
1180
|
const owner = "b";
|
|
1181
1181
|
const lock = lockProvider.create(key, {
|
|
@@ -1183,17 +1183,17 @@ export function lockProviderTestSuite(settings) {
|
|
|
1183
1183
|
ttl: TTL,
|
|
1184
1184
|
});
|
|
1185
1185
|
let event_ = null;
|
|
1186
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1186
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.ACQUIRED, (event) => {
|
|
1187
1187
|
event_ = event;
|
|
1188
1188
|
});
|
|
1189
1189
|
await lock.acquireOrFail();
|
|
1190
1190
|
await LazyPromise.delay(DELAY_TIME);
|
|
1191
|
-
expect(event_?.
|
|
1192
|
-
expect(event_?.
|
|
1193
|
-
expect(event_?.
|
|
1191
|
+
expect(event_?.key).toBe("a");
|
|
1192
|
+
expect(event_?.owner).toBe(owner);
|
|
1193
|
+
expect(event_?.ttl?.toMilliseconds()).toBe(TTL.toMilliseconds());
|
|
1194
1194
|
await unsubscribe();
|
|
1195
1195
|
});
|
|
1196
|
-
test("Should dispatch
|
|
1196
|
+
test("Should dispatch NotAvailableLockEvent when lock is acquired", async () => {
|
|
1197
1197
|
const key = "a";
|
|
1198
1198
|
const owner = "b";
|
|
1199
1199
|
const lock = lockProvider.create(key, {
|
|
@@ -1201,7 +1201,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
1201
1201
|
});
|
|
1202
1202
|
let event_ = null;
|
|
1203
1203
|
await lock.acquireOrFail();
|
|
1204
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1204
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.NOT_AVAILABLE, (event) => {
|
|
1205
1205
|
event_ = event;
|
|
1206
1206
|
});
|
|
1207
1207
|
try {
|
|
@@ -1211,13 +1211,13 @@ export function lockProviderTestSuite(settings) {
|
|
|
1211
1211
|
catch {
|
|
1212
1212
|
/* Empty */
|
|
1213
1213
|
}
|
|
1214
|
-
expect(event_?.
|
|
1215
|
-
expect(event_?.
|
|
1214
|
+
expect(event_?.key).toBe("a");
|
|
1215
|
+
expect(event_?.owner).toBe(owner);
|
|
1216
1216
|
await unsubscribe();
|
|
1217
1217
|
});
|
|
1218
1218
|
});
|
|
1219
1219
|
describe("method: release", () => {
|
|
1220
|
-
test("Should dispatch
|
|
1220
|
+
test("Should dispatch ReleasedLockEvent when released by same owner", async () => {
|
|
1221
1221
|
const key = "a";
|
|
1222
1222
|
const owner = "b";
|
|
1223
1223
|
const lock = lockProvider.create(key, {
|
|
@@ -1225,16 +1225,16 @@ export function lockProviderTestSuite(settings) {
|
|
|
1225
1225
|
});
|
|
1226
1226
|
await lock.acquire();
|
|
1227
1227
|
let event_ = null;
|
|
1228
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1228
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.RELEASED, (event) => {
|
|
1229
1229
|
event_ = event;
|
|
1230
1230
|
});
|
|
1231
1231
|
await lock.release();
|
|
1232
1232
|
await LazyPromise.delay(DELAY_TIME);
|
|
1233
|
-
expect(event_?.
|
|
1234
|
-
expect(event_?.
|
|
1233
|
+
expect(event_?.key).toBe(key);
|
|
1234
|
+
expect(event_?.owner).toBe(owner);
|
|
1235
1235
|
await unsubscribe();
|
|
1236
1236
|
});
|
|
1237
|
-
test("Should dispatch
|
|
1237
|
+
test("Should dispatch UnownedReleaseTryLockEvent when released by same owner", async () => {
|
|
1238
1238
|
const key = "a";
|
|
1239
1239
|
const owner1 = "b";
|
|
1240
1240
|
const lock1 = lockProvider.create(key, {
|
|
@@ -1246,18 +1246,18 @@ export function lockProviderTestSuite(settings) {
|
|
|
1246
1246
|
owner: owner2,
|
|
1247
1247
|
});
|
|
1248
1248
|
let event_ = null;
|
|
1249
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1249
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.UNOWNED_RELEASE_TRY, (event) => {
|
|
1250
1250
|
event_ = event;
|
|
1251
1251
|
});
|
|
1252
1252
|
await lock2.release();
|
|
1253
1253
|
await LazyPromise.delay(DELAY_TIME);
|
|
1254
|
-
expect(event_?.
|
|
1255
|
-
expect(event_?.
|
|
1254
|
+
expect(event_?.key).toBe(key);
|
|
1255
|
+
expect(event_?.owner).toBe(owner2);
|
|
1256
1256
|
await unsubscribe();
|
|
1257
1257
|
});
|
|
1258
1258
|
});
|
|
1259
1259
|
describe("method: releaseOrFail", () => {
|
|
1260
|
-
test("Should dispatch
|
|
1260
|
+
test("Should dispatch ReleasedLockEvent when released by same owner", async () => {
|
|
1261
1261
|
const key = "a";
|
|
1262
1262
|
const owner = "b";
|
|
1263
1263
|
const lock = lockProvider.create(key, {
|
|
@@ -1265,16 +1265,16 @@ export function lockProviderTestSuite(settings) {
|
|
|
1265
1265
|
});
|
|
1266
1266
|
await lock.acquire();
|
|
1267
1267
|
let event_ = null;
|
|
1268
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1268
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.RELEASED, (event) => {
|
|
1269
1269
|
event_ = event;
|
|
1270
1270
|
});
|
|
1271
1271
|
await lock.releaseOrFail();
|
|
1272
1272
|
await LazyPromise.delay(DELAY_TIME);
|
|
1273
|
-
expect(event_?.
|
|
1274
|
-
expect(event_?.
|
|
1273
|
+
expect(event_?.key).toBe(key);
|
|
1274
|
+
expect(event_?.owner).toBe(owner);
|
|
1275
1275
|
await unsubscribe();
|
|
1276
1276
|
});
|
|
1277
|
-
test("Should dispatch
|
|
1277
|
+
test("Should dispatch UnownedReleaseTryLockEvent when released by same owner", async () => {
|
|
1278
1278
|
const key = "a";
|
|
1279
1279
|
const owner1 = "b";
|
|
1280
1280
|
const lock1 = lockProvider.create(key, {
|
|
@@ -1286,7 +1286,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
1286
1286
|
owner: owner2,
|
|
1287
1287
|
});
|
|
1288
1288
|
let event_ = null;
|
|
1289
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1289
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.UNOWNED_RELEASE_TRY, (event) => {
|
|
1290
1290
|
event_ = event;
|
|
1291
1291
|
});
|
|
1292
1292
|
try {
|
|
@@ -1296,13 +1296,13 @@ export function lockProviderTestSuite(settings) {
|
|
|
1296
1296
|
catch {
|
|
1297
1297
|
/* Empty */
|
|
1298
1298
|
}
|
|
1299
|
-
expect(event_?.
|
|
1300
|
-
expect(event_?.
|
|
1299
|
+
expect(event_?.key).toBe(key);
|
|
1300
|
+
expect(event_?.owner).toBe(owner2);
|
|
1301
1301
|
await unsubscribe();
|
|
1302
1302
|
});
|
|
1303
1303
|
});
|
|
1304
1304
|
describe("method: forceRelease", () => {
|
|
1305
|
-
test("Should dispatch
|
|
1305
|
+
test("Should dispatch ForceReleasedLockEvent when lock forcefully released", async () => {
|
|
1306
1306
|
const key = "a";
|
|
1307
1307
|
const owner1 = "b";
|
|
1308
1308
|
const lock1 = lockProvider.create(key, {
|
|
@@ -1314,17 +1314,17 @@ export function lockProviderTestSuite(settings) {
|
|
|
1314
1314
|
owner: owner2,
|
|
1315
1315
|
});
|
|
1316
1316
|
let event_ = null;
|
|
1317
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1317
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.FORCE_RELEASED, (event) => {
|
|
1318
1318
|
event_ = event;
|
|
1319
1319
|
});
|
|
1320
1320
|
await lock2.forceRelease();
|
|
1321
1321
|
await LazyPromise.delay(DELAY_TIME);
|
|
1322
|
-
expect(event_?.
|
|
1322
|
+
expect(event_?.key).toBe(key);
|
|
1323
1323
|
await unsubscribe();
|
|
1324
1324
|
});
|
|
1325
1325
|
});
|
|
1326
1326
|
describe("method: refresh", () => {
|
|
1327
|
-
test("Should dispatch
|
|
1327
|
+
test("Should dispatch RefreshedLockEvent when refreshed by same owner", async () => {
|
|
1328
1328
|
const key = "a";
|
|
1329
1329
|
const owner = "b";
|
|
1330
1330
|
const lock = lockProvider.create(key, {
|
|
@@ -1333,19 +1333,19 @@ export function lockProviderTestSuite(settings) {
|
|
|
1333
1333
|
});
|
|
1334
1334
|
await lock.acquire();
|
|
1335
1335
|
let event_ = null;
|
|
1336
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1336
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.REFRESHED, (event) => {
|
|
1337
1337
|
event_ = event;
|
|
1338
1338
|
});
|
|
1339
1339
|
await LazyPromise.delay(TTL.divide(2));
|
|
1340
1340
|
const newTTL = TTL.multiply(2);
|
|
1341
1341
|
await lock.refresh(newTTL);
|
|
1342
1342
|
await LazyPromise.delay(DELAY_TIME);
|
|
1343
|
-
expect(event_?.
|
|
1344
|
-
expect(event_?.
|
|
1345
|
-
expect(event_?.
|
|
1343
|
+
expect(event_?.key).toBe(key);
|
|
1344
|
+
expect(event_?.owner).toBe(owner);
|
|
1345
|
+
expect(event_?.ttl.toMilliseconds()).toBe(newTTL.toMilliseconds());
|
|
1346
1346
|
await unsubscribe();
|
|
1347
1347
|
});
|
|
1348
|
-
test("Should dispatch
|
|
1348
|
+
test("Should dispatch UnownedRefreshTryLockEvent when refreshed by different owner", async () => {
|
|
1349
1349
|
const key = "a";
|
|
1350
1350
|
const owner1 = "b";
|
|
1351
1351
|
const lock1 = lockProvider.create(key, {
|
|
@@ -1358,20 +1358,20 @@ export function lockProviderTestSuite(settings) {
|
|
|
1358
1358
|
owner: owner2,
|
|
1359
1359
|
});
|
|
1360
1360
|
let event_ = null;
|
|
1361
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1361
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.UNOWNED_REFRESH_TRY, (event) => {
|
|
1362
1362
|
event_ = event;
|
|
1363
1363
|
});
|
|
1364
1364
|
await LazyPromise.delay(TTL.divide(2));
|
|
1365
1365
|
const newTTL = TTL.multiply(2);
|
|
1366
1366
|
await lock2.refresh(newTTL);
|
|
1367
1367
|
await LazyPromise.delay(DELAY_TIME);
|
|
1368
|
-
expect(event_?.
|
|
1369
|
-
expect(event_?.
|
|
1368
|
+
expect(event_?.key).toBe(key);
|
|
1369
|
+
expect(event_?.owner).toBe(owner2);
|
|
1370
1370
|
await unsubscribe();
|
|
1371
1371
|
});
|
|
1372
1372
|
});
|
|
1373
1373
|
describe("method: refreshOrFail", () => {
|
|
1374
|
-
test("Should dispatch
|
|
1374
|
+
test("Should dispatch RefreshedLockEvent when refreshed by same owner", async () => {
|
|
1375
1375
|
const key = "a";
|
|
1376
1376
|
const owner = "b";
|
|
1377
1377
|
const lock = lockProvider.create(key, {
|
|
@@ -1380,19 +1380,19 @@ export function lockProviderTestSuite(settings) {
|
|
|
1380
1380
|
});
|
|
1381
1381
|
await lock.acquire();
|
|
1382
1382
|
let event_ = null;
|
|
1383
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1383
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.REFRESHED, (event) => {
|
|
1384
1384
|
event_ = event;
|
|
1385
1385
|
});
|
|
1386
1386
|
await LazyPromise.delay(TTL.divide(2));
|
|
1387
1387
|
const newTTL = TTL.multiply(2);
|
|
1388
1388
|
await lock.refreshOrFail(newTTL);
|
|
1389
1389
|
await LazyPromise.delay(DELAY_TIME);
|
|
1390
|
-
expect(event_?.
|
|
1391
|
-
expect(event_?.
|
|
1392
|
-
expect(event_?.
|
|
1390
|
+
expect(event_?.key).toBe(key);
|
|
1391
|
+
expect(event_?.owner).toBe(owner);
|
|
1392
|
+
expect(event_?.ttl.toMilliseconds()).toBe(newTTL.toMilliseconds());
|
|
1393
1393
|
await unsubscribe();
|
|
1394
1394
|
});
|
|
1395
|
-
test("Should dispatch
|
|
1395
|
+
test("Should dispatch UnownedRefreshTryLockEvent when refreshed by different owner", async () => {
|
|
1396
1396
|
const key = "a";
|
|
1397
1397
|
const owner1 = "b";
|
|
1398
1398
|
const lock1 = lockProvider.create(key, {
|
|
@@ -1405,7 +1405,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
1405
1405
|
owner: owner2,
|
|
1406
1406
|
});
|
|
1407
1407
|
let event_ = null;
|
|
1408
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1408
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.UNOWNED_REFRESH_TRY, (event) => {
|
|
1409
1409
|
event_ = event;
|
|
1410
1410
|
});
|
|
1411
1411
|
await LazyPromise.delay(TTL.divide(2));
|
|
@@ -1417,15 +1417,15 @@ export function lockProviderTestSuite(settings) {
|
|
|
1417
1417
|
catch {
|
|
1418
1418
|
/* Empty */
|
|
1419
1419
|
}
|
|
1420
|
-
expect(event_?.
|
|
1421
|
-
expect(event_?.
|
|
1420
|
+
expect(event_?.key).toBe(key);
|
|
1421
|
+
expect(event_?.owner).toBe(owner2);
|
|
1422
1422
|
await unsubscribe();
|
|
1423
1423
|
});
|
|
1424
1424
|
});
|
|
1425
1425
|
});
|
|
1426
1426
|
describe("LockProvider:", () => {
|
|
1427
1427
|
describe("method: run", () => {
|
|
1428
|
-
test("Should dispatch
|
|
1428
|
+
test("Should dispatch AcquiredLockEvent when lock is not acquired", async () => {
|
|
1429
1429
|
const key = "a";
|
|
1430
1430
|
const owner = "b";
|
|
1431
1431
|
const lock = lockProvider.create(key, {
|
|
@@ -1433,19 +1433,19 @@ export function lockProviderTestSuite(settings) {
|
|
|
1433
1433
|
ttl: TTL,
|
|
1434
1434
|
});
|
|
1435
1435
|
let event_ = null;
|
|
1436
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1436
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.ACQUIRED, (event) => {
|
|
1437
1437
|
event_ = event;
|
|
1438
1438
|
});
|
|
1439
1439
|
await lock.run(async () => {
|
|
1440
1440
|
await LazyPromise.delay(DELAY_TIME);
|
|
1441
1441
|
});
|
|
1442
1442
|
await LazyPromise.delay(DELAY_TIME);
|
|
1443
|
-
expect(event_?.
|
|
1444
|
-
expect(event_?.
|
|
1445
|
-
expect(event_?.
|
|
1443
|
+
expect(event_?.key).toBe("a");
|
|
1444
|
+
expect(event_?.owner).toBe(owner);
|
|
1445
|
+
expect(event_?.ttl?.toMilliseconds()).toBe(TTL.toMilliseconds());
|
|
1446
1446
|
await unsubscribe();
|
|
1447
1447
|
});
|
|
1448
|
-
test("Should dispatch
|
|
1448
|
+
test("Should dispatch ReleasedLockEvent when lock is not acquired", async () => {
|
|
1449
1449
|
const key = "a";
|
|
1450
1450
|
const owner = "b";
|
|
1451
1451
|
const lock = lockProvider.create(key, {
|
|
@@ -1453,18 +1453,18 @@ export function lockProviderTestSuite(settings) {
|
|
|
1453
1453
|
ttl: TTL,
|
|
1454
1454
|
});
|
|
1455
1455
|
let event_ = null;
|
|
1456
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1456
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.RELEASED, (event) => {
|
|
1457
1457
|
event_ = event;
|
|
1458
1458
|
});
|
|
1459
1459
|
await lock.run(async () => {
|
|
1460
1460
|
await LazyPromise.delay(DELAY_TIME);
|
|
1461
1461
|
});
|
|
1462
1462
|
await LazyPromise.delay(DELAY_TIME);
|
|
1463
|
-
expect(event_?.
|
|
1464
|
-
expect(event_?.
|
|
1463
|
+
expect(event_?.key).toBe(key);
|
|
1464
|
+
expect(event_?.owner).toBe(owner);
|
|
1465
1465
|
await unsubscribe();
|
|
1466
1466
|
});
|
|
1467
|
-
test("Should dispatch
|
|
1467
|
+
test("Should dispatch NotAvailableLockEvent when lock is acquired", async () => {
|
|
1468
1468
|
const key = "a";
|
|
1469
1469
|
const owner = "b";
|
|
1470
1470
|
const lock = lockProvider.create(key, {
|
|
@@ -1472,20 +1472,20 @@ export function lockProviderTestSuite(settings) {
|
|
|
1472
1472
|
});
|
|
1473
1473
|
let event_ = null;
|
|
1474
1474
|
await lock.acquire();
|
|
1475
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1475
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.NOT_AVAILABLE, (event) => {
|
|
1476
1476
|
event_ = event;
|
|
1477
1477
|
});
|
|
1478
1478
|
await lock.run(async () => {
|
|
1479
1479
|
await LazyPromise.delay(DELAY_TIME);
|
|
1480
1480
|
});
|
|
1481
1481
|
await LazyPromise.delay(DELAY_TIME);
|
|
1482
|
-
expect(event_?.
|
|
1483
|
-
expect(event_?.
|
|
1482
|
+
expect(event_?.key).toBe("a");
|
|
1483
|
+
expect(event_?.owner).toBe(owner);
|
|
1484
1484
|
await unsubscribe();
|
|
1485
1485
|
});
|
|
1486
1486
|
});
|
|
1487
1487
|
describe("method: runBlocking", () => {
|
|
1488
|
-
test("Should dispatch
|
|
1488
|
+
test("Should dispatch AcquiredLockEvent when lock is not acquired", async () => {
|
|
1489
1489
|
const key = "a";
|
|
1490
1490
|
const owner = "b";
|
|
1491
1491
|
const lock = lockProvider.create(key, {
|
|
@@ -1493,7 +1493,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
1493
1493
|
ttl: TTL,
|
|
1494
1494
|
});
|
|
1495
1495
|
let event_ = null;
|
|
1496
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1496
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.ACQUIRED, (event) => {
|
|
1497
1497
|
event_ = event;
|
|
1498
1498
|
});
|
|
1499
1499
|
await lock.runBlocking(async () => {
|
|
@@ -1503,12 +1503,12 @@ export function lockProviderTestSuite(settings) {
|
|
|
1503
1503
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1504
1504
|
});
|
|
1505
1505
|
await LazyPromise.delay(DELAY_TIME);
|
|
1506
|
-
expect(event_?.
|
|
1507
|
-
expect(event_?.
|
|
1508
|
-
expect(event_?.
|
|
1506
|
+
expect(event_?.key).toBe("a");
|
|
1507
|
+
expect(event_?.owner).toBe(owner);
|
|
1508
|
+
expect(event_?.ttl?.toMilliseconds()).toBe(TTL.toMilliseconds());
|
|
1509
1509
|
await unsubscribe();
|
|
1510
1510
|
});
|
|
1511
|
-
test("Should dispatch
|
|
1511
|
+
test("Should dispatch ReleasedLockEvent when lock is not acquired", async () => {
|
|
1512
1512
|
const key = "a";
|
|
1513
1513
|
const owner = "b";
|
|
1514
1514
|
const lock = lockProvider.create(key, {
|
|
@@ -1516,7 +1516,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
1516
1516
|
ttl: TTL,
|
|
1517
1517
|
});
|
|
1518
1518
|
let event_ = null;
|
|
1519
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1519
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.RELEASED, (event) => {
|
|
1520
1520
|
event_ = event;
|
|
1521
1521
|
});
|
|
1522
1522
|
await lock.runBlocking(async () => {
|
|
@@ -1526,11 +1526,11 @@ export function lockProviderTestSuite(settings) {
|
|
|
1526
1526
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1527
1527
|
});
|
|
1528
1528
|
await LazyPromise.delay(DELAY_TIME);
|
|
1529
|
-
expect(event_?.
|
|
1530
|
-
expect(event_?.
|
|
1529
|
+
expect(event_?.key).toBe(key);
|
|
1530
|
+
expect(event_?.owner).toBe(owner);
|
|
1531
1531
|
await unsubscribe();
|
|
1532
1532
|
});
|
|
1533
|
-
test("Should dispatch
|
|
1533
|
+
test("Should dispatch NotAvailableLockEvent when lock is acquired", async () => {
|
|
1534
1534
|
const key = "a";
|
|
1535
1535
|
const owner = "b";
|
|
1536
1536
|
const lock = lockProvider.create(key, {
|
|
@@ -1538,7 +1538,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
1538
1538
|
});
|
|
1539
1539
|
let event_ = null;
|
|
1540
1540
|
await lock.acquire();
|
|
1541
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1541
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.NOT_AVAILABLE, (event) => {
|
|
1542
1542
|
event_ = event;
|
|
1543
1543
|
});
|
|
1544
1544
|
await lock.runBlocking(async () => {
|
|
@@ -1548,13 +1548,13 @@ export function lockProviderTestSuite(settings) {
|
|
|
1548
1548
|
interval: TimeSpan.fromMilliseconds(5),
|
|
1549
1549
|
});
|
|
1550
1550
|
await LazyPromise.delay(DELAY_TIME);
|
|
1551
|
-
expect(event_?.
|
|
1552
|
-
expect(event_?.
|
|
1551
|
+
expect(event_?.key).toBe("a");
|
|
1552
|
+
expect(event_?.owner).toBe(owner);
|
|
1553
1553
|
await unsubscribe();
|
|
1554
1554
|
});
|
|
1555
1555
|
});
|
|
1556
1556
|
describe("method: runOrFail", () => {
|
|
1557
|
-
test("Should dispatch
|
|
1557
|
+
test("Should dispatch AcquiredLockEvent when lock is not acquired", async () => {
|
|
1558
1558
|
const key = "a";
|
|
1559
1559
|
const owner = "b";
|
|
1560
1560
|
const lock = lockProvider.create(key, {
|
|
@@ -1562,19 +1562,19 @@ export function lockProviderTestSuite(settings) {
|
|
|
1562
1562
|
ttl: TTL,
|
|
1563
1563
|
});
|
|
1564
1564
|
let event_ = null;
|
|
1565
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1565
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.ACQUIRED, (event) => {
|
|
1566
1566
|
event_ = event;
|
|
1567
1567
|
});
|
|
1568
1568
|
await lock.runOrFail(async () => {
|
|
1569
1569
|
await LazyPromise.delay(DELAY_TIME);
|
|
1570
1570
|
});
|
|
1571
1571
|
await LazyPromise.delay(DELAY_TIME);
|
|
1572
|
-
expect(event_?.
|
|
1573
|
-
expect(event_?.
|
|
1574
|
-
expect(event_?.
|
|
1572
|
+
expect(event_?.key).toBe("a");
|
|
1573
|
+
expect(event_?.owner).toBe(owner);
|
|
1574
|
+
expect(event_?.ttl?.toMilliseconds()).toBe(TTL.toMilliseconds());
|
|
1575
1575
|
await unsubscribe();
|
|
1576
1576
|
});
|
|
1577
|
-
test("Should dispatch
|
|
1577
|
+
test("Should dispatch ReleasedLockEvent when lock is not acquired", async () => {
|
|
1578
1578
|
const key = "a";
|
|
1579
1579
|
const owner = "b";
|
|
1580
1580
|
const lock = lockProvider.create(key, {
|
|
@@ -1582,18 +1582,18 @@ export function lockProviderTestSuite(settings) {
|
|
|
1582
1582
|
ttl: TTL,
|
|
1583
1583
|
});
|
|
1584
1584
|
let event_ = null;
|
|
1585
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1585
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.RELEASED, (event) => {
|
|
1586
1586
|
event_ = event;
|
|
1587
1587
|
});
|
|
1588
1588
|
await lock.runOrFail(async () => {
|
|
1589
1589
|
await LazyPromise.delay(DELAY_TIME);
|
|
1590
1590
|
});
|
|
1591
1591
|
await LazyPromise.delay(DELAY_TIME);
|
|
1592
|
-
expect(event_?.
|
|
1593
|
-
expect(event_?.
|
|
1592
|
+
expect(event_?.key).toBe(key);
|
|
1593
|
+
expect(event_?.owner).toBe(owner);
|
|
1594
1594
|
await unsubscribe();
|
|
1595
1595
|
});
|
|
1596
|
-
test("Should dispatch
|
|
1596
|
+
test("Should dispatch NotAvailableLockEvent when lock is acquired", async () => {
|
|
1597
1597
|
const key = "a";
|
|
1598
1598
|
const owner = "b";
|
|
1599
1599
|
const lock = lockProvider.create(key, {
|
|
@@ -1601,7 +1601,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
1601
1601
|
});
|
|
1602
1602
|
let event_ = null;
|
|
1603
1603
|
await lock.acquire();
|
|
1604
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1604
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.NOT_AVAILABLE, (event) => {
|
|
1605
1605
|
event_ = event;
|
|
1606
1606
|
});
|
|
1607
1607
|
try {
|
|
@@ -1613,13 +1613,13 @@ export function lockProviderTestSuite(settings) {
|
|
|
1613
1613
|
catch {
|
|
1614
1614
|
/* Empty */
|
|
1615
1615
|
}
|
|
1616
|
-
expect(event_?.
|
|
1617
|
-
expect(event_?.
|
|
1616
|
+
expect(event_?.key).toBe("a");
|
|
1617
|
+
expect(event_?.owner).toBe(owner);
|
|
1618
1618
|
await unsubscribe();
|
|
1619
1619
|
});
|
|
1620
1620
|
});
|
|
1621
1621
|
describe("method: acquire", () => {
|
|
1622
|
-
test("Should dispatch
|
|
1622
|
+
test("Should dispatch AcquiredLockEvent when lock is not acquired", async () => {
|
|
1623
1623
|
const key = "a";
|
|
1624
1624
|
const owner = "b";
|
|
1625
1625
|
const lock = lockProvider.create(key, {
|
|
@@ -1627,17 +1627,17 @@ export function lockProviderTestSuite(settings) {
|
|
|
1627
1627
|
ttl: TTL,
|
|
1628
1628
|
});
|
|
1629
1629
|
let event_ = null;
|
|
1630
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1630
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.ACQUIRED, (event) => {
|
|
1631
1631
|
event_ = event;
|
|
1632
1632
|
});
|
|
1633
1633
|
await lock.acquire();
|
|
1634
1634
|
await LazyPromise.delay(DELAY_TIME);
|
|
1635
|
-
expect(event_?.
|
|
1636
|
-
expect(event_?.
|
|
1637
|
-
expect(event_?.
|
|
1635
|
+
expect(event_?.key).toBe("a");
|
|
1636
|
+
expect(event_?.owner).toBe(owner);
|
|
1637
|
+
expect(event_?.ttl?.toMilliseconds()).toBe(TTL.toMilliseconds());
|
|
1638
1638
|
await unsubscribe();
|
|
1639
1639
|
});
|
|
1640
|
-
test("Should dispatch
|
|
1640
|
+
test("Should dispatch NotAvailableLockEvent when lock is acquired", async () => {
|
|
1641
1641
|
const key = "a";
|
|
1642
1642
|
const owner = "b";
|
|
1643
1643
|
const lock = lockProvider.create(key, {
|
|
@@ -1645,18 +1645,18 @@ export function lockProviderTestSuite(settings) {
|
|
|
1645
1645
|
});
|
|
1646
1646
|
let event_ = null;
|
|
1647
1647
|
await lock.acquire();
|
|
1648
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1648
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.NOT_AVAILABLE, (event) => {
|
|
1649
1649
|
event_ = event;
|
|
1650
1650
|
});
|
|
1651
1651
|
await lock.acquire();
|
|
1652
1652
|
await LazyPromise.delay(DELAY_TIME);
|
|
1653
|
-
expect(event_?.
|
|
1654
|
-
expect(event_?.
|
|
1653
|
+
expect(event_?.key).toBe("a");
|
|
1654
|
+
expect(event_?.owner).toBe(owner);
|
|
1655
1655
|
await unsubscribe();
|
|
1656
1656
|
});
|
|
1657
1657
|
});
|
|
1658
1658
|
describe("method: acquireBlocking", () => {
|
|
1659
|
-
test("Should dispatch
|
|
1659
|
+
test("Should dispatch AcquiredLockEvent when lock is not acquired", async () => {
|
|
1660
1660
|
const key = "a";
|
|
1661
1661
|
const owner = "b";
|
|
1662
1662
|
const lock = lockProvider.create(key, {
|
|
@@ -1664,17 +1664,17 @@ export function lockProviderTestSuite(settings) {
|
|
|
1664
1664
|
ttl: TTL,
|
|
1665
1665
|
});
|
|
1666
1666
|
let event_ = null;
|
|
1667
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1667
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.ACQUIRED, (event) => {
|
|
1668
1668
|
event_ = event;
|
|
1669
1669
|
});
|
|
1670
1670
|
await lock.acquire();
|
|
1671
1671
|
await LazyPromise.delay(DELAY_TIME);
|
|
1672
|
-
expect(event_?.
|
|
1673
|
-
expect(event_?.
|
|
1674
|
-
expect(event_?.
|
|
1672
|
+
expect(event_?.key).toBe("a");
|
|
1673
|
+
expect(event_?.owner).toBe(owner);
|
|
1674
|
+
expect(event_?.ttl?.toMilliseconds()).toBe(TTL.toMilliseconds());
|
|
1675
1675
|
await unsubscribe();
|
|
1676
1676
|
});
|
|
1677
|
-
test("Should dispatch
|
|
1677
|
+
test("Should dispatch NotAvailableLockEvent when lock is acquired", async () => {
|
|
1678
1678
|
const key = "a";
|
|
1679
1679
|
const owner = "b";
|
|
1680
1680
|
const lock = lockProvider.create(key, {
|
|
@@ -1682,18 +1682,18 @@ export function lockProviderTestSuite(settings) {
|
|
|
1682
1682
|
});
|
|
1683
1683
|
let event_ = null;
|
|
1684
1684
|
await lock.acquire();
|
|
1685
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1685
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.NOT_AVAILABLE, (event) => {
|
|
1686
1686
|
event_ = event;
|
|
1687
1687
|
});
|
|
1688
1688
|
await lock.acquire();
|
|
1689
1689
|
await LazyPromise.delay(DELAY_TIME);
|
|
1690
|
-
expect(event_?.
|
|
1691
|
-
expect(event_?.
|
|
1690
|
+
expect(event_?.key).toBe("a");
|
|
1691
|
+
expect(event_?.owner).toBe(owner);
|
|
1692
1692
|
await unsubscribe();
|
|
1693
1693
|
});
|
|
1694
1694
|
});
|
|
1695
1695
|
describe("method: acquireOrFail", () => {
|
|
1696
|
-
test("Should dispatch
|
|
1696
|
+
test("Should dispatch AcquiredLockEvent when lock is not acquired", async () => {
|
|
1697
1697
|
const key = "a";
|
|
1698
1698
|
const owner = "b";
|
|
1699
1699
|
const lock = lockProvider.create(key, {
|
|
@@ -1701,17 +1701,17 @@ export function lockProviderTestSuite(settings) {
|
|
|
1701
1701
|
ttl: TTL,
|
|
1702
1702
|
});
|
|
1703
1703
|
let event_ = null;
|
|
1704
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1704
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.ACQUIRED, (event) => {
|
|
1705
1705
|
event_ = event;
|
|
1706
1706
|
});
|
|
1707
1707
|
await lock.acquireOrFail();
|
|
1708
1708
|
await LazyPromise.delay(DELAY_TIME);
|
|
1709
|
-
expect(event_?.
|
|
1710
|
-
expect(event_?.
|
|
1711
|
-
expect(event_?.
|
|
1709
|
+
expect(event_?.key).toBe("a");
|
|
1710
|
+
expect(event_?.owner).toBe(owner);
|
|
1711
|
+
expect(event_?.ttl?.toMilliseconds()).toBe(TTL.toMilliseconds());
|
|
1712
1712
|
await unsubscribe();
|
|
1713
1713
|
});
|
|
1714
|
-
test("Should dispatch
|
|
1714
|
+
test("Should dispatch NotAvailableLockEvent when lock is acquired", async () => {
|
|
1715
1715
|
const key = "a";
|
|
1716
1716
|
const owner = "b";
|
|
1717
1717
|
const lock = lockProvider.create(key, {
|
|
@@ -1719,7 +1719,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
1719
1719
|
});
|
|
1720
1720
|
let event_ = null;
|
|
1721
1721
|
await lock.acquireOrFail();
|
|
1722
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1722
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.NOT_AVAILABLE, (event) => {
|
|
1723
1723
|
event_ = event;
|
|
1724
1724
|
});
|
|
1725
1725
|
try {
|
|
@@ -1729,13 +1729,13 @@ export function lockProviderTestSuite(settings) {
|
|
|
1729
1729
|
catch {
|
|
1730
1730
|
/* Empty */
|
|
1731
1731
|
}
|
|
1732
|
-
expect(event_?.
|
|
1733
|
-
expect(event_?.
|
|
1732
|
+
expect(event_?.key).toBe("a");
|
|
1733
|
+
expect(event_?.owner).toBe(owner);
|
|
1734
1734
|
await unsubscribe();
|
|
1735
1735
|
});
|
|
1736
1736
|
});
|
|
1737
1737
|
describe("method: release", () => {
|
|
1738
|
-
test("Should dispatch
|
|
1738
|
+
test("Should dispatch ReleasedLockEvent when released by same owner", async () => {
|
|
1739
1739
|
const key = "a";
|
|
1740
1740
|
const owner = "b";
|
|
1741
1741
|
const lock = lockProvider.create(key, {
|
|
@@ -1743,16 +1743,16 @@ export function lockProviderTestSuite(settings) {
|
|
|
1743
1743
|
});
|
|
1744
1744
|
await lock.acquire();
|
|
1745
1745
|
let event_ = null;
|
|
1746
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1746
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.RELEASED, (event) => {
|
|
1747
1747
|
event_ = event;
|
|
1748
1748
|
});
|
|
1749
1749
|
await lock.release();
|
|
1750
1750
|
await LazyPromise.delay(DELAY_TIME);
|
|
1751
|
-
expect(event_?.
|
|
1752
|
-
expect(event_?.
|
|
1751
|
+
expect(event_?.key).toBe(key);
|
|
1752
|
+
expect(event_?.owner).toBe(owner);
|
|
1753
1753
|
await unsubscribe();
|
|
1754
1754
|
});
|
|
1755
|
-
test("Should dispatch
|
|
1755
|
+
test("Should dispatch UnownedReleaseTryLockEvent when released by same owner", async () => {
|
|
1756
1756
|
const key = "a";
|
|
1757
1757
|
const owner1 = "b";
|
|
1758
1758
|
const lock1 = lockProvider.create(key, {
|
|
@@ -1764,18 +1764,18 @@ export function lockProviderTestSuite(settings) {
|
|
|
1764
1764
|
owner: owner2,
|
|
1765
1765
|
});
|
|
1766
1766
|
let event_ = null;
|
|
1767
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1767
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.UNOWNED_RELEASE_TRY, (event) => {
|
|
1768
1768
|
event_ = event;
|
|
1769
1769
|
});
|
|
1770
1770
|
await lock2.release();
|
|
1771
1771
|
await LazyPromise.delay(DELAY_TIME);
|
|
1772
|
-
expect(event_?.
|
|
1773
|
-
expect(event_?.
|
|
1772
|
+
expect(event_?.key).toBe(key);
|
|
1773
|
+
expect(event_?.owner).toBe(owner2);
|
|
1774
1774
|
await unsubscribe();
|
|
1775
1775
|
});
|
|
1776
1776
|
});
|
|
1777
1777
|
describe("method: releaseOrFail", () => {
|
|
1778
|
-
test("Should dispatch
|
|
1778
|
+
test("Should dispatch ReleasedLockEvent when released by same owner", async () => {
|
|
1779
1779
|
const key = "a";
|
|
1780
1780
|
const owner = "b";
|
|
1781
1781
|
const lock = lockProvider.create(key, {
|
|
@@ -1783,16 +1783,16 @@ export function lockProviderTestSuite(settings) {
|
|
|
1783
1783
|
});
|
|
1784
1784
|
await lock.acquire();
|
|
1785
1785
|
let event_ = null;
|
|
1786
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1786
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.RELEASED, (event) => {
|
|
1787
1787
|
event_ = event;
|
|
1788
1788
|
});
|
|
1789
1789
|
await lock.releaseOrFail();
|
|
1790
1790
|
await LazyPromise.delay(DELAY_TIME);
|
|
1791
|
-
expect(event_?.
|
|
1792
|
-
expect(event_?.
|
|
1791
|
+
expect(event_?.key).toBe(key);
|
|
1792
|
+
expect(event_?.owner).toBe(owner);
|
|
1793
1793
|
await unsubscribe();
|
|
1794
1794
|
});
|
|
1795
|
-
test("Should dispatch
|
|
1795
|
+
test("Should dispatch UnownedReleaseTryLockEvent when released by same owner", async () => {
|
|
1796
1796
|
const key = "a";
|
|
1797
1797
|
const owner1 = "b";
|
|
1798
1798
|
const lock1 = lockProvider.create(key, {
|
|
@@ -1804,7 +1804,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
1804
1804
|
owner: owner2,
|
|
1805
1805
|
});
|
|
1806
1806
|
let event_ = null;
|
|
1807
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1807
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.UNOWNED_RELEASE_TRY, (event) => {
|
|
1808
1808
|
event_ = event;
|
|
1809
1809
|
});
|
|
1810
1810
|
try {
|
|
@@ -1814,13 +1814,13 @@ export function lockProviderTestSuite(settings) {
|
|
|
1814
1814
|
catch {
|
|
1815
1815
|
/* Empty */
|
|
1816
1816
|
}
|
|
1817
|
-
expect(event_?.
|
|
1818
|
-
expect(event_?.
|
|
1817
|
+
expect(event_?.key).toBe(key);
|
|
1818
|
+
expect(event_?.owner).toBe(owner2);
|
|
1819
1819
|
await unsubscribe();
|
|
1820
1820
|
});
|
|
1821
1821
|
});
|
|
1822
1822
|
describe("method: forceRelease", () => {
|
|
1823
|
-
test("Should dispatch
|
|
1823
|
+
test("Should dispatch ForceReleasedLockEvent when lock forcefully released", async () => {
|
|
1824
1824
|
const key = "a";
|
|
1825
1825
|
const owner1 = "b";
|
|
1826
1826
|
const lock1 = lockProvider.create(key, {
|
|
@@ -1832,17 +1832,17 @@ export function lockProviderTestSuite(settings) {
|
|
|
1832
1832
|
owner: owner2,
|
|
1833
1833
|
});
|
|
1834
1834
|
let event_ = null;
|
|
1835
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1835
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.FORCE_RELEASED, (event) => {
|
|
1836
1836
|
event_ = event;
|
|
1837
1837
|
});
|
|
1838
1838
|
await lock2.forceRelease();
|
|
1839
1839
|
await LazyPromise.delay(DELAY_TIME);
|
|
1840
|
-
expect(event_?.
|
|
1840
|
+
expect(event_?.key).toBe(key);
|
|
1841
1841
|
await unsubscribe();
|
|
1842
1842
|
});
|
|
1843
1843
|
});
|
|
1844
1844
|
describe("method: refresh", () => {
|
|
1845
|
-
test("Should dispatch
|
|
1845
|
+
test("Should dispatch RefreshedLockEvent when refreshed by same owner", async () => {
|
|
1846
1846
|
const key = "a";
|
|
1847
1847
|
const owner = "b";
|
|
1848
1848
|
const lock = lockProvider.create(key, {
|
|
@@ -1851,19 +1851,19 @@ export function lockProviderTestSuite(settings) {
|
|
|
1851
1851
|
});
|
|
1852
1852
|
await lock.acquire();
|
|
1853
1853
|
let event_ = null;
|
|
1854
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1854
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.REFRESHED, (event) => {
|
|
1855
1855
|
event_ = event;
|
|
1856
1856
|
});
|
|
1857
1857
|
await LazyPromise.delay(TTL.divide(2));
|
|
1858
1858
|
const newTTL = TTL.multiply(2);
|
|
1859
1859
|
await lock.refresh(newTTL);
|
|
1860
1860
|
await LazyPromise.delay(DELAY_TIME);
|
|
1861
|
-
expect(event_?.
|
|
1862
|
-
expect(event_?.
|
|
1863
|
-
expect(event_?.
|
|
1861
|
+
expect(event_?.key).toBe(key);
|
|
1862
|
+
expect(event_?.owner).toBe(owner);
|
|
1863
|
+
expect(event_?.ttl.toMilliseconds()).toBe(newTTL.toMilliseconds());
|
|
1864
1864
|
await unsubscribe();
|
|
1865
1865
|
});
|
|
1866
|
-
test("Should dispatch
|
|
1866
|
+
test("Should dispatch UnownedRefreshTryLockEvent when refreshed by different owner", async () => {
|
|
1867
1867
|
const key = "a";
|
|
1868
1868
|
const owner1 = "b";
|
|
1869
1869
|
const lock1 = lockProvider.create(key, {
|
|
@@ -1876,20 +1876,20 @@ export function lockProviderTestSuite(settings) {
|
|
|
1876
1876
|
owner: owner2,
|
|
1877
1877
|
});
|
|
1878
1878
|
let event_ = null;
|
|
1879
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1879
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.UNOWNED_REFRESH_TRY, (event) => {
|
|
1880
1880
|
event_ = event;
|
|
1881
1881
|
});
|
|
1882
1882
|
await LazyPromise.delay(TTL.divide(2));
|
|
1883
1883
|
const newTTL = TTL.multiply(2);
|
|
1884
1884
|
await lock2.refresh(newTTL);
|
|
1885
1885
|
await LazyPromise.delay(DELAY_TIME);
|
|
1886
|
-
expect(event_?.
|
|
1887
|
-
expect(event_?.
|
|
1886
|
+
expect(event_?.key).toBe(key);
|
|
1887
|
+
expect(event_?.owner).toBe(owner2);
|
|
1888
1888
|
await unsubscribe();
|
|
1889
1889
|
});
|
|
1890
1890
|
});
|
|
1891
1891
|
describe("method: refreshOrFail", () => {
|
|
1892
|
-
test("Should dispatch
|
|
1892
|
+
test("Should dispatch RefreshedLockEvent when refreshed by same owner", async () => {
|
|
1893
1893
|
const key = "a";
|
|
1894
1894
|
const owner = "b";
|
|
1895
1895
|
const lock = lockProvider.create(key, {
|
|
@@ -1898,19 +1898,19 @@ export function lockProviderTestSuite(settings) {
|
|
|
1898
1898
|
});
|
|
1899
1899
|
await lock.acquire();
|
|
1900
1900
|
let event_ = null;
|
|
1901
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1901
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.REFRESHED, (event) => {
|
|
1902
1902
|
event_ = event;
|
|
1903
1903
|
});
|
|
1904
1904
|
await LazyPromise.delay(TTL.divide(2));
|
|
1905
1905
|
const newTTL = TTL.multiply(2);
|
|
1906
1906
|
await lock.refreshOrFail(newTTL);
|
|
1907
1907
|
await LazyPromise.delay(DELAY_TIME);
|
|
1908
|
-
expect(event_?.
|
|
1909
|
-
expect(event_?.
|
|
1910
|
-
expect(event_?.
|
|
1908
|
+
expect(event_?.key).toBe(key);
|
|
1909
|
+
expect(event_?.owner).toBe(owner);
|
|
1910
|
+
expect(event_?.ttl.toMilliseconds()).toBe(newTTL.toMilliseconds());
|
|
1911
1911
|
await unsubscribe();
|
|
1912
1912
|
});
|
|
1913
|
-
test("Should dispatch
|
|
1913
|
+
test("Should dispatch UnownedRefreshTryLockEvent when refreshed by different owner", async () => {
|
|
1914
1914
|
const key = "a";
|
|
1915
1915
|
const owner1 = "b";
|
|
1916
1916
|
const lock1 = lockProvider.create(key, {
|
|
@@ -1923,7 +1923,7 @@ export function lockProviderTestSuite(settings) {
|
|
|
1923
1923
|
owner: owner2,
|
|
1924
1924
|
});
|
|
1925
1925
|
let event_ = null;
|
|
1926
|
-
const unsubscribe = await lockProvider.subscribe(
|
|
1926
|
+
const unsubscribe = await lockProvider.subscribe(LOCK_EVENTS.UNOWNED_REFRESH_TRY, (event) => {
|
|
1927
1927
|
event_ = event;
|
|
1928
1928
|
});
|
|
1929
1929
|
await LazyPromise.delay(TTL.divide(2));
|
|
@@ -1935,8 +1935,8 @@ export function lockProviderTestSuite(settings) {
|
|
|
1935
1935
|
catch {
|
|
1936
1936
|
/* Empty */
|
|
1937
1937
|
}
|
|
1938
|
-
expect(event_?.
|
|
1939
|
-
expect(event_?.
|
|
1938
|
+
expect(event_?.key).toBe(key);
|
|
1939
|
+
expect(event_?.owner).toBe(owner2);
|
|
1940
1940
|
await unsubscribe();
|
|
1941
1941
|
});
|
|
1942
1942
|
});
|