@daiso-tech/core 0.22.2 → 0.23.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/dist/cjs/lock/contracts/lock.errors.js +4 -4
- package/dist/cjs/lock/contracts/lock.errors.js.map +1 -1
- package/dist/cjs/lock/implementations/_shared/lock-adapter.test-suite.js +0 -129
- package/dist/cjs/lock/implementations/_shared/lock-adapter.test-suite.js.map +1 -1
- package/dist/cjs/lock/implementations/_shared/lock-provider.test-suite.js +487 -489
- package/dist/cjs/lock/implementations/_shared/lock-provider.test-suite.js.map +1 -1
- package/dist/cjs/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js.map +1 -1
- package/dist/cjs/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.js.map +1 -1
- package/dist/cjs/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +0 -16
- package/dist/cjs/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js.map +1 -1
- package/dist/cjs/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +5 -5
- package/dist/cjs/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js.map +1 -1
- package/dist/cjs/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +0 -13
- package/dist/cjs/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js.map +1 -1
- package/dist/cjs/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.js.map +1 -1
- package/dist/cjs/lock/implementations/derivables/lock-provider/database-lock-adapter.js +0 -32
- package/dist/cjs/lock/implementations/derivables/lock-provider/database-lock-adapter.js.map +1 -1
- package/dist/cjs/lock/implementations/derivables/lock-provider/lock-provider.js +22 -12
- package/dist/cjs/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/cjs/lock/implementations/derivables/lock-provider/lock-state.js +58 -0
- package/dist/cjs/lock/implementations/derivables/lock-provider/lock-state.js.map +1 -0
- package/dist/cjs/lock/implementations/derivables/lock-provider/lock.js +32 -39
- package/dist/cjs/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
- package/dist/cjs/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +1 -1
- package/dist/cjs/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
- package/dist/cjs/utilities/contracts/_module.js +0 -1
- package/dist/cjs/utilities/contracts/_module.js.map +1 -1
- package/dist/esm/lock/contracts/lock.errors.js +2 -2
- package/dist/esm/lock/contracts/lock.errors.js.map +1 -1
- package/dist/esm/lock/implementations/_shared/lock-adapter.test-suite.js +0 -129
- package/dist/esm/lock/implementations/_shared/lock-adapter.test-suite.js.map +1 -1
- package/dist/esm/lock/implementations/_shared/lock-provider.test-suite.js +488 -490
- package/dist/esm/lock/implementations/_shared/lock-provider.test-suite.js.map +1 -1
- package/dist/esm/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js +1 -1
- package/dist/esm/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js.map +1 -1
- package/dist/esm/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.js +1 -1
- package/dist/esm/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.js.map +1 -1
- package/dist/esm/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +1 -17
- package/dist/esm/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js.map +1 -1
- package/dist/esm/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +6 -6
- package/dist/esm/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js.map +1 -1
- package/dist/esm/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +1 -14
- package/dist/esm/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js.map +1 -1
- package/dist/esm/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.js +1 -1
- package/dist/esm/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.js.map +1 -1
- package/dist/esm/lock/implementations/derivables/lock-provider/database-lock-adapter.js +1 -33
- package/dist/esm/lock/implementations/derivables/lock-provider/database-lock-adapter.js.map +1 -1
- package/dist/esm/lock/implementations/derivables/lock-provider/lock-provider.js +22 -12
- package/dist/esm/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/esm/lock/implementations/derivables/lock-provider/lock-state.js +54 -0
- package/dist/esm/lock/implementations/derivables/lock-provider/lock-state.js.map +1 -0
- package/dist/esm/lock/implementations/derivables/lock-provider/lock.js +33 -40
- package/dist/esm/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
- package/dist/esm/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +1 -1
- package/dist/esm/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
- package/dist/esm/utilities/contracts/_module.js +0 -1
- package/dist/esm/utilities/contracts/_module.js.map +1 -1
- package/dist/types/lock/contracts/database-lock-adapter.contract.d.ts +1 -2
- package/dist/types/lock/contracts/lock-adapter.contract.d.ts +0 -9
- package/dist/types/lock/contracts/lock.contract.d.ts +1 -1
- package/dist/types/lock/contracts/lock.errors.d.ts +2 -2
- package/dist/types/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.d.ts +2 -2
- package/dist/types/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.d.ts +2 -2
- package/dist/types/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.d.ts +1 -3
- package/dist/types/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.d.ts +2 -1
- package/dist/types/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.d.ts +1 -3
- package/dist/types/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.d.ts +2 -2
- package/dist/types/lock/implementations/derivables/lock-provider/database-lock-adapter.d.ts +2 -7
- package/dist/types/lock/implementations/derivables/lock-provider/lock-provider.d.ts +8 -10
- package/dist/types/lock/implementations/derivables/lock-provider/lock-state.d.ts +40 -0
- package/dist/types/lock/implementations/derivables/lock-provider/lock.d.ts +8 -2
- package/dist/types/utilities/contracts/_module.d.ts +0 -1
- package/package.json +1 -1
- package/dist/cjs/utilities/contracts/serde-registrable.contract.js +0 -3
- package/dist/cjs/utilities/contracts/serde-registrable.contract.js.map +0 -1
- package/dist/esm/utilities/contracts/serde-registrable.contract.js +0 -1
- package/dist/esm/utilities/contracts/serde-registrable.contract.js.map +0 -1
- package/dist/types/utilities/contracts/serde-registrable.contract.d.ts +0 -11
|
@@ -16,538 +16,536 @@ function lockProviderTestSuite(settings) {
|
|
|
16
16
|
});
|
|
17
17
|
const TTL = _module_2.TimeSpan.fromMilliseconds(50);
|
|
18
18
|
describe("Api tests:", () => {
|
|
19
|
-
describe("
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
ttl,
|
|
26
|
-
});
|
|
27
|
-
const [result, error] = await lock.run(async () => {
|
|
28
|
-
await (0, _module_3.delay)(TTL);
|
|
29
|
-
return "a";
|
|
30
|
-
});
|
|
31
|
-
expect(result).toBe("a");
|
|
32
|
-
expect(error).toBeNull();
|
|
33
|
-
});
|
|
34
|
-
test("Should return null when lock is already acquired", async () => {
|
|
35
|
-
const key = "a";
|
|
36
|
-
const ttl = null;
|
|
37
|
-
const lock = lockProviderA.create(key, {
|
|
38
|
-
ttl,
|
|
39
|
-
});
|
|
40
|
-
await lock.acquire();
|
|
41
|
-
const [result, error] = await lock.run(async () => {
|
|
42
|
-
await (0, _module_3.delay)(TTL);
|
|
43
|
-
return "a";
|
|
44
|
-
});
|
|
45
|
-
expect(result).toBeNull();
|
|
46
|
-
expect(error).toBeInstanceOf(_module_1.KeyAlreadyAcquiredLockError);
|
|
19
|
+
describe("method: run", () => {
|
|
20
|
+
test("Should return string when lock is available", async () => {
|
|
21
|
+
const key = "a";
|
|
22
|
+
const ttl = null;
|
|
23
|
+
const lock = lockProviderA.create(key, {
|
|
24
|
+
ttl,
|
|
47
25
|
});
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const lock = lockProviderA.create(key, {
|
|
52
|
-
ttl,
|
|
53
|
-
});
|
|
54
|
-
const [result, error] = await lock.run(new _module_3.LazyPromise(async () => {
|
|
55
|
-
await (0, _module_3.delay)(TTL);
|
|
56
|
-
return "a";
|
|
57
|
-
}));
|
|
58
|
-
expect(result).toBe("a");
|
|
59
|
-
expect(error).toBeNull();
|
|
26
|
+
const [result, error] = await lock.run(async () => {
|
|
27
|
+
await (0, _module_3.delay)(TTL);
|
|
28
|
+
return "a";
|
|
60
29
|
});
|
|
30
|
+
expect(result).toBe("a");
|
|
31
|
+
expect(error).toBeNull();
|
|
61
32
|
});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
ttl,
|
|
68
|
-
});
|
|
69
|
-
const result = await lock.runOrFail(async () => {
|
|
70
|
-
await (0, _module_3.delay)(TTL);
|
|
71
|
-
return "a";
|
|
72
|
-
});
|
|
73
|
-
expect(result).toBe("a");
|
|
74
|
-
});
|
|
75
|
-
test("Should throw KeyAlreadyAcquiredLockError when lock is already acquired", async () => {
|
|
76
|
-
const key = "a";
|
|
77
|
-
const ttl = null;
|
|
78
|
-
const lock = lockProviderA.create(key, {
|
|
79
|
-
ttl,
|
|
80
|
-
});
|
|
81
|
-
await lock.acquire();
|
|
82
|
-
const result = lock.runOrFail(async () => {
|
|
83
|
-
await (0, _module_3.delay)(TTL);
|
|
84
|
-
return "a";
|
|
85
|
-
});
|
|
86
|
-
await expect(result).rejects.toBeInstanceOf(_module_1.KeyAlreadyAcquiredLockError);
|
|
33
|
+
test("Should return null when lock is already acquired", async () => {
|
|
34
|
+
const key = "a";
|
|
35
|
+
const ttl = null;
|
|
36
|
+
const lock = lockProviderA.create(key, {
|
|
37
|
+
ttl,
|
|
87
38
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
ttl,
|
|
93
|
-
});
|
|
94
|
-
const result = await lock.runOrFail(new _module_3.LazyPromise(async () => {
|
|
95
|
-
await (0, _module_3.delay)(TTL);
|
|
96
|
-
return "a";
|
|
97
|
-
}));
|
|
98
|
-
expect(result).toBe("a");
|
|
39
|
+
await lock.acquire();
|
|
40
|
+
const [result, error] = await lock.run(async () => {
|
|
41
|
+
await (0, _module_3.delay)(TTL);
|
|
42
|
+
return "a";
|
|
99
43
|
});
|
|
44
|
+
expect(result).toBeNull();
|
|
45
|
+
expect(error).toBeInstanceOf(_module_1.KeyAlreadyAcquiredLockError);
|
|
100
46
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
ttl,
|
|
107
|
-
});
|
|
108
|
-
const result = await lock.acquire();
|
|
109
|
-
expect(result).toBe(true);
|
|
110
|
-
});
|
|
111
|
-
test("Should return false when lock is already acquired", async () => {
|
|
112
|
-
const key = "a";
|
|
113
|
-
const ttl = null;
|
|
114
|
-
const lock = lockProviderA.create(key, {
|
|
115
|
-
ttl,
|
|
116
|
-
});
|
|
117
|
-
await lock.acquire();
|
|
118
|
-
const result = await lock.acquire();
|
|
119
|
-
expect(result).toBe(false);
|
|
120
|
-
});
|
|
121
|
-
test("Should not be expired when released by same owner", async () => {
|
|
122
|
-
const key = "a";
|
|
123
|
-
const ttl = null;
|
|
124
|
-
const owner = "b";
|
|
125
|
-
const lock = lockProviderA.create(key, {
|
|
126
|
-
ttl,
|
|
127
|
-
owner,
|
|
128
|
-
});
|
|
129
|
-
await lock.acquire();
|
|
130
|
-
const result = await lock.isExpired();
|
|
131
|
-
expect(result).toBe(false);
|
|
132
|
-
});
|
|
133
|
-
test("Should be loked when released by same owner", async () => {
|
|
134
|
-
const key = "a";
|
|
135
|
-
const ttl = null;
|
|
136
|
-
const owner = "b";
|
|
137
|
-
const lock = lockProviderA.create(key, {
|
|
138
|
-
ttl,
|
|
139
|
-
owner,
|
|
140
|
-
});
|
|
141
|
-
await lock.acquire();
|
|
142
|
-
const result = await lock.isLocked();
|
|
143
|
-
expect(result).toBe(true);
|
|
47
|
+
test("Should work with LazyPromise", async () => {
|
|
48
|
+
const key = "a";
|
|
49
|
+
const ttl = null;
|
|
50
|
+
const lock = lockProviderA.create(key, {
|
|
51
|
+
ttl,
|
|
144
52
|
});
|
|
53
|
+
const [result, error] = await lock.run(new _module_3.LazyPromise(async () => {
|
|
54
|
+
await (0, _module_3.delay)(TTL);
|
|
55
|
+
return "a";
|
|
56
|
+
}));
|
|
57
|
+
expect(result).toBe("a");
|
|
58
|
+
expect(error).toBeNull();
|
|
145
59
|
});
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const result = lock.acquireOrFail();
|
|
154
|
-
await expect(result).resolves.toBeUndefined();
|
|
60
|
+
});
|
|
61
|
+
describe("method: runOrFail", () => {
|
|
62
|
+
test("Should return string when lock is available", async () => {
|
|
63
|
+
const key = "a";
|
|
64
|
+
const ttl = null;
|
|
65
|
+
const lock = lockProviderA.create(key, {
|
|
66
|
+
ttl,
|
|
155
67
|
});
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const lock = lockProviderA.create(key, {
|
|
160
|
-
ttl,
|
|
161
|
-
});
|
|
162
|
-
await lock.acquireOrFail();
|
|
163
|
-
const result = lock.acquireOrFail();
|
|
164
|
-
await expect(result).rejects.toBeInstanceOf(_module_1.KeyAlreadyAcquiredLockError);
|
|
68
|
+
const result = await lock.runOrFail(async () => {
|
|
69
|
+
await (0, _module_3.delay)(TTL);
|
|
70
|
+
return "a";
|
|
165
71
|
});
|
|
72
|
+
expect(result).toBe("a");
|
|
166
73
|
});
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const lock = lockProviderA.create(key, {
|
|
173
|
-
ttl,
|
|
174
|
-
owner,
|
|
175
|
-
});
|
|
176
|
-
await lock.acquire();
|
|
177
|
-
const result = await lock.release();
|
|
178
|
-
expect(result).toBe(true);
|
|
179
|
-
});
|
|
180
|
-
test("Should return false when released by different owner", async () => {
|
|
181
|
-
const key = "a";
|
|
182
|
-
const ttl = null;
|
|
183
|
-
const owner1 = "b";
|
|
184
|
-
const lock1 = lockProviderA.create(key, {
|
|
185
|
-
ttl,
|
|
186
|
-
owner: owner1,
|
|
187
|
-
});
|
|
188
|
-
await lock1.acquire();
|
|
189
|
-
const owner2 = "c";
|
|
190
|
-
const lock2 = lockProviderA.create(key, {
|
|
191
|
-
ttl,
|
|
192
|
-
owner: owner2,
|
|
193
|
-
});
|
|
194
|
-
const result = await lock2.release();
|
|
195
|
-
expect(result).toBe(false);
|
|
196
|
-
});
|
|
197
|
-
test("Should be expired when released by same owner", async () => {
|
|
198
|
-
const key = "a";
|
|
199
|
-
const ttl = null;
|
|
200
|
-
const owner = "b";
|
|
201
|
-
const lock = lockProviderA.create(key, {
|
|
202
|
-
ttl,
|
|
203
|
-
owner,
|
|
204
|
-
});
|
|
205
|
-
await lock.acquire();
|
|
206
|
-
await lock.release();
|
|
207
|
-
const result = await lock.isExpired();
|
|
208
|
-
expect(result).toBe(true);
|
|
74
|
+
test("Should throw KeyAlreadyAcquiredLockError when lock is already acquired", async () => {
|
|
75
|
+
const key = "a";
|
|
76
|
+
const ttl = null;
|
|
77
|
+
const lock = lockProviderA.create(key, {
|
|
78
|
+
ttl,
|
|
209
79
|
});
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const lock = lockProviderA.create(key, {
|
|
215
|
-
ttl,
|
|
216
|
-
owner,
|
|
217
|
-
});
|
|
218
|
-
await lock.acquire();
|
|
219
|
-
await lock.release();
|
|
220
|
-
const result = await lock.isLocked();
|
|
221
|
-
expect(result).toBe(false);
|
|
80
|
+
await lock.acquire();
|
|
81
|
+
const result = lock.runOrFail(async () => {
|
|
82
|
+
await (0, _module_3.delay)(TTL);
|
|
83
|
+
return "a";
|
|
222
84
|
});
|
|
85
|
+
await expect(result).rejects.toBeInstanceOf(_module_1.KeyAlreadyAcquiredLockError);
|
|
223
86
|
});
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const lock = lockProviderA.create(key, {
|
|
230
|
-
ttl,
|
|
231
|
-
owner,
|
|
232
|
-
});
|
|
233
|
-
await lock.acquire();
|
|
234
|
-
const result = lock.releaseOrFail();
|
|
235
|
-
await expect(result).resolves.toBeUndefined();
|
|
236
|
-
});
|
|
237
|
-
test("Should throw UnownedReleaseLockError when released by different owner", async () => {
|
|
238
|
-
const key = "a";
|
|
239
|
-
const ttl = null;
|
|
240
|
-
const owner1 = "b";
|
|
241
|
-
const lock1 = lockProviderA.create(key, {
|
|
242
|
-
ttl,
|
|
243
|
-
owner: owner1,
|
|
244
|
-
});
|
|
245
|
-
await lock1.acquire();
|
|
246
|
-
const owner2 = "c";
|
|
247
|
-
const lock2 = lockProviderA.create(key, {
|
|
248
|
-
ttl,
|
|
249
|
-
owner: owner2,
|
|
250
|
-
});
|
|
251
|
-
const result = lock2.releaseOrFail();
|
|
252
|
-
await expect(result).rejects.toBeInstanceOf(_module_1.UnownedReleaseLockError);
|
|
253
|
-
});
|
|
254
|
-
test("Should be expired when released by same owner", async () => {
|
|
255
|
-
const key = "a";
|
|
256
|
-
const ttl = null;
|
|
257
|
-
const owner = "b";
|
|
258
|
-
const lock = lockProviderA.create(key, {
|
|
259
|
-
ttl,
|
|
260
|
-
owner,
|
|
261
|
-
});
|
|
262
|
-
await lock.acquire();
|
|
263
|
-
await lock.releaseOrFail();
|
|
264
|
-
const result = await lock.isExpired();
|
|
265
|
-
expect(result).toBe(true);
|
|
87
|
+
test("Should work with LazyPromise", async () => {
|
|
88
|
+
const key = "a";
|
|
89
|
+
const ttl = null;
|
|
90
|
+
const lock = lockProviderA.create(key, {
|
|
91
|
+
ttl,
|
|
266
92
|
});
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
93
|
+
const result = await lock.runOrFail(new _module_3.LazyPromise(async () => {
|
|
94
|
+
await (0, _module_3.delay)(TTL);
|
|
95
|
+
return "a";
|
|
96
|
+
}));
|
|
97
|
+
expect(result).toBe("a");
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
describe("method: acquire", () => {
|
|
101
|
+
test("Should return true when lock is available", async () => {
|
|
102
|
+
const key = "a";
|
|
103
|
+
const ttl = null;
|
|
104
|
+
const lock = lockProviderA.create(key, {
|
|
105
|
+
ttl,
|
|
279
106
|
});
|
|
107
|
+
const result = await lock.acquire();
|
|
108
|
+
expect(result).toBe(true);
|
|
280
109
|
});
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const lock1 = lockProviderA.create(key, {
|
|
287
|
-
ttl,
|
|
288
|
-
owner: owner1,
|
|
289
|
-
});
|
|
290
|
-
await lock1.acquire();
|
|
291
|
-
const owner2 = "c";
|
|
292
|
-
const lock2 = lockProviderA.create(key, {
|
|
293
|
-
ttl,
|
|
294
|
-
owner: owner2,
|
|
295
|
-
});
|
|
296
|
-
await lock2.forceRelease();
|
|
297
|
-
const result = await lock1.acquire();
|
|
298
|
-
expect(result).toBe(true);
|
|
110
|
+
test("Should return false when lock is already acquired", async () => {
|
|
111
|
+
const key = "a";
|
|
112
|
+
const ttl = null;
|
|
113
|
+
const lock = lockProviderA.create(key, {
|
|
114
|
+
ttl,
|
|
299
115
|
});
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
expect(result).toBe(true);
|
|
116
|
+
await lock.acquire();
|
|
117
|
+
const result = await lock.acquire();
|
|
118
|
+
expect(result).toBe(false);
|
|
119
|
+
});
|
|
120
|
+
test("Should not be expired when released by same owner", async () => {
|
|
121
|
+
const key = "a";
|
|
122
|
+
const ttl = null;
|
|
123
|
+
const owner = "b";
|
|
124
|
+
const lock = lockProviderA.create(key, {
|
|
125
|
+
ttl,
|
|
126
|
+
owner,
|
|
312
127
|
});
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
expect(result).toBe(false);
|
|
128
|
+
await lock.acquire();
|
|
129
|
+
const result = await lock.isExpired();
|
|
130
|
+
expect(result).toBe(false);
|
|
131
|
+
});
|
|
132
|
+
test("Should be loked when released by same owner", async () => {
|
|
133
|
+
const key = "a";
|
|
134
|
+
const ttl = null;
|
|
135
|
+
const owner = "b";
|
|
136
|
+
const lock = lockProviderA.create(key, {
|
|
137
|
+
ttl,
|
|
138
|
+
owner,
|
|
325
139
|
});
|
|
140
|
+
await lock.acquire();
|
|
141
|
+
const result = await lock.isLocked();
|
|
142
|
+
expect(result).toBe(true);
|
|
326
143
|
});
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
owner,
|
|
335
|
-
});
|
|
336
|
-
await lock.acquire();
|
|
337
|
-
const result = await lock.isExpired();
|
|
338
|
-
expect(result).toBe(false);
|
|
144
|
+
});
|
|
145
|
+
describe("method: acquireOrFail", () => {
|
|
146
|
+
test("Should not throw KeyAlreadyAcquiredLockError when lock is available", async () => {
|
|
147
|
+
const key = "a";
|
|
148
|
+
const ttl = null;
|
|
149
|
+
const lock = lockProviderA.create(key, {
|
|
150
|
+
ttl,
|
|
339
151
|
});
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
await lock.acquire();
|
|
349
|
-
const result = await lock.isExpired();
|
|
350
|
-
expect(result).toBe(false);
|
|
152
|
+
const result = lock.acquireOrFail();
|
|
153
|
+
await expect(result).resolves.toBeUndefined();
|
|
154
|
+
});
|
|
155
|
+
test("Should throw KeyAlreadyAcquiredLockError when lock is already acquired", async () => {
|
|
156
|
+
const key = "a";
|
|
157
|
+
const ttl = null;
|
|
158
|
+
const lock = lockProviderA.create(key, {
|
|
159
|
+
ttl,
|
|
351
160
|
});
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
161
|
+
await lock.acquireOrFail();
|
|
162
|
+
const result = lock.acquireOrFail();
|
|
163
|
+
await expect(result).rejects.toBeInstanceOf(_module_1.KeyAlreadyAcquiredLockError);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
describe("method: release", () => {
|
|
167
|
+
test("Should return true when released by same owner", async () => {
|
|
168
|
+
const key = "a";
|
|
169
|
+
const ttl = null;
|
|
170
|
+
const owner = "b";
|
|
171
|
+
const lock = lockProviderA.create(key, {
|
|
172
|
+
ttl,
|
|
173
|
+
owner,
|
|
364
174
|
});
|
|
175
|
+
await lock.acquire();
|
|
176
|
+
const result = await lock.release();
|
|
177
|
+
expect(result).toBe(true);
|
|
365
178
|
});
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
179
|
+
test("Should return false when released by different owner", async () => {
|
|
180
|
+
const key = "a";
|
|
181
|
+
const ttl = null;
|
|
182
|
+
const owner1 = "b";
|
|
183
|
+
const lock1 = lockProviderA.create(key, {
|
|
184
|
+
ttl,
|
|
185
|
+
owner: owner1,
|
|
186
|
+
});
|
|
187
|
+
await lock1.acquire();
|
|
188
|
+
const owner2 = "c";
|
|
189
|
+
const lock2 = lockProviderA.create(key, {
|
|
190
|
+
ttl,
|
|
191
|
+
owner: owner2,
|
|
192
|
+
});
|
|
193
|
+
const result = await lock2.release();
|
|
194
|
+
expect(result).toBe(false);
|
|
195
|
+
});
|
|
196
|
+
test("Should be expired when released by same owner", async () => {
|
|
197
|
+
const key = "a";
|
|
198
|
+
const ttl = null;
|
|
199
|
+
const owner = "b";
|
|
200
|
+
const lock = lockProviderA.create(key, {
|
|
201
|
+
ttl,
|
|
202
|
+
owner,
|
|
203
|
+
});
|
|
204
|
+
await lock.acquire();
|
|
205
|
+
await lock.release();
|
|
206
|
+
const result = await lock.isExpired();
|
|
207
|
+
expect(result).toBe(true);
|
|
208
|
+
});
|
|
209
|
+
test("Should be not loked when released by same owner", async () => {
|
|
210
|
+
const key = "a";
|
|
211
|
+
const ttl = null;
|
|
212
|
+
const owner = "b";
|
|
213
|
+
const lock = lockProviderA.create(key, {
|
|
214
|
+
ttl,
|
|
215
|
+
owner,
|
|
378
216
|
});
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
217
|
+
await lock.acquire();
|
|
218
|
+
await lock.release();
|
|
219
|
+
const result = await lock.isLocked();
|
|
220
|
+
expect(result).toBe(false);
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
describe("method: releaseOrFail", () => {
|
|
224
|
+
test("Should not throw UnownedReleaseLockError when released by same owner", async () => {
|
|
225
|
+
const key = "a";
|
|
226
|
+
const ttl = null;
|
|
227
|
+
const owner = "b";
|
|
228
|
+
const lock = lockProviderA.create(key, {
|
|
229
|
+
ttl,
|
|
230
|
+
owner,
|
|
390
231
|
});
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
232
|
+
await lock.acquire();
|
|
233
|
+
const result = lock.releaseOrFail();
|
|
234
|
+
await expect(result).resolves.toBeUndefined();
|
|
235
|
+
});
|
|
236
|
+
test("Should throw UnownedReleaseLockError when released by different owner", async () => {
|
|
237
|
+
const key = "a";
|
|
238
|
+
const ttl = null;
|
|
239
|
+
const owner1 = "b";
|
|
240
|
+
const lock1 = lockProviderA.create(key, {
|
|
241
|
+
ttl,
|
|
242
|
+
owner: owner1,
|
|
243
|
+
});
|
|
244
|
+
await lock1.acquire();
|
|
245
|
+
const owner2 = "c";
|
|
246
|
+
const lock2 = lockProviderA.create(key, {
|
|
247
|
+
ttl,
|
|
248
|
+
owner: owner2,
|
|
249
|
+
});
|
|
250
|
+
const result = lock2.releaseOrFail();
|
|
251
|
+
await expect(result).rejects.toBeInstanceOf(_module_1.UnownedReleaseLockError);
|
|
252
|
+
});
|
|
253
|
+
test("Should be expired when released by same owner", async () => {
|
|
254
|
+
const key = "a";
|
|
255
|
+
const ttl = null;
|
|
256
|
+
const owner = "b";
|
|
257
|
+
const lock = lockProviderA.create(key, {
|
|
258
|
+
ttl,
|
|
259
|
+
owner,
|
|
260
|
+
});
|
|
261
|
+
await lock.acquire();
|
|
262
|
+
await lock.releaseOrFail();
|
|
263
|
+
const result = await lock.isExpired();
|
|
264
|
+
expect(result).toBe(true);
|
|
265
|
+
});
|
|
266
|
+
test("Should be not loked when released by same owner", async () => {
|
|
267
|
+
const key = "a";
|
|
268
|
+
const ttl = null;
|
|
269
|
+
const owner = "b";
|
|
270
|
+
const lock = lockProviderA.create(key, {
|
|
271
|
+
ttl,
|
|
272
|
+
owner,
|
|
403
273
|
});
|
|
274
|
+
await lock.acquire();
|
|
275
|
+
await lock.releaseOrFail();
|
|
276
|
+
const result = await lock.isLocked();
|
|
277
|
+
expect(result).toBe(false);
|
|
404
278
|
});
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
279
|
+
});
|
|
280
|
+
describe("method: forceRelease", () => {
|
|
281
|
+
test("Should release lock no regardless of the owner", async () => {
|
|
282
|
+
const key = "a";
|
|
283
|
+
const ttl = null;
|
|
284
|
+
const owner1 = "b";
|
|
285
|
+
const lock1 = lockProviderA.create(key, {
|
|
286
|
+
ttl,
|
|
287
|
+
owner: owner1,
|
|
288
|
+
});
|
|
289
|
+
await lock1.acquire();
|
|
290
|
+
const owner2 = "c";
|
|
291
|
+
const lock2 = lockProviderA.create(key, {
|
|
292
|
+
ttl,
|
|
293
|
+
owner: owner2,
|
|
294
|
+
});
|
|
295
|
+
await lock2.forceRelease();
|
|
296
|
+
const result = await lock1.acquire();
|
|
297
|
+
expect(result).toBe(true);
|
|
298
|
+
});
|
|
299
|
+
test("Should be expired when released", async () => {
|
|
300
|
+
const key = "a";
|
|
301
|
+
const ttl = null;
|
|
302
|
+
const owner = "b";
|
|
303
|
+
const lock = lockProviderA.create(key, {
|
|
304
|
+
ttl,
|
|
305
|
+
owner,
|
|
306
|
+
});
|
|
307
|
+
await lock.acquire();
|
|
308
|
+
await lock.forceRelease();
|
|
309
|
+
const result = await lock.isExpired();
|
|
310
|
+
expect(result).toBe(true);
|
|
311
|
+
});
|
|
312
|
+
test("Should be not loked when released", async () => {
|
|
313
|
+
const key = "a";
|
|
314
|
+
const ttl = null;
|
|
315
|
+
const owner = "b";
|
|
316
|
+
const lock = lockProviderA.create(key, {
|
|
317
|
+
ttl,
|
|
318
|
+
owner,
|
|
418
319
|
});
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
const result = await lock2.refresh();
|
|
434
|
-
expect(result).toBe(false);
|
|
320
|
+
await lock.acquire();
|
|
321
|
+
await lock.forceRelease();
|
|
322
|
+
const result = await lock.isLocked();
|
|
323
|
+
expect(result).toBe(false);
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
describe("method: isExpired", () => {
|
|
327
|
+
test("Should return false when lock has no expiration", async () => {
|
|
328
|
+
const key = "a";
|
|
329
|
+
const ttl = null;
|
|
330
|
+
const owner = "b";
|
|
331
|
+
const lock = lockProviderA.create(key, {
|
|
332
|
+
ttl,
|
|
333
|
+
owner,
|
|
435
334
|
});
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
const time = await lock.getRemainingTime();
|
|
448
|
-
expect(time?.toMilliseconds()).toBeGreaterThan(0);
|
|
335
|
+
await lock.acquire();
|
|
336
|
+
const result = await lock.isExpired();
|
|
337
|
+
expect(result).toBe(false);
|
|
338
|
+
});
|
|
339
|
+
test("Should return false when lock has not expired", async () => {
|
|
340
|
+
const key = "a";
|
|
341
|
+
const owner = "b";
|
|
342
|
+
const ttl = TTL;
|
|
343
|
+
const lock = lockProviderA.create(key, {
|
|
344
|
+
ttl,
|
|
345
|
+
owner,
|
|
449
346
|
});
|
|
347
|
+
await lock.acquire();
|
|
348
|
+
const result = await lock.isExpired();
|
|
349
|
+
expect(result).toBe(false);
|
|
450
350
|
});
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
owner,
|
|
459
|
-
});
|
|
460
|
-
await lock.acquire();
|
|
461
|
-
await (0, _module_3.delay)(ttl);
|
|
462
|
-
const result = lock.refreshOrFail();
|
|
463
|
-
await expect(result).resolves.toBeUndefined();
|
|
351
|
+
test("Should return true when lock has expired", async () => {
|
|
352
|
+
const key = "a";
|
|
353
|
+
const owner = "b";
|
|
354
|
+
const ttl = TTL;
|
|
355
|
+
const lock = lockProviderA.create(key, {
|
|
356
|
+
ttl,
|
|
357
|
+
owner,
|
|
464
358
|
});
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
const result = lock2.refreshOrFail();
|
|
480
|
-
await expect(result).rejects.toBeInstanceOf(_module_1.UnownedExtendLockError);
|
|
359
|
+
await lock.acquire();
|
|
360
|
+
await (0, _module_3.delay)(ttl.addMilliseconds(25));
|
|
361
|
+
const result = await lock.isExpired();
|
|
362
|
+
expect(result).toBe(true);
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
describe("method: isLocked", () => {
|
|
366
|
+
test("Should return true when lock has no expiration", async () => {
|
|
367
|
+
const key = "a";
|
|
368
|
+
const ttl = null;
|
|
369
|
+
const owner = "b";
|
|
370
|
+
const lock = lockProviderA.create(key, {
|
|
371
|
+
ttl,
|
|
372
|
+
owner,
|
|
481
373
|
});
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
const time = await lock.getRemainingTime();
|
|
494
|
-
expect(time?.toMilliseconds()).toBeGreaterThan(0);
|
|
374
|
+
await lock.acquire();
|
|
375
|
+
const result = await lock.isLocked();
|
|
376
|
+
expect(result).toBe(true);
|
|
377
|
+
});
|
|
378
|
+
test("Should return true when lock has not expired", async () => {
|
|
379
|
+
const key = "a";
|
|
380
|
+
const owner = "b";
|
|
381
|
+
const ttl = TTL;
|
|
382
|
+
const lock = lockProviderA.create(key, {
|
|
383
|
+
ttl,
|
|
384
|
+
owner,
|
|
495
385
|
});
|
|
386
|
+
await lock.acquire();
|
|
387
|
+
const result = await lock.isLocked();
|
|
388
|
+
expect(result).toBe(true);
|
|
496
389
|
});
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
owner,
|
|
505
|
-
});
|
|
506
|
-
const result = await lock.getRemainingTime();
|
|
507
|
-
expect(result).toBeNull();
|
|
390
|
+
test("Should return false when lock has expired", async () => {
|
|
391
|
+
const key = "a";
|
|
392
|
+
const owner = "b";
|
|
393
|
+
const ttl = TTL;
|
|
394
|
+
const lock = lockProviderA.create(key, {
|
|
395
|
+
ttl,
|
|
396
|
+
owner,
|
|
508
397
|
});
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
398
|
+
await lock.acquire();
|
|
399
|
+
await (0, _module_3.delay)(ttl.addMilliseconds(25));
|
|
400
|
+
const result = await lock.isLocked();
|
|
401
|
+
expect(result).toBe(false);
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
describe("method: refresh", () => {
|
|
405
|
+
test("Should return true when refreshed by same owner", async () => {
|
|
406
|
+
const key = "a";
|
|
407
|
+
const ttl = TTL;
|
|
408
|
+
const owner = "b";
|
|
409
|
+
const lock = lockProviderA.create(key, {
|
|
410
|
+
ttl,
|
|
411
|
+
owner,
|
|
412
|
+
});
|
|
413
|
+
await lock.acquire();
|
|
414
|
+
await (0, _module_3.delay)(ttl);
|
|
415
|
+
const result = await lock.refresh();
|
|
416
|
+
expect(result).toBe(true);
|
|
417
|
+
});
|
|
418
|
+
test("Should return false when refreshed by different owner", async () => {
|
|
419
|
+
const key = "a";
|
|
420
|
+
const ttl = TTL;
|
|
421
|
+
const owner1 = "b";
|
|
422
|
+
const lock1 = lockProviderA.create(key, {
|
|
423
|
+
ttl,
|
|
424
|
+
owner: owner1,
|
|
425
|
+
});
|
|
426
|
+
await lock1.acquire();
|
|
427
|
+
const owner2 = "c";
|
|
428
|
+
const lock2 = lockProviderA.create(key, {
|
|
429
|
+
ttl,
|
|
430
|
+
owner: owner2,
|
|
431
|
+
});
|
|
432
|
+
const result = await lock2.refresh();
|
|
433
|
+
expect(result).toBe(false);
|
|
434
|
+
});
|
|
435
|
+
test("Should refresh expiration by same owner", async () => {
|
|
436
|
+
const key = "a";
|
|
437
|
+
const ttl = TTL;
|
|
438
|
+
const owner = "b";
|
|
439
|
+
const lock = lockProviderA.create(key, {
|
|
440
|
+
ttl,
|
|
441
|
+
owner,
|
|
442
|
+
});
|
|
443
|
+
await lock.acquire();
|
|
444
|
+
await (0, _module_3.delay)(ttl.subtractMilliseconds(10));
|
|
445
|
+
await lock.refresh();
|
|
446
|
+
const time = await lock.getRemainingTime();
|
|
447
|
+
expect(time?.toMilliseconds()).toBeGreaterThan(0);
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
describe("method: refreshOrFail", () => {
|
|
451
|
+
test("Should not throw UnownedRefreshLockError when refreshed by same owner", async () => {
|
|
452
|
+
const key = "a";
|
|
453
|
+
const ttl = TTL;
|
|
454
|
+
const owner = "b";
|
|
455
|
+
const lock = lockProviderA.create(key, {
|
|
456
|
+
ttl,
|
|
457
|
+
owner,
|
|
458
|
+
});
|
|
459
|
+
await lock.acquire();
|
|
460
|
+
await (0, _module_3.delay)(ttl);
|
|
461
|
+
const result = lock.refreshOrFail();
|
|
462
|
+
await expect(result).resolves.toBeUndefined();
|
|
463
|
+
});
|
|
464
|
+
test("Should throw UnownedRefreshLockError when refreshed by different owner", async () => {
|
|
465
|
+
const key = "a";
|
|
466
|
+
const ttl = TTL;
|
|
467
|
+
const owner1 = "b";
|
|
468
|
+
const lock1 = lockProviderA.create(key, {
|
|
469
|
+
ttl,
|
|
470
|
+
owner: owner1,
|
|
471
|
+
});
|
|
472
|
+
await lock1.acquire();
|
|
473
|
+
const owner2 = "c";
|
|
474
|
+
const lock2 = lockProviderA.create(key, {
|
|
475
|
+
ttl,
|
|
476
|
+
owner: owner2,
|
|
477
|
+
});
|
|
478
|
+
const result = lock2.refreshOrFail();
|
|
479
|
+
await expect(result).rejects.toBeInstanceOf(_module_1.UnownedRefreshLockError);
|
|
480
|
+
});
|
|
481
|
+
test("Should refresh expiration by same owner", async () => {
|
|
482
|
+
const key = "a";
|
|
483
|
+
const ttl = TTL;
|
|
484
|
+
const owner = "b";
|
|
485
|
+
const lock = lockProviderA.create(key, {
|
|
486
|
+
ttl,
|
|
487
|
+
owner,
|
|
488
|
+
});
|
|
489
|
+
await lock.acquireOrFail();
|
|
490
|
+
await (0, _module_3.delay)(ttl.subtractMilliseconds(10));
|
|
491
|
+
await lock.refresh();
|
|
492
|
+
const time = await lock.getRemainingTime();
|
|
493
|
+
expect(time?.toMilliseconds()).toBeGreaterThan(0);
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
describe("method: getRemainingTime", () => {
|
|
497
|
+
test("Should return null when lock is not acquired", async () => {
|
|
498
|
+
const key = "a";
|
|
499
|
+
const ttl = null;
|
|
500
|
+
const owner = "b";
|
|
501
|
+
const lock = lockProviderA.create(key, {
|
|
502
|
+
ttl,
|
|
503
|
+
owner,
|
|
520
504
|
});
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
expect(result?.toMilliseconds()).toBe(ttl.toMilliseconds());
|
|
505
|
+
const result = await lock.getRemainingTime();
|
|
506
|
+
expect(result).toBeNull();
|
|
507
|
+
});
|
|
508
|
+
test("Should return null when lock is acquired and has expiration", async () => {
|
|
509
|
+
const key = "a";
|
|
510
|
+
const ttl = null;
|
|
511
|
+
const owner = "b";
|
|
512
|
+
const lock = lockProviderA.create(key, {
|
|
513
|
+
ttl,
|
|
514
|
+
owner,
|
|
532
515
|
});
|
|
516
|
+
await lock.acquire();
|
|
517
|
+
const result = await lock.getRemainingTime();
|
|
518
|
+
expect(result).toBeNull();
|
|
533
519
|
});
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
const result = await lock.getOwner();
|
|
542
|
-
expect(result).toBe(owner);
|
|
520
|
+
test("Should return remaining time when lock is not acquired", async () => {
|
|
521
|
+
const key = "a";
|
|
522
|
+
const ttl = TTL;
|
|
523
|
+
const owner = "b";
|
|
524
|
+
const lock = lockProviderA.create(key, {
|
|
525
|
+
ttl,
|
|
526
|
+
owner,
|
|
543
527
|
});
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
528
|
+
await lock.acquire();
|
|
529
|
+
const result = await lock.getRemainingTime();
|
|
530
|
+
expect(result?.toMilliseconds()).toBe(ttl.toMilliseconds());
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
describe("method: getOwner", () => {
|
|
534
|
+
test("Should return the owner", async () => {
|
|
535
|
+
const key = "a";
|
|
536
|
+
const owner = "b";
|
|
537
|
+
const lock = lockProviderA.create(key, {
|
|
538
|
+
owner,
|
|
550
539
|
});
|
|
540
|
+
const result = await lock.getOwner();
|
|
541
|
+
expect(result).toBe(owner);
|
|
542
|
+
});
|
|
543
|
+
test("Should return the auto generated owner", async () => {
|
|
544
|
+
const key = "a";
|
|
545
|
+
const lock = lockProviderA.create(key);
|
|
546
|
+
const result = await lock.getOwner();
|
|
547
|
+
expect(result).toBeDefined();
|
|
548
|
+
expect(typeof result).toBe("string");
|
|
551
549
|
});
|
|
552
550
|
});
|
|
553
551
|
});
|