Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
moticless committed Jun 13, 2024
1 parent c99f278 commit 8d60a05
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 41 deletions.
61 changes: 33 additions & 28 deletions test/test_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,14 @@ void get_redis_version(redisContext *c, int *majorptr, int *minorptr) {
exit(1);
}

#define MAX_ARGS 50
void setupRedisServer(const char *extraArgs) {

/* If redis not installed return gracefully */
if (!redisInstallFolder) return;

/* execl() not accept empty string */
const char *_extraArgs = (extraArgs) ? extraArgs : "--loglevel verbose";

pid_t pid = fork();
assert_int_not_equal (pid, -1);
assert(pid != -1);

int port = findFreePort(6500, 6600);

Expand All @@ -364,31 +362,38 @@ void setupRedisServer(const char *extraArgs) {
snprintf(testrdbModulePath, sizeof(testrdbModulePath), "%s/../tests/modules/testrdb.so", redisInstallFolder);
snprintf(redisPortStr, sizeof(redisPortStr), "%d", port);

/* if module testrdb.so exists (ci.yaml takes care to build testrdb), part
* of redis repo testing, then load it for test_rdb_to_redis_module. The
* test will run only if testrdb appear in the server "MODULE LIST",
* otherwise skipped gracefully. */
// Tokenize extraArgs and build the arguments list
char *args[MAX_ARGS];
int argIndex = 0;

args[argIndex++] = fullpath;
args[argIndex++] = "--port";
args[argIndex++] = redisPortStr;
args[argIndex++] = "--dir";
args[argIndex++] = "./test/tmp/";
args[argIndex++] = "--logfile";
args[argIndex++] = "./redis.log";

// Add module loading arguments if the module exists
if (access(testrdbModulePath, F_OK) != -1) {
execl(fullpath, fullpath,
"--enable-debug-command", "yes",
"--port", redisPortStr,
"--dir", "./test/tmp/",
"--logfile", "./redis.log",
"--loadmodule", testrdbModulePath, "4",
_extraArgs,
(char *) NULL);
} else {
execl(fullpath, fullpath,
"--enable-debug-command", "yes",
"--port", redisPortStr,
"--dir", "./test/tmp/",
"--logfile", "./redis.log",
_extraArgs,
(char *) NULL);
}

/* If execl returns, an error occurred! */
perror("execl");
args[argIndex++] = "--loadmodule";
args[argIndex++] = testrdbModulePath;
args[argIndex++] = "4";
}

/* Tokenize extraArgs and add to the arguments list */
char *extraArgsCopy = strdup(_extraArgs);
char *token = strtok(extraArgsCopy, " ");
while (token && argIndex < MAX_ARGS - 1) {
args[argIndex++] = token;
token = strtok(NULL, " ");
}
args[argIndex] = NULL;

execvp(fullpath, args);

/* If execvp returns, an error occurred */
perror("execvp");
exit(1);
} else { /* parent */
int retryCount = 3;
Expand Down
30 changes: 17 additions & 13 deletions test/test_rdb_to_redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static void rdb_to_json(const char *rdbfile, const char *outfile) {
* isDigest - if set, compare DB digest before and after reload
* isRestore - if set, use RESTORE command after reload. Otherwise, plain commands
*/
static void rdb_save_librdb_reload_eq(int isRestore) {
static void rdb_save_librdb_reload_eq(int isRestore, char *serverRdbFile) {
char *res;
const char *rdbfile = TMP_FOLDER("reload.rdb");
char expectedSha[100];
Expand All @@ -84,7 +84,7 @@ static void rdb_save_librdb_reload_eq(int isRestore) {
/* Keep aside rdb file */
sendRedisCmd("SAVE", REDIS_REPLY_STATUS, NULL);
runSystemCmd("rm %s || true", rdbfile);
runSystemCmd("cp %s %s > /dev/null", TMP_FOLDER("dump.rdb"), rdbfile);
runSystemCmd("cp %s %s > /dev/null", serverRdbFile, rdbfile);

/* Flush Redis */
sendRedisCmd("FLUSHALL", REDIS_REPLY_STATUS, NULL);
Expand Down Expand Up @@ -194,25 +194,29 @@ static void test_rdb_to_redis_hash_with_expire(void **state) {
if ((serverMajorVer<7) || ((serverMajorVer==7) && (serverMinorVer<4)))
skip();

/* dict (max-lp-entries=0) */
sendRedisCmd("FLUSHALL", REDIS_REPLY_STATUS, NULL);
sendRedisCmd("CONFIG SET HASH-MAX-LISTPACK-ENTRIES 0", REDIS_REPLY_STATUS, NULL);
sendRedisCmd("HSET myhash f1 v1 f2 v2 f3 v3", REDIS_REPLY_INTEGER, "3");
sendRedisCmd("HPEXPIREAT myhash 70368744177663 FIELDS 2 f1 f2", REDIS_REPLY_ARRAY, "1 1");
rdb_save_librdb_reload_eq(0 /*restore*/);
rdb_save_librdb_reload_eq(1 /*restore*/);
sendRedisCmd("HPEXPIRETIME myhash FIELDS 3 f1 f2 f3", REDIS_REPLY_ARRAY,
"70368744177663 70368744177663 -1"); /* verify expected output */
setupRedisServer("--enable-debug-command yes --dbfilename expire.rdb");

/* listpack */
sendRedisCmd("FLUSHALL", REDIS_REPLY_STATUS, NULL);
sendRedisCmd("CONFIG SET HASH-MAX-LISTPACK-ENTRIES 512", REDIS_REPLY_STATUS, NULL);
sendRedisCmd("HSET myhash f4 v1 f5 v2 f6 v3", REDIS_REPLY_INTEGER, "3");
sendRedisCmd("HPEXPIREAT myhash 70368744177663 FIELDS 2 f4 f5", REDIS_REPLY_ARRAY, "1 1");
rdb_save_librdb_reload_eq(0 /*restore*/);
rdb_save_librdb_reload_eq(1 /*restore*/);
rdb_save_librdb_reload_eq(0 /*restore*/, TMP_FOLDER("expire.rdb"));
rdb_save_librdb_reload_eq(1 /*restore*/, TMP_FOLDER("expire.rdb"));
sendRedisCmd("HPEXPIRETIME myhash FIELDS 3 f4 f5 f6", REDIS_REPLY_ARRAY,
"70368744177663 70368744177663 -1"); /* verify expected output */

/* dict (max-lp-entries=0) */
sendRedisCmd("FLUSHALL", REDIS_REPLY_STATUS, NULL);
sendRedisCmd("CONFIG SET HASH-MAX-LISTPACK-ENTRIES 0", REDIS_REPLY_STATUS, NULL);
sendRedisCmd("HSET myhash f4 v1 f5 v2 f6 v3", REDIS_REPLY_INTEGER, "3");
sendRedisCmd("HPEXPIREAT myhash 70368744177663 FIELDS 2 f4 f5", REDIS_REPLY_ARRAY, "1 1");
rdb_save_librdb_reload_eq(0 /*restore*/, TMP_FOLDER("expire.rdb"));
rdb_save_librdb_reload_eq(1 /*restore*/, TMP_FOLDER("expire.rdb"));
sendRedisCmd("HPEXPIRETIME myhash FIELDS 3 f4 f5 f6", REDIS_REPLY_ARRAY,
"70368744177663 70368744177663 -1"); /* verify expected output */

teardownRedisServer();
}

static void test_rdb_to_redis_hash_zl(void **state) {
Expand Down

0 comments on commit 8d60a05

Please sign in to comment.