1
1
import { strict as assert } from 'node:assert' ;
2
2
import testUtils , { GLOBAL , waitTillBeenCalled } from '../test-utils' ;
3
3
import RedisClient , { RedisClientType } from '.' ;
4
- // import { RedisClientMultiCommandType } from './multi-command';
5
- // import { RedisCommandRawReply, RedisModules, RedisFunctions, RedisScripts } from '../commands';
6
4
import { AbortError , ClientClosedError , ClientOfflineError , ConnectionTimeoutError , DisconnectsClientError , ErrorReply , MultiErrorReply , SocketClosedUnexpectedlyError , WatchError } from '../errors' ;
7
5
import { defineScript } from '../lua-script' ;
8
6
import { spy } from 'sinon' ;
9
7
import { once } from 'node:events' ;
10
- // import { ClientKillFilters } from '../commands/CLIENT_KILL';
11
- // import { promisify } from 'node:util';
12
8
import { MATH_FUNCTION , loadMathFunction } from '../commands/FUNCTION_LOAD.spec' ;
13
9
import { RESP_TYPES } from '../RESP/decoder' ;
14
- import { NumberReply } from '../RESP/types' ;
10
+ import { BlobStringReply , NumberReply } from '../RESP/types' ;
15
11
import { SortedSetMember } from '../commands/generic-transformers' ;
16
12
17
13
export const SQUARE_SCRIPT = defineScript ( {
@@ -232,24 +228,26 @@ describe('Client', () => {
232
228
}
233
229
} ) ;
234
230
235
- // testUtils.testWithClient('WatchError', async client => {
236
- // await client.watch('key');
237
-
238
- // await client.set(
239
- // RedisClient.commandOptions({
240
- // isolated: true
241
- // }),
242
- // 'key',
243
- // '1'
244
- // );
245
-
246
- // await assert.rejects(
247
- // client.multi()
248
- // .decr('key')
249
- // .exec(),
250
- // WatchError
251
- // );
252
- // }, GLOBAL.SERVERS.OPEN);
231
+ testUtils . testWithClient ( 'WatchError' , async client => {
232
+ await client . watch ( 'key' ) ;
233
+
234
+ const duplicate = await client . duplicate ( ) . connect ( ) ;
235
+ try {
236
+ await client . set (
237
+ 'key' ,
238
+ '1'
239
+ ) ;
240
+ } finally {
241
+ duplicate . destroy ( ) ;
242
+ }
243
+
244
+ await assert . rejects (
245
+ client . multi ( )
246
+ . decr ( 'key' )
247
+ . exec ( ) ,
248
+ WatchError
249
+ ) ;
250
+ } , GLOBAL . SERVERS . OPEN ) ;
253
251
254
252
describe ( 'execAsPipeline' , ( ) => {
255
253
testUtils . testWithClient ( 'exec(true)' , async client => {
@@ -269,20 +267,19 @@ describe('Client', () => {
269
267
} , GLOBAL . SERVERS . OPEN ) ;
270
268
} ) ;
271
269
272
- // testUtils.testWithClient('should remember selected db', async client => {
273
- // await client.multi()
274
- // .select(1)
275
- // .exec();
276
- // await killClient(client);
277
- // assert.equal(
278
- // (await client.clientInfo()).db,
279
- // 1
280
- // );
281
- // }, {
282
- // ...GLOBAL.SERVERS.OPEN,
283
- // minimumDockerVersion: [6, 2] // CLIENT INFO
284
- // });
285
-
270
+ testUtils . testWithClient ( 'should remember selected db' , async client => {
271
+ await client . multi ( )
272
+ . select ( 1 )
273
+ . exec ( ) ;
274
+ await killClient ( client ) ;
275
+ assert . equal (
276
+ ( await client . clientInfo ( ) ) . db ,
277
+ 1
278
+ ) ;
279
+ } , {
280
+ ...GLOBAL . SERVERS . OPEN ,
281
+ minimumDockerVersion : [ 6 , 2 ] // CLIENT INFO
282
+ } ) ;
286
283
287
284
testUtils . testWithClient ( 'should handle error replies (#2665)' , async client => {
288
285
await assert . rejects (
@@ -320,12 +317,10 @@ describe('Client', () => {
320
317
321
318
const module = {
322
319
echo : {
323
- transformArguments ( message : string ) : Array < string > {
320
+ transformArguments ( message : string ) {
324
321
return [ 'ECHO' , message ] ;
325
322
} ,
326
- transformReply ( reply : string ) : string {
327
- return reply ;
328
- }
323
+ transformReply : undefined as unknown as ( ) => BlobStringReply
329
324
}
330
325
} ;
331
326
@@ -386,81 +381,34 @@ describe('Client', () => {
386
381
disableClientSetup : true ,
387
382
} ) ;
388
383
389
- // describe('isolationPool', () => {
390
- // testUtils.testWithClient('executeIsolated', async client => {
391
- // const id = await client.clientId(),
392
- // isolatedId = await client.executeIsolated(isolatedClient => isolatedClient.clientId());
393
- // assert.ok(id !== isolatedId);
394
- // }, GLOBAL.SERVERS.OPEN);
395
-
396
- // testUtils.testWithClient('should be able to use pool even before connect', async client => {
397
- // await client.executeIsolated(() => Promise.resolve());
398
- // // make sure to destroy isolation pool
399
- // await client.connect();
400
- // await client.disconnect();
401
- // }, {
402
- // ...GLOBAL.SERVERS.OPEN,
403
- // disableClientSetup: true
404
- // });
405
-
406
- // testUtils.testWithClient('should work after reconnect (#2406)', async client => {
407
- // await client.disconnect();
408
- // await client.connect();
409
- // await client.executeIsolated(() => Promise.resolve());
410
- // }, GLOBAL.SERVERS.OPEN);
411
-
412
- // testUtils.testWithClient('should throw ClientClosedError after disconnect', async client => {
413
- // await client.connect();
414
- // await client.disconnect();
415
- // await assert.rejects(
416
- // client.executeIsolated(() => Promise.resolve()),
417
- // ClientClosedError
418
- // );
419
- // }, {
420
- // ...GLOBAL.SERVERS.OPEN,
421
- // disableClientSetup: true
422
- // });
423
- // });
424
-
425
- // async function killClient<
426
- // M extends RedisModules,
427
- // F extends RedisFunctions,
428
- // S extends RedisScripts
429
- // >(
430
- // client: RedisClientType<M, F, S>,
431
- // errorClient: RedisClientType<M, F, S> = client
432
- // ): Promise<void> {
433
- // const onceErrorPromise = once(errorClient, 'error');
434
- // await client.sendCommand(['QUIT']);
435
- // await Promise.all([
436
- // onceErrorPromise,
437
- // assert.rejects(client.ping(), SocketClosedUnexpectedlyError)
438
- // ]);
439
- // }
440
-
441
- // testUtils.testWithClient('should reconnect when socket disconnects', async client => {
442
- // await killClient(client);
443
- // await assert.doesNotReject(client.ping());
444
- // }, GLOBAL.SERVERS.OPEN);
445
-
446
- // testUtils.testWithClient('should remember selected db', async client => {
447
- // await client.select(1);
448
- // await killClient(client);
449
- // assert.equal(
450
- // (await client.clientInfo()).db,
451
- // 1
452
- // );
453
- // }, {
454
- // ...GLOBAL.SERVERS.OPEN,
455
- // minimumDockerVersion: [6, 2] // CLIENT INFO
456
- // });
457
-
458
- // testUtils.testWithClient('should propagated errors from "isolated" clients', client => {
459
- // client.on('error', () => {
460
- // // ignore errors
461
- // });
462
- // return client.executeIsolated(isolated => killClient(isolated, client));
463
- // }, GLOBAL.SERVERS.OPEN);
384
+ async function killClient (
385
+ client : RedisClientType < any , any , any , any , any > ,
386
+ errorClient : RedisClientType < any , any , any , any , any > = client
387
+ ) : Promise < void > {
388
+ const onceErrorPromise = once ( errorClient , 'error' ) ;
389
+ await client . sendCommand ( [ 'QUIT' ] ) ;
390
+ await Promise . all ( [
391
+ onceErrorPromise ,
392
+ assert . rejects ( client . ping ( ) , SocketClosedUnexpectedlyError )
393
+ ] ) ;
394
+ }
395
+
396
+ testUtils . testWithClient ( 'should reconnect when socket disconnects' , async client => {
397
+ await killClient ( client ) ;
398
+ await assert . doesNotReject ( client . ping ( ) ) ;
399
+ } , GLOBAL . SERVERS . OPEN ) ;
400
+
401
+ testUtils . testWithClient ( 'should remember selected db' , async client => {
402
+ await client . select ( 1 ) ;
403
+ await killClient ( client ) ;
404
+ assert . equal (
405
+ ( await client . clientInfo ( ) ) . db ,
406
+ 1
407
+ ) ;
408
+ } , {
409
+ ...GLOBAL . SERVERS . OPEN ,
410
+ minimumDockerVersion : [ 6 , 2 ] // CLIENT INFO
411
+ } ) ;
464
412
465
413
testUtils . testWithClient ( 'scanIterator' , async client => {
466
414
const entries : Array < string > = [ ] ,
0 commit comments