Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit 711180b

Browse files
committed
add 'PFADD/PFCOUNT simple test'
1 parent bc66391 commit 711180b

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/vr_hyperloglog.c

+1
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,7 @@ void pfcountCommand(client *c) {
12761276
* we need to propagate the change. */
12771277
signalModifiedKey(c->db,c->argv[1]);
12781278
server.dirty++;
1279+
c->vel->dirty++;
12791280
}
12801281
addReplyLongLong(c,card);
12811282
}

tests/vrt_simple.c

+57
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,61 @@ static int simple_test_cmd_hdel(vire_instance *vi)
12961296
return 0;
12971297
}
12981298

1299+
static int simple_test_cmd_pfadd_pfcount(vire_instance *vi)
1300+
{
1301+
char *key = "test_cmd_pfadd_pfcount-key";
1302+
char *value = "test_cmd_pfadd_pfcount-value";
1303+
char *MESSAGE = "PFADD/PFCOUNT simple test";
1304+
redisReply * reply = NULL;
1305+
int n = 0, count = 20329, repeat;
1306+
1307+
while (repeat < 2) {
1308+
int expect_count;
1309+
reply = redisCommand(vi->ctx, "pfadd %s %s%d", key, value, n++);
1310+
if (reply == NULL || reply->type != REDIS_REPLY_INTEGER) {
1311+
goto error;
1312+
}
1313+
freeReplyObject(reply);
1314+
if (n >= count) {
1315+
repeat++;
1316+
n = 0;
1317+
}
1318+
1319+
if (repeat == 0) {
1320+
expect_count = n;
1321+
} else {
1322+
expect_count = count;
1323+
}
1324+
1325+
reply = redisCommand(vi->ctx, "pfcount %s", key);
1326+
if (reply == NULL || reply->type != REDIS_REPLY_INTEGER) {
1327+
goto error;
1328+
}
1329+
if (reply->integer != (long long)expect_count) {
1330+
float mistake = ((float)expect_count-(float)reply->integer)/(float)expect_count;
1331+
if (mistake < -0.02 || mistake > 0.02) {
1332+
vrt_scnprintf(errmsg, LOG_MAX_LEN, "pfadd %d different elements is not approximated pfcount returned %lld, mistake %f",
1333+
expect_count, reply->integer, mistake);
1334+
goto error;
1335+
}
1336+
}
1337+
freeReplyObject(reply);
1338+
}
1339+
1340+
show_test_result(VRT_TEST_OK,MESSAGE,errmsg);
1341+
1342+
return 1;
1343+
1344+
error:
1345+
1346+
if (reply) freeReplyObject(reply);
1347+
1348+
show_test_result(VRT_TEST_ERR,MESSAGE,errmsg);
1349+
errmsg[0] = '\0';
1350+
1351+
return 0;
1352+
}
1353+
12991354
int simple_test(void)
13001355
{
13011356
vire_instance *vi;
@@ -1331,6 +1386,8 @@ int simple_test(void)
13311386
ok_count+=simple_test_cmd_hget_hset(vi); all_count++;
13321387
ok_count+=simple_test_cmd_hlen(vi); all_count++;
13331388
ok_count+=simple_test_cmd_hdel(vi); all_count++;
1389+
/* HyperLogLog */
1390+
ok_count+=simple_test_cmd_pfadd_pfcount(vi); all_count++;
13341391

13351392
vire_instance_destroy(vi);
13361393

0 commit comments

Comments
 (0)