|
| 1 | +import { strict as assert } from 'node:assert'; |
| 2 | +import XNACK from './XNACK'; |
| 3 | +import { parseArgs } from './generic-transformers'; |
| 4 | +import testUtils, { GLOBAL } from '../test-utils'; |
| 5 | + |
| 6 | +describe('XNACK', () => { |
| 7 | + describe('transformArguments', () => { |
| 8 | + it('string - SILENT', () => { |
| 9 | + assert.deepEqual( |
| 10 | + parseArgs(XNACK, 'key', 'group', 'SILENT', '0-0'), |
| 11 | + ['XNACK', 'key', 'group', 'SILENT', 'IDS', '1', '0-0'] |
| 12 | + ); |
| 13 | + }); |
| 14 | + |
| 15 | + it('array - FAIL', () => { |
| 16 | + assert.deepEqual( |
| 17 | + parseArgs(XNACK, 'key', 'group', 'FAIL', ['0-0', '1-0']), |
| 18 | + ['XNACK', 'key', 'group', 'FAIL', 'IDS', '2', '0-0', '1-0'] |
| 19 | + ); |
| 20 | + }); |
| 21 | + |
| 22 | + it('array - FATAL', () => { |
| 23 | + assert.deepEqual( |
| 24 | + parseArgs(XNACK, 'key', 'group', 'FATAL', ['0-0', '1-0', '2-0']), |
| 25 | + ['XNACK', 'key', 'group', 'FATAL', 'IDS', '3', '0-0', '1-0', '2-0'] |
| 26 | + ); |
| 27 | + }); |
| 28 | + |
| 29 | + it('with RETRYCOUNT', () => { |
| 30 | + assert.deepEqual( |
| 31 | + parseArgs(XNACK, 'key', 'group', 'FAIL', '0-0', { |
| 32 | + RETRYCOUNT: 7 |
| 33 | + }), |
| 34 | + ['XNACK', 'key', 'group', 'FAIL', 'IDS', '1', '0-0', 'RETRYCOUNT', '7'] |
| 35 | + ); |
| 36 | + }); |
| 37 | + |
| 38 | + it('with FORCE', () => { |
| 39 | + assert.deepEqual( |
| 40 | + parseArgs(XNACK, 'key', 'group', 'FAIL', ['0-0', '1-0'], { |
| 41 | + FORCE: true |
| 42 | + }), |
| 43 | + ['XNACK', 'key', 'group', 'FAIL', 'IDS', '2', '0-0', '1-0', 'FORCE'] |
| 44 | + ); |
| 45 | + }); |
| 46 | + |
| 47 | + it('with RETRYCOUNT and FORCE', () => { |
| 48 | + assert.deepEqual( |
| 49 | + parseArgs(XNACK, 'key', 'group', 'FAIL', ['0-0', '1-0'], { |
| 50 | + RETRYCOUNT: 3, |
| 51 | + FORCE: true |
| 52 | + }), |
| 53 | + ['XNACK', 'key', 'group', 'FAIL', 'IDS', '2', '0-0', '1-0', 'RETRYCOUNT', '3', 'FORCE'] |
| 54 | + ); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + testUtils.testWithClient('xNack', async client => { |
| 59 | + |
| 60 | + const key = `xnack:tmp:${Date.now()}`; |
| 61 | + const group = 'group'; |
| 62 | + const consumer = 'consumer-1'; |
| 63 | + |
| 64 | + await client.del(key); |
| 65 | + await client.xGroupCreate(key, group, '0', { MKSTREAM: true }); |
| 66 | + |
| 67 | + const id1 = await client.xAdd(key, '*', { field: '1' }); |
| 68 | + const id2 = await client.xAdd(key, '*', { field: '2' }); |
| 69 | + const id3 = await client.xAdd(key, '*', { field: '3' }); |
| 70 | + const id4 = await client.xAdd(key, '*', { field: '4' }); |
| 71 | + const id5 = await client.xAdd(key, '*', { field: '5' }); |
| 72 | + const id6 = await client.xAdd(key, '*', { field: '6' }); |
| 73 | + |
| 74 | + await client.xReadGroup(group, consumer, { |
| 75 | + key, |
| 76 | + id: '>' |
| 77 | + }); |
| 78 | + |
| 79 | + const reply = await client.xNack(key, group, 'FAIL', [id1, id2]); |
| 80 | + const replyWithRetryCount = await client.xNack(key, group, 'FAIL', id3, { |
| 81 | + RETRYCOUNT: 7 |
| 82 | + }); |
| 83 | + const replyWithForce = await client.xNack(key, group, 'FAIL', id4, { |
| 84 | + FORCE: true |
| 85 | + }); |
| 86 | + const replyWithRetryCountAndForce = await client.xNack(key, group, 'FAIL', [id5, id6], { |
| 87 | + RETRYCOUNT: 3, |
| 88 | + FORCE: true |
| 89 | + }); |
| 90 | + |
| 91 | + assert.equal(reply, 2); |
| 92 | + assert.equal(replyWithRetryCount, 1); |
| 93 | + assert.equal(replyWithForce, 1); |
| 94 | + assert.equal(replyWithRetryCountAndForce, 2); |
| 95 | + |
| 96 | + assert.equal(typeof reply, 'number'); |
| 97 | + assert.equal(typeof replyWithRetryCount, 'number'); |
| 98 | + assert.equal(typeof replyWithForce, 'number'); |
| 99 | + assert.equal(typeof replyWithRetryCountAndForce, 'number'); |
| 100 | + }, { |
| 101 | + ...GLOBAL.SERVERS.OPEN, |
| 102 | + minimumDockerVersion: [8, 8] |
| 103 | + }); |
| 104 | + |
| 105 | +}); |
0 commit comments