keuss 1.7.4 → 2.0.1

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.
Files changed (65) hide show
  1. package/Pipeline/Queue.js +0 -1
  2. package/QFactory.js +49 -17
  3. package/Queue.js +1 -4
  4. package/README.md +2 -1
  5. package/TODO +0 -9
  6. package/backends/bucket-mongo-safe.js +11 -11
  7. package/backends/intraorder.js +13 -11
  8. package/backends/mongo.js +12 -9
  9. package/backends/pl-mongo.js +8 -5
  10. package/backends/postgres.js +380 -0
  11. package/backends/ps-mongo.js +11 -8
  12. package/backends/redis-list.js +8 -8
  13. package/backends/redis-oq.js +8 -3
  14. package/backends/stream-mongo.js +10 -15
  15. package/package.json +12 -8
  16. package/stats/mem.js +0 -1
  17. package/.github/workflows/codeql-analysis.yml +0 -72
  18. package/bench/all-mongo.js +0 -108
  19. package/bench/multi-q.js +0 -85
  20. package/bench/redis-oq-consumer-producer.js +0 -52
  21. package/bench/redis-oq-consumer.js +0 -40
  22. package/bench/redis-oq-producer.js +0 -43
  23. package/docker-compose/docker-compose.yaml +0 -18
  24. package/docker-compose.yaml +0 -18
  25. package/examples/pipelines/builder/index.js +0 -99
  26. package/examples/pipelines/fromRecipe/index.js +0 -127
  27. package/examples/pipelines/simplest/index.js +0 -38
  28. package/examples/pipelines/simulation-fork/index.js +0 -115
  29. package/examples/snippets/01-simplest-pop-push.js +0 -49
  30. package/examples/snippets/02-simplest-reserve-rollback-commit.js +0 -44
  31. package/examples/snippets/03-simplest-producer-consumer-loops.js +0 -77
  32. package/examples/snippets/04-bucket-mongo-safe-insert-reserve-commit.js +0 -78
  33. package/examples/snippets/05-insert-reserve-rollback-deadletter.js +0 -105
  34. package/examples/snippets/06-random-consumer-producer.js +0 -270
  35. package/examples/snippets/07-stream-simple.js +0 -53
  36. package/examples/snippets/redislabs-consumer-producer.js +0 -44
  37. package/examples/snippets/with-redis-stats-and-signaller-consumer-producer.js +0 -52
  38. package/examples/webhooks/README.md +0 -36
  39. package/examples/webhooks/app.js +0 -70
  40. package/examples/webhooks/consumer.js +0 -98
  41. package/examples/webhooks/index.js +0 -55
  42. package/examples/webhooks/package-lock.json +0 -500
  43. package/examples/webhooks/package.json +0 -23
  44. package/examples/webhooks/wh-payload.json +0 -38
  45. package/playground/irc.js +0 -53
  46. package/playground/pl-rollback.js +0 -55
  47. package/playground/pl1.js +0 -74
  48. package/playground/q1.js +0 -34
  49. package/playground/simple-pl.js +0 -42
  50. package/playground/stream-loops.js +0 -114
  51. package/test/backends_bucket-at-least-once.js +0 -302
  52. package/test/backends_deadletter.js +0 -227
  53. package/test/backends_payload.js +0 -542
  54. package/test/backends_push-pop.js +0 -170
  55. package/test/backends_remove.js +0 -320
  56. package/test/backends_reserve-commit-rollback.js +0 -1033
  57. package/test/intraorder.js +0 -325
  58. package/test/pause.js +0 -220
  59. package/test/pipeline-Builder.js +0 -285
  60. package/test/pipeline-ChoiceLink.js +0 -241
  61. package/test/pipeline-DirectLink.js +0 -376
  62. package/test/pipeline-Sink.js +0 -175
  63. package/test/signal.js +0 -196
  64. package/test/stats.js +0 -296
  65. package/test/stream-mongo.js +0 -166
@@ -1,325 +0,0 @@
1
- const async = require ('async');
2
- const should = require ('should');
3
- const _ = require ('lodash');
4
-
5
- const LocalSignal = require ('../signal/local');
6
- const MemStats = require ('../stats/mem');
7
-
8
- const MongoClient = require ('mongodb').MongoClient;
9
-
10
-
11
- const MQ = require ('../backends/intraorder');
12
-
13
- var factory = null;
14
-
15
-
16
- describe('IntraOrder backend: specific operations', () => {
17
-
18
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////
19
- before(done => {
20
- var opts = {
21
- url: 'mongodb://localhost/keuss_test_intraorder',
22
- signaller: {provider: LocalSignal},
23
- stats: {provider: MemStats}
24
- };
25
-
26
- MQ(opts, (err, fct) => {
27
- if (err) return done(err);
28
- factory = fct;
29
- done();
30
- });
31
- });
32
-
33
-
34
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////
35
- after (done => async.series ([
36
- cb => setTimeout (cb, 1000),
37
- cb => factory.close (cb),
38
- cb => MongoClient.connect ('mongodb://localhost/keuss_test_intraorder', (err, cl) => {
39
- if (err) return done (err);
40
- cl.db().dropDatabase (() => cl.close (cb))
41
- })
42
- ], done));
43
-
44
-
45
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////
46
- it('sequential push & pops with no retries preserves order', done => {
47
- const q = factory.queue('test_queue_1');
48
-
49
- async.series([
50
- cb => q.push({elem: 1, iid: 'twetrwte', pl: {d: 't-', a: 56}}, cb),
51
- cb => q.push({elem: 2, iid: 'twetrwte', pl: {d: 't--', a: 156}}, cb),
52
- cb => q.push({elem: 3, iid: 'twetrwte', pl: {d: 't---', a: 256}}, cb),
53
- cb => q.push({elem: 4, iid: 'twetrwte', pl: {d: 't----', a: 356}}, cb),
54
- cb => q.push({elem: 5, iid: 'twetrwte', pl: {d: 't-----', a: 456}}, cb),
55
- cb => {
56
- q.size ((err, size) => {
57
- if (err) return done (err);
58
- size.should.equal(5);
59
- cb();
60
- })
61
- },
62
- cb => q.stats((err, res) => {
63
- if (err) return done (err);
64
- res.should.match({
65
- get: 0,
66
- put: 5,
67
- reserve: 0,
68
- commit: 0,
69
- rollback: 0,
70
- deadletter: 0
71
- });
72
- cb();
73
- }),
74
- cb => q.pop('c1', cb),
75
- cb => q.pop('c1', cb),
76
- cb => q.pop('c1', cb),
77
- cb => q.pop('c1', cb),
78
- cb => q.pop('c1', cb),
79
- cb => q.size((err, size) => {
80
- if (err) return done (err);
81
- size.should.equal(0);
82
- cb();
83
- }),
84
- cb => q.stats((err, res) => {
85
- if (err) return done (err);
86
- res.should.match({
87
- get: 5,
88
- put: 5,
89
- reserve: 0,
90
- commit: 0,
91
- rollback: 0,
92
- deadletter: 0
93
- });
94
- cb();
95
- }),
96
- ], (err, results) => {
97
- if (err) return done (err);
98
- results[7].payload.should.eql ({ elem: 1, iid: 'twetrwte', pl: { d: 't-', a: 56 } });
99
- results[8].payload.should.eql ({ elem: 2, iid: 'twetrwte', pl: { d: 't--', a: 156 } });
100
- results[9].payload.should.eql ({ elem: 3, iid: 'twetrwte', pl: { d: 't---', a: 256 } });
101
- results[10].payload.should.eql ({ elem: 4, iid: 'twetrwte', pl: { d: 't----', a: 356 } });
102
- results[11].payload.should.eql ({ elem: 5, iid: 'twetrwte', pl: { d: 't-----', a: 456 } });
103
- done();
104
- });
105
- });
106
-
107
-
108
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////
109
- it('sequential reserve-commit with retries preserves order', done => {
110
- const q = factory.queue('test_queue_2');
111
- const t0 = process.hrtime();
112
- async.series([
113
- cb => q.push({elem: 1, iid: 'twetrwte', pl: {d: 't-', a: 56}}, cb),
114
- cb => q.push({elem: 2, iid: 'twetrwte', pl: {d: 't--', a: 156}}, cb),
115
- cb => q.push({elem: 3, iid: 'twetrwte', pl: {d: 't---', a: 256}}, cb),
116
- cb => q.push({elem: 4, iid: 'twetrwte', pl: {d: 't----', a: 356}}, cb),
117
- cb => q.push({elem: 5, iid: 'twetrwte', pl: {d: 't-----', a: 456}}, cb),
118
-
119
- cb => q.pop('c1', {reserve: true}, (err, res) => {
120
- if (err) return done (err);
121
- res.payload.should.eql ({ elem: 1, iid: 'twetrwte', pl: { d: 't-', a: 56 } });
122
- q.ko (res, new Date().getTime () + 2000, cb)
123
- }),
124
-
125
- cb => q.pop('c1', {reserve: true}, (err, res) => {
126
- if (err) return done (err);
127
- res.payload.should.eql ({ elem: 1, iid: 'twetrwte', pl: { d: 't-', a: 56 } });
128
- q.ko (res, new Date().getTime () + 3000, cb)
129
- }),
130
-
131
- cb => q.pop('c1', {reserve: true}, (err, res) => {
132
- if (err) return done (err);
133
- res.payload.should.eql ({ elem: 1, iid: 'twetrwte', pl: { d: 't-', a: 56 } });
134
- q.ko (res, new Date().getTime () + 1000, cb)
135
- }),
136
-
137
- // cb => q.pop('c1', (err, res) => {console.log (new Date().toISOString (), res.payload); cb (err, res)}),
138
-
139
- cb => q.pop('c1', cb),
140
- cb => q.pop('c1', cb),
141
- cb => q.pop('c1', cb),
142
- cb => q.pop('c1', cb),
143
- cb => q.pop('c1', cb),
144
-
145
- cb => q.size((err, size) => {
146
- if (err) return done (err);
147
- size.should.equal(0);
148
- cb();
149
- }),
150
- ], (err, results) => {
151
- if (err) return done (err);
152
-
153
- // duration must be about 6 secs
154
- const delta = process.hrtime(t0);
155
- delta[0].should.eql (6);
156
- results[8].payload.should.eql ({ elem: 1, iid: 'twetrwte', pl: { d: 't-', a: 56 } });
157
- results[9].payload.should.eql ({ elem: 2, iid: 'twetrwte', pl: { d: 't--', a: 156 } });
158
- results[10].payload.should.eql ({ elem: 3, iid: 'twetrwte', pl: { d: 't---', a: 256 } });
159
- results[11].payload.should.eql ({ elem: 4, iid: 'twetrwte', pl: { d: 't----', a: 356 } });
160
- results[12].payload.should.eql ({ elem: 5, iid: 'twetrwte', pl: { d: 't-----', a: 456 } });
161
- done();
162
- });
163
- });
164
-
165
-
166
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////
167
- it('parallel reserve-commit on same iid blocks until commit', done => {
168
- const q = factory.queue('test_queue_3');
169
- const t0 = process.hrtime();
170
- const pops = [];
171
-
172
- async.series([
173
- cb => q.push({elem: 1, iid: 'twetrwte', pl: {d: 't-', a: 56}}, cb),
174
- cb => q.push({elem: 2, iid: 'twetrwte', pl: {d: 't--', a: 156}}, cb),
175
- cb => q.push({elem: 3, iid: 'twetrwte', pl: {d: 't---', a: 256}}, cb),
176
-
177
- cb => async.parallel ([
178
- cb => {
179
- let elem;
180
- async.series ([
181
- cb => setTimeout (cb, 500),
182
- cb => q.pop('c1', {reserve: true}, (err, res) => {elem = res; pops.push (res); cb (err); }),
183
- cb => setTimeout (cb, 1500),
184
- cb => q.ok (elem, cb),
185
- ], cb);
186
- },
187
- cb => {
188
- let elem;
189
- async.series ([
190
- cb => setTimeout (cb, 1000),
191
- cb => q.pop('c1', {reserve: true}, (err, res) => {elem = res; pops.push (res);; cb (err); }),
192
- cb => setTimeout (cb, 1500),
193
- cb => q.ok (elem, cb),
194
- ], cb);
195
- },
196
- cb => {
197
- let elem;
198
- async.series ([
199
- cb => setTimeout (cb, 1500),
200
- cb => q.pop('c1', {reserve: true}, (err, res) => {elem = res; pops.push (res);; cb (err); }),
201
- cb => setTimeout (cb, 1500),
202
- cb => q.ok (elem, cb),
203
- ], cb);
204
- },
205
- ], cb)
206
- ], (err, results) => {
207
- if (err) return done (err);
208
-
209
- pops[0].payload.should.eql ({ elem: 1, iid: 'twetrwte', pl: { d: 't-', a: 56 } });
210
- pops[1].payload.should.eql ({ elem: 2, iid: 'twetrwte', pl: { d: 't--', a: 156 } });
211
- pops[2].payload.should.eql ({ elem: 3, iid: 'twetrwte', pl: { d: 't---', a: 256 } });
212
-
213
- // duration must be about 6 secs
214
- const delta = process.hrtime(t0);
215
-
216
- // queue pop won't rearm after commit... so it will timeout after a min and only then rearm again for next pop/reserve
217
- // delta[0].should.eql (7);
218
- done();
219
- });
220
- });
221
-
222
-
223
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////
224
- it('parallel reserve-commit on same iid blocks until rollback', done => {
225
- const q = factory.queue('test_queue_4');
226
- const t0 = process.hrtime();
227
- const pops = [];
228
-
229
- async.series([
230
- cb => q.push({elem: 1, iid: 'twetrwte', pl: {d: 't-', a: 56}}, cb),
231
- cb => q.push({elem: 2, iid: 'twetrwte', pl: {d: 't--', a: 156}}, cb),
232
- cb => q.push({elem: 3, iid: 'twetrwte', pl: {d: 't---', a: 256}}, cb),
233
-
234
- cb => async.parallel ([
235
- cb => {
236
- let elem;
237
- async.series ([
238
- cb => setTimeout (cb, 500),
239
- cb => q.pop('c1', {reserve: true}, (err, res) => {elem = res; pops.push (res); cb (err); }),
240
- cb => q.ko (elem, new Date().getTime () + 1000, cb),
241
- ], cb);
242
- },
243
- cb => {
244
- let elem;
245
- async.series ([
246
- cb => setTimeout (cb, 700),
247
- cb => q.pop('c1', {reserve: true}, (err, res) => {elem = res; pops.push (res);; cb (err); }),
248
- cb => q.ko (elem, new Date().getTime () + 1000, cb),
249
- ], cb);
250
- },
251
- cb => {
252
- let elem;
253
- async.series ([
254
- cb => setTimeout (cb, 1500),
255
- cb => q.pop('c1', {reserve: true}, (err, res) => {elem = res; pops.push (res);; cb (err); }),
256
- cb => setTimeout (cb, 1500),
257
- cb => q.ok (elem, cb),
258
- ], cb);
259
- },
260
- cb => {
261
- let elem;
262
- async.series ([
263
- cb => setTimeout (cb, 2000),
264
- cb => q.pop('c1', {reserve: true}, (err, res) => {elem = res; pops.push (res);; cb (err); }),
265
- cb => setTimeout (cb, 1500),
266
- cb => q.ok (elem, cb),
267
- ], cb);
268
- },
269
- cb => {
270
- let elem;
271
- async.series ([
272
- cb => setTimeout (cb, 2500),
273
- cb => q.pop('c1', {reserve: true}, (err, res) => {elem = res; pops.push (res);; cb (err); }),
274
- cb => setTimeout (cb, 1500),
275
- cb => q.ok (elem, cb),
276
- ], cb);
277
- },
278
- ], cb)
279
- ], (err, results) => {
280
- if (err) return done (err);
281
-
282
- pops[0].payload.should.eql ({ elem: 1, iid: 'twetrwte', pl: { d: 't-', a: 56 } });
283
- pops[1].payload.should.eql ({ elem: 1, iid: 'twetrwte', pl: { d: 't-', a: 56 } });
284
- pops[2].payload.should.eql ({ elem: 1, iid: 'twetrwte', pl: { d: 't-', a: 56 } });
285
- pops[3].payload.should.eql ({ elem: 2, iid: 'twetrwte', pl: { d: 't--', a: 156 } });
286
- pops[4].payload.should.eql ({ elem: 3, iid: 'twetrwte', pl: { d: 't---', a: 256 } });
287
-
288
- // duration must be about 6 secs
289
- const delta = process.hrtime(t0);
290
-
291
- // queue pop won't rearm after commit... so it will timeout after a min and only then rearm again for next pop/reserve
292
- // delta[0].should.eql (7);
293
- done();
294
- });
295
- });
296
-
297
-
298
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////
299
- it('delayed push preserves order', done => {
300
- const q = factory.queue('test_queue_1');
301
-
302
- async.series([
303
- cb => q.push({elem: 1, iid: 'twetrwte', pl: {d: 't-', a: 56}}, {delay: 5}, cb),
304
- cb => q.push({elem: 2, iid: 'twetrwte', pl: {d: 't--', a: 156}}, {delay: 4}, cb),
305
- cb => q.push({elem: 3, iid: 'twetrwte', pl: {d: 't---', a: 256}}, {delay: 3}, cb),
306
- cb => q.push({elem: 4, iid: 'twetrwte', pl: {d: 't----', a: 356}}, {delay: 2}, cb),
307
- cb => q.push({elem: 5, iid: 'twetrwte', pl: {d: 't-----', a: 456}}, {delay: 1}, cb),
308
- cb => q.pop('c1', cb),
309
- cb => q.pop('c1', cb),
310
- cb => q.pop('c1', cb),
311
- cb => q.pop('c1', cb),
312
- cb => q.pop('c1', cb),
313
- ], (err, results) => {
314
- if (err) return done (err);
315
- results[5].payload.should.eql ({ elem: 1, iid: 'twetrwte', pl: { d: 't-', a: 56 } });
316
- results[6].payload.should.eql ({ elem: 2, iid: 'twetrwte', pl: { d: 't--', a: 156 } });
317
- results[7].payload.should.eql ({ elem: 3, iid: 'twetrwte', pl: { d: 't---', a: 256 } });
318
- results[8].payload.should.eql ({ elem: 4, iid: 'twetrwte', pl: { d: 't----', a: 356 } });
319
- results[9].payload.should.eql ({ elem: 5, iid: 'twetrwte', pl: { d: 't-----', a: 456 } });
320
- done();
321
- });
322
- });
323
-
324
-
325
- });
package/test/pause.js DELETED
@@ -1,220 +0,0 @@
1
-
2
- var async = require ('async');
3
- var should = require ('should');
4
- var _ = require ('lodash');
5
- var MongoClient = require ('mongodb').MongoClient;
6
-
7
- var factory = null;
8
-
9
- [
10
- {label: 'redis list', backend: require ('../backends/redis-list')},
11
- {label: 'redis OrderedQueue', backend: require ('../backends/redis-oq')},
12
- {label: 'pipeline MongoDB', backend: require ('../backends/pl-mongo')},
13
- {label: 'persistent MongoDB', backend: require ('../backends/ps-mongo')},
14
- {label: 'Stream MongoDB', backend: require ('../backends/stream-mongo')},
15
- {label: 'plain MongoDB', backend: require ('../backends/mongo')},
16
- {label: 'Safe MongoDB Bucket', backend: require ('../backends/bucket-mongo-safe')},
17
- {label: 'Mongo IntraOrder', backend: require ('../backends/intraorder')},
18
- ].forEach (backend_item => {
19
- [
20
- {label: 'mem', stats: require('../stats/mem')},
21
- {label: 'mongo', stats: require('../stats/mongo')},
22
- {label: 'redis', stats: require('../stats/redis')},
23
- ].forEach (stats_item => {
24
- [
25
- {label: 'local', signal: require ('../signal/local')},
26
- {label: 'redis-pubsub', signal: require ('../signal/redis-pubsub')},
27
- {label: 'mongo-capped', signal: require ('../signal/mongo-capped')},
28
- ].forEach (signal_item => {
29
- describe (`pause/resume tests with backend ${backend_item.label}, stats ${stats_item.label}, signal ${signal_item.label}`, () => {
30
- var MQ = backend_item.backend;
31
-
32
- before (done => {
33
- var opts = {
34
- url: 'mongodb://localhost/keuss_test_pause',
35
- signaller: {
36
- provider: signal_item.signal,
37
- opts: {url: 'mongodb://localhost/keuss_test_pause_signal'}
38
- },
39
- stats: {
40
- provider: stats_item.stats,
41
- opts: {url: 'mongodb://localhost/keuss_test_pause_stats'}
42
- }
43
- };
44
-
45
- MQ (opts, (err, fct) => {
46
- if (err) return done (err);
47
- factory = fct;
48
- done();
49
- });
50
- });
51
-
52
- after (done => {
53
- async.series ([
54
- cb => setTimeout (cb, 1000),
55
- cb => factory.close (cb),
56
- cb => MongoClient.connect ('mongodb://localhost/keuss_test_pause', (err, cl) => {
57
- if (err) return done (err);
58
- cl.db().dropDatabase (() => cl.close (cb))
59
- }),
60
- cb => MongoClient.connect ('mongodb://localhost/keuss_test_pause_stats', (err, cl) => {
61
- if (err) return done (err);
62
- cl.db().dropDatabase (() => cl.close (cb))
63
- }),
64
- cb => MongoClient.connect ('mongodb://localhost/keuss_test_pause_signal', (err, cl) => {
65
- if (err) return done (err);
66
- cl.db().dropDatabase (() => cl.close (cb))
67
- })
68
- ], done);
69
- });
70
-
71
- it ('queue pauses and resumes ok, existing consumers react accordingly', done => {
72
- var q = factory.queue('_test_0_queue_', {});
73
-
74
- async.series ([
75
- cb => q._stats.clear (cb),
76
-
77
- cb => async.parallel ([
78
- cb => q.push ({q:0, a: 'ryetyeryre 0'}, cb),
79
- cb => q.push ({q:1, a: 'ryetyeryre 1'}, cb),
80
- cb => q.push ({q:2, a: 'ryetyeryre 2'}, cb),
81
- cb => q.push ({q:3, a: 'ryetyeryre 3'}, cb),
82
- cb => q.push ({q:4, a: 'ryetyeryre 4'}, cb),
83
- cb => q.push ({q:5, a: 'ryetyeryre 5'}, cb),
84
- ], cb),
85
-
86
- cb => async.parallel ([
87
- cb => setTimeout (() => q.pop ('me', cb), 1000),
88
- cb => setTimeout (() => q.pop ('me', cb), 1000),
89
- cb => setTimeout (() => q.pop ('me', cb), 1000),
90
- cb => setTimeout (() => q.pop ('me', cb), 1000),
91
- cb => setTimeout (() => q.pop ('me', cb), 1000),
92
- cb => setTimeout (() => q.pop ('me', cb), 1000),
93
-
94
- cb => setTimeout (() => {q.pause(true); cb ();}, 100),
95
- cb => setTimeout (() => {q.pause(false); cb ();}, 2000),
96
- ], cb),
97
-
98
- cb => setTimeout (cb, 1000),
99
-
100
- cb => q.stats(cb),
101
- cb => q.size (cb),
102
- cb => q._stats.clear (cb),
103
-
104
- ], (err, res) => {
105
- if (err) return done (err);
106
- res[4].should.match ({ put: 6, get: 6 });
107
- res[5].should.equal (0);
108
- q.nConsumers().should.equal (0);
109
-
110
- done ();
111
- });
112
- });
113
-
114
- it ('pauses ok new consumers if queue paused, resumes them allright', done => {
115
- var q = factory.queue('_test_1_queue_', {});
116
-
117
- async.series ([
118
- cb => q._stats.clear (cb),
119
- cb => {q.pause (true); cb ();},
120
-
121
- cb => async.parallel ([
122
- cb => setTimeout (() => q.pop ('me', cb), 100),
123
- cb => setTimeout (() => q.push ({q:0, a: 'ryetyeryre 0'}, cb), 1000),
124
- cb => setTimeout (() => {q.pause (false); cb ();}, 2000),
125
- ], cb),
126
-
127
- cb => setTimeout (cb, 1000),
128
-
129
- cb => q.stats(cb),
130
- cb => q.size (cb),
131
-
132
- cb => q._stats.clear (cb),
133
- ], (err, res) => {
134
- if (err) return done (err);
135
- res[4].should.match ({ put: 1, get: 1 });
136
- res[5].should.equal (0);
137
- q.nConsumers().should.equal (0);
138
-
139
- done ();
140
- });
141
- });
142
-
143
- it ('consumer with timeout times out ok if queue was paused', done => {
144
- var q = factory.queue('_test_2_queue_', {});
145
-
146
- async.series ([
147
- cb => q._stats.clear (cb),
148
- cb => {q.pause (true); cb ();},
149
-
150
- cb => async.parallel ([
151
- cb => setTimeout (() => q.pop ('me', {timeout: 2000}, err => cb (null, err)), 100),
152
- cb => setTimeout (() => q.push ({q:0, a: 'ryetyeryre 0'}, cb), 200),
153
- ], cb),
154
-
155
- cb => setTimeout (cb, 1000),
156
-
157
- cb => q.stats((err, res) => {
158
- if (err) return cb (err);
159
- cb (null, _.cloneDeep (res))
160
- }),
161
- cb => q.size (cb),
162
-
163
- cb => {q.pause (false); cb ();},
164
- cb => q.pop ('me', cb),
165
-
166
- cb => q._stats.clear (cb)
167
- ], (err, res) => {
168
- if (err) return done (err);
169
- res[4].should.match ({ put: 1 });
170
- res[5].should.equal (1);
171
- res[2][0].timeout.should.eql (true);
172
- res[7].payload.should.eql ({q:0, a: 'ryetyeryre 0'});
173
-
174
- q.nConsumers().should.equal (0);
175
-
176
- done ();
177
- });
178
- });
179
-
180
- it ('consumer with timeout times out ok if queue is paused while waiting for delayed item', done => {
181
- var q = factory.queue('_test_3_queue_', {});
182
-
183
- async.series ([
184
- cb => q._stats.clear (cb),
185
- cb => q.push ({q:0, a: 'ryetyeryre 0'}, {delay: 3}, cb),
186
- cb => {q.pause (true); cb ();},
187
- cb => setTimeout (cb, 100),
188
-
189
- cb => q.pop ('me', {timeout: 1000}, err => cb (null, err)),
190
-
191
- cb => setTimeout (cb, 1000),
192
-
193
- cb => q.stats((err, res) => {
194
- if (err) return cb (err);
195
- cb (null, _.cloneDeep (res))
196
- }),
197
- cb => q.totalSize (cb),
198
-
199
- cb => {q.pause (false); cb ();},
200
- cb => q.pop ('me', cb),
201
-
202
- cb => q._stats.clear (cb)
203
- ], (err, res) => {
204
- if (err) return done (err);
205
- res[6].should.match ({ put: 1 });
206
- res[7].should.equal (1);
207
- res[4].timeout.should.eql (true);
208
- res[9].payload.should.eql ({q:0, a: 'ryetyeryre 0'});
209
-
210
- q.nConsumers().should.equal (0);
211
-
212
- done ();
213
- });
214
- });
215
-
216
- });
217
- });
218
- });
219
- });
220
-