@@ -21,6 +21,7 @@ import {
2121 Routes ,
2222} from ".." ;
2323import { RedisCluster } from "../../utils/TestUtils.js" ;
24+ import { FlushMode } from "../build-ts/src/commands/FlushMode" ;
2425import { checkIfServerVersionLessThan , runBaseTests } from "./SharedTests" ;
2526import {
2627 checkClusterResponse ,
@@ -35,7 +36,6 @@ import {
3536 parseEndpoints ,
3637 transactionTest ,
3738} from "./TestUtilities" ;
38- import { FlushMode } from "../build-ts/src/commands/FlushMode" ;
3939type Context = {
4040 client : GlideClusterClient ;
4141} ;
@@ -675,12 +675,118 @@ describe("GlideClusterClient", () => {
675675 ( value ) => expect ( value ) . toEqual ( 2 ) ,
676676 ) ;
677677 } finally {
678- expect (
678+ expect ( await client . functionFlush ( ) ) . toEqual (
679+ "OK" ,
680+ ) ;
681+ client . close ( ) ;
682+ }
683+ } ,
684+ TIMEOUT ,
685+ ) ;
686+ } ,
687+ ) ;
688+ } ,
689+ ) ;
690+
691+ describe . each ( [ ProtocolVersion . RESP2 , ProtocolVersion . RESP3 ] ) (
692+ "Protocol is RESP2 = %s" ,
693+ ( protocol ) => {
694+ describe . each ( [ true , false ] ) (
695+ "Single node route = %s" ,
696+ ( singleNodeRoute ) => {
697+ it (
698+ "function flush" ,
699+ async ( ) => {
700+ if ( await checkIfServerVersionLessThan ( "7.0.0" ) )
701+ return ;
702+
703+ const client =
704+ await GlideClusterClient . createClient (
705+ getClientConfigurationOption (
706+ cluster . getAddresses ( ) ,
707+ protocol ,
708+ ) ,
709+ ) ;
710+
711+ try {
712+ const libName =
713+ "mylib1C" + uuidv4 ( ) . replaceAll ( "-" , "" ) ;
714+ const funcName =
715+ "myfunc1c" + uuidv4 ( ) . replaceAll ( "-" , "" ) ;
716+ const code = generateLuaLibCode (
717+ libName ,
718+ new Map ( [ [ funcName , "return args[1]" ] ] ) ,
719+ true ,
720+ ) ;
721+ const route : Routes = singleNodeRoute
722+ ? { type : "primarySlotKey" , key : "1" }
723+ : "allPrimaries" ;
724+
725+ // TODO use commands instead of customCommand once implemented
726+ // verify function does not yet exist
727+ const functionList1 =
679728 await client . customCommand ( [
680729 "FUNCTION" ,
681- "FLUSH" ,
682- ] ) ,
730+ "LIST" ,
731+ "LIBRARYNAME" ,
732+ libName ,
733+ ] ) ;
734+ checkClusterResponse (
735+ functionList1 as object ,
736+ singleNodeRoute ,
737+ ( value ) => expect ( value ) . toEqual ( [ ] ) ,
738+ ) ;
739+
740+ // load the library
741+ checkSimple (
742+ await client . functionLoad (
743+ code ,
744+ undefined ,
745+ route ,
746+ ) ,
747+ ) . toEqual ( libName ) ;
748+
749+ // flush functions
750+ expect (
751+ await client . functionFlush (
752+ FlushMode . SYNC ,
753+ route ,
754+ ) ,
755+ ) . toEqual ( "OK" ) ;
756+ expect (
757+ await client . functionFlush (
758+ FlushMode . ASYNC ,
759+ route ,
760+ ) ,
683761 ) . toEqual ( "OK" ) ;
762+
763+ // TODO use commands instead of customCommand once implemented
764+ // verify function does not exist
765+ const functionList2 =
766+ await client . customCommand ( [
767+ "FUNCTION" ,
768+ "LIST" ,
769+ "LIBRARYNAME" ,
770+ libName ,
771+ ] ) ;
772+ checkClusterResponse (
773+ functionList2 as object ,
774+ singleNodeRoute ,
775+ ( value ) => expect ( value ) . toEqual ( [ ] ) ,
776+ ) ;
777+
778+ // Attempt to re-load library without overwriting to ensure FLUSH was effective
779+ checkSimple (
780+ await client . functionLoad (
781+ code ,
782+ undefined ,
783+ route ,
784+ ) ,
785+ ) . toEqual ( libName ) ;
786+ } finally {
787+ expect ( await client . functionFlush ( ) ) . toEqual (
788+ "OK" ,
789+ ) ;
684790 client . close ( ) ;
685791 }
686792 } ,
0 commit comments