@@ -14,6 +14,7 @@ import {
1414 InsertPosition ,
1515 ProtocolVersion ,
1616 RequestError ,
17+ ScoreFilter ,
1718 Script ,
1819 parseInfoResponse ,
1920} from "../" ;
@@ -4545,6 +4546,71 @@ export function runBaseTests<Context>(config: {
45454546 } ,
45464547 config . timeout ,
45474548 ) ;
4549+
4550+ it . each ( [ ProtocolVersion . RESP2 , ProtocolVersion . RESP3 ] ) (
4551+ `zmpop test_%p` ,
4552+ async ( protocol ) => {
4553+ await runTest ( async ( client : BaseClient ) => {
4554+ if ( await checkIfServerVersionLessThan ( "7.0.0" ) ) return ;
4555+ const key1 = "{key}-1" + uuidv4 ( ) ;
4556+ const key2 = "{key}-2" + uuidv4 ( ) ;
4557+ const nonExistingKey = "{key}-0" + uuidv4 ( ) ;
4558+ const stringKey = "{key}-string" + uuidv4 ( ) ;
4559+
4560+ expect ( await client . zadd ( key1 , { a1 : 1 , b1 : 2 } ) ) . toEqual ( 2 ) ;
4561+ expect ( await client . zadd ( key2 , { a2 : 0.1 , b2 : 0.2 } ) ) . toEqual (
4562+ 2 ,
4563+ ) ;
4564+
4565+ checkSimple (
4566+ await client . zmpop ( [ key1 , key2 ] , ScoreFilter . MAX ) ,
4567+ ) . toEqual ( [ key1 , { b1 : 2 } ] ) ;
4568+ checkSimple (
4569+ await client . zmpop ( [ key2 , key1 ] , ScoreFilter . MAX , 10 ) ,
4570+ ) . toEqual ( [ key2 , { a2 : 0.1 , b2 : 0.2 } ] ) ;
4571+
4572+ expect ( await client . zmpop ( [ nonExistingKey ] , ScoreFilter . MIN ) )
4573+ . toBeNull ;
4574+ expect ( await client . zmpop ( [ nonExistingKey ] , ScoreFilter . MIN , 1 ) )
4575+ . toBeNull ;
4576+
4577+ // key exists, but it is not a sorted set
4578+ expect ( await client . set ( stringKey , "value" ) ) . toEqual ( "OK" ) ;
4579+ await expect (
4580+ client . zmpop ( [ stringKey ] , ScoreFilter . MAX ) ,
4581+ ) . rejects . toThrow ( RequestError ) ;
4582+ await expect (
4583+ client . zmpop ( [ stringKey ] , ScoreFilter . MAX , 1 ) ,
4584+ ) . rejects . toThrow ( RequestError ) ;
4585+
4586+ // incorrect argument: key list should not be empty
4587+ await expect (
4588+ client . zmpop ( [ ] , ScoreFilter . MAX , 1 ) ,
4589+ ) . rejects . toThrow ( RequestError ) ;
4590+
4591+ // incorrect argument: count should be greater than 0
4592+ await expect (
4593+ client . zmpop ( [ key1 ] , ScoreFilter . MAX , 0 ) ,
4594+ ) . rejects . toThrow ( RequestError ) ;
4595+
4596+ // check that order of entries in the response is preserved
4597+ const entries : Record < string , number > = { } ;
4598+
4599+ for ( let i = 0 ; i < 10 ; i ++ ) {
4600+ // a0 => 0, a1 => 1 etc
4601+ entries [ "a" + i ] = i ;
4602+ }
4603+
4604+ expect ( await client . zadd ( key2 , entries ) ) . toEqual ( 10 ) ;
4605+ const result = await client . zmpop ( [ key2 ] , ScoreFilter . MIN , 10 ) ;
4606+
4607+ if ( result ) {
4608+ expect ( result [ 1 ] ) . toEqual ( entries ) ;
4609+ }
4610+ } , protocol ) ;
4611+ } ,
4612+ config . timeout ,
4613+ ) ;
45484614}
45494615
45504616export function runCommonTests < Context > ( config : {
0 commit comments