Skip to content

Commit f7fac1b

Browse files
committed
more tests
Signed-off-by: xbasel <[email protected]>
1 parent 5cc7714 commit f7fac1b

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

src/unit/test_files.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ int test_demotion_ht_to_single(int argc, char **argv, int flags);
204204
int test_update_same_bucket_noop(int argc, char **argv, int flags);
205205
int test_update_entry_within_same_bucket(int argc, char **argv, int flags);
206206
int test_update_entry_across_buckets(int argc, char **argv, int flags);
207+
int test_bucket_order_by_expiry(int argc, char **argv, int flags);
208+
int test_bucket_lookup_strictly_below(int argc, char **argv, int flags);
207209
int test_ziplistCreateIntList(int argc, char **argv, int flags);
208210
int test_ziplistPop(int argc, char **argv, int flags);
209211
int test_ziplistGetElementAtIndex3(int argc, char **argv, int flags);
@@ -265,6 +267,7 @@ unitTest __test_util_c[] = {{"test_string2ll", test_string2ll}, {"test_string2l"
265267
unitTest __test_valkey_strtod_c[] = {{"test_valkey_strtod", test_valkey_strtod}, {NULL, NULL}};
266268
unitTest __test_vector_c[] = {{"test_vector", test_vector}, {NULL, NULL}};
267269
unitTest __test_volatile_set_c[] = {{"test_basic", test_basic}, {"test_update_entry", test_update_entry}, {"test_hashtable", test_hashtable}, {"test_promotion", test_promotion}, {"test_demotion_ht_to_single", test_demotion_ht_to_single}, {"test_update_same_bucket_noop", test_update_same_bucket_noop}, {"test_update_entry_within_same_bucket", test_update_entry_within_same_bucket}, {"test_update_entry_across_buckets", test_update_entry_across_buckets}, {NULL, NULL}};
270+
unitTest __test_volatile_set_c[] = {{"test_basic", test_basic}, {"test_update_entry", test_update_entry}, {"test_hashtable", test_hashtable}, {"test_promotion", test_promotion}, {"test_demotion_ht_to_single", test_demotion_ht_to_single}, {"test_update_same_bucket_noop", test_update_same_bucket_noop}, {"test_update_entry_within_same_bucket", test_update_entry_within_same_bucket}, {"test_update_entry_across_buckets", test_update_entry_across_buckets}, {"test_bucket_order_by_expiry", test_bucket_order_by_expiry}, {"test_bucket_lookup_strictly_below", test_bucket_lookup_strictly_below}, {NULL, NULL}};
268271
unitTest __test_ziplist_c[] = {{"test_ziplistCreateIntList", test_ziplistCreateIntList}, {"test_ziplistPop", test_ziplistPop}, {"test_ziplistGetElementAtIndex3", test_ziplistGetElementAtIndex3}, {"test_ziplistGetElementOutOfRange", test_ziplistGetElementOutOfRange}, {"test_ziplistGetLastElement", test_ziplistGetLastElement}, {"test_ziplistGetFirstElement", test_ziplistGetFirstElement}, {"test_ziplistGetElementOutOfRangeReverse", test_ziplistGetElementOutOfRangeReverse}, {"test_ziplistIterateThroughFullList", test_ziplistIterateThroughFullList}, {"test_ziplistIterateThroughListFrom1ToEnd", test_ziplistIterateThroughListFrom1ToEnd}, {"test_ziplistIterateThroughListFrom2ToEnd", test_ziplistIterateThroughListFrom2ToEnd}, {"test_ziplistIterateThroughStartOutOfRange", test_ziplistIterateThroughStartOutOfRange}, {"test_ziplistIterateBackToFront", test_ziplistIterateBackToFront}, {"test_ziplistIterateBackToFrontDeletingAllItems", test_ziplistIterateBackToFrontDeletingAllItems}, {"test_ziplistDeleteInclusiveRange0To0", test_ziplistDeleteInclusiveRange0To0}, {"test_ziplistDeleteInclusiveRange0To1", test_ziplistDeleteInclusiveRange0To1}, {"test_ziplistDeleteInclusiveRange1To2", test_ziplistDeleteInclusiveRange1To2}, {"test_ziplistDeleteWithStartIndexOutOfRange", test_ziplistDeleteWithStartIndexOutOfRange}, {"test_ziplistDeleteWithNumOverflow", test_ziplistDeleteWithNumOverflow}, {"test_ziplistDeleteFooWhileIterating", test_ziplistDeleteFooWhileIterating}, {"test_ziplistReplaceWithSameSize", test_ziplistReplaceWithSameSize}, {"test_ziplistReplaceWithDifferentSize", test_ziplistReplaceWithDifferentSize}, {"test_ziplistRegressionTestForOver255ByteStrings", test_ziplistRegressionTestForOver255ByteStrings}, {"test_ziplistRegressionTestDeleteNextToLastEntries", test_ziplistRegressionTestDeleteNextToLastEntries}, {"test_ziplistCreateLongListAndCheckIndices", test_ziplistCreateLongListAndCheckIndices}, {"test_ziplistCompareStringWithZiplistEntries", test_ziplistCompareStringWithZiplistEntries}, {"test_ziplistMergeTest", test_ziplistMergeTest}, {"test_ziplistStressWithRandomPayloadsOfDifferentEncoding", test_ziplistStressWithRandomPayloadsOfDifferentEncoding}, {"test_ziplistCascadeUpdateEdgeCases", test_ziplistCascadeUpdateEdgeCases}, {"test_ziplistInsertEdgeCase", test_ziplistInsertEdgeCase}, {"test_ziplistStressWithVariableSize", test_ziplistStressWithVariableSize}, {"test_BenchmarkziplistFind", test_BenchmarkziplistFind}, {"test_BenchmarkziplistIndex", test_BenchmarkziplistIndex}, {"test_BenchmarkziplistValidateIntegrity", test_BenchmarkziplistValidateIntegrity}, {"test_BenchmarkziplistCompareWithString", test_BenchmarkziplistCompareWithString}, {"test_BenchmarkziplistCompareWithNumber", test_BenchmarkziplistCompareWithNumber}, {"test_ziplistStress__ziplistCascadeUpdate", test_ziplistStress__ziplistCascadeUpdate}, {NULL, NULL}};
269272
unitTest __test_zipmap_c[] = {{"test_zipmapIterateWithLargeKey", test_zipmapIterateWithLargeKey}, {"test_zipmapIterateThroughElements", test_zipmapIterateThroughElements}, {NULL, NULL}};
270273
unitTest __test_zmalloc_c[] = {{"test_zmallocInitialUsedMemory", test_zmallocInitialUsedMemory}, {"test_zmallocAllocReallocCallocAndFree", test_zmallocAllocReallocCallocAndFree}, {"test_zmallocAllocZeroByteAndFree", test_zmallocAllocZeroByteAndFree}, {NULL, NULL}};

src/unit/test_volatile_set.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,3 +441,78 @@ static void crash_duplicate_in_hashtable(void) {
441441
//
442442
// return 0;
443443
// }
444+
445+
int test_bucket_order_by_expiry(int argc, char **argv, int flags) {
446+
UNUSED(argc); UNUSED(argv); UNUSED(flags);
447+
448+
volatile_set *vset = createVolatileSet(NULL);
449+
450+
long long expiries[] = {180000, 60000, 120000}; // intentionally unordered
451+
long long expected[] = {60000, 120000, 180000};
452+
453+
for (int i = 0; i < 3; i++) {
454+
char f[16], v[16];
455+
snprintf(f, sizeof(f), "f%lld", expiries[i]);
456+
snprintf(v, sizeof(v), "v%lld", expiries[i]);
457+
entry *e = entryCreate(createSds(f), createSds(v), expiries[i]);
458+
TEST_ASSERT(volatileSetAddEntry(vset, e, expiries[i]) == 1);
459+
}
460+
461+
raxIterator ri;
462+
raxStart(&ri, vset->expiry_buckets);
463+
raxSeek(&ri, ">=", NULL, 0);
464+
465+
int i = 0;
466+
while (raxNext(&ri)) {
467+
long long ts;
468+
memcpy(&ts, ri.key, sizeof(ts));
469+
ts = ntohu64(ts); // convert back from BE
470+
TEST_ASSERT(ts == expected[i]);
471+
i++;
472+
}
473+
TEST_ASSERT(i == 3); // Ensure we saw all buckets
474+
475+
raxStop(&ri);
476+
freeVolatileSet(vset);
477+
return 0;
478+
}
479+
480+
int test_bucket_lookup_strictly_below(int argc, char **argv, int flags) {
481+
UNUSED(argc); UNUSED(argv); UNUSED(flags);
482+
483+
volatile_set *vset = createVolatileSet(NULL);
484+
long long buckets[] = {60000, 120000, 180000};
485+
entry *e[3];
486+
487+
for (int i = 0; i < 3; i++) {
488+
char f[16], v[16];
489+
snprintf(f, sizeof(f), "f%lld", buckets[i]);
490+
snprintf(v, sizeof(v), "v%lld", buckets[i]);
491+
e[i] = entryCreate(createSds(f), createSds(v), buckets[i]);
492+
TEST_ASSERT(volatileSetAddEntry(vset, e[i], buckets[i]) == 1);
493+
}
494+
495+
// Try to find the bucket just below or equal to 119000 → should get 60000
496+
long long lookup_ts = 119000;
497+
unsigned char lookup_key[VSET_BUCKET_KEY_LEN] = {0};
498+
encodeExpiryBucketKey(lookup_key, lookup_ts);
499+
500+
raxIterator ri;
501+
raxStart(&ri, vset->expiry_buckets);
502+
raxSeek(&ri, ">=", lookup_key, sizeof(long long));
503+
504+
if (!raxPrev(&ri)) {
505+
TEST_ASSERT(!"Expected to find bucket below");
506+
} else {
507+
long long ts;
508+
memcpy(&ts, ri.key, sizeof(ts));
509+
ts = ntohu64(ts);
510+
511+
TEST_ASSERT(ts == 60000);
512+
// TEST_ASSERT(ri.data == e[0]); // matches entry at 60000
513+
}
514+
515+
raxStop(&ri);
516+
freeVolatileSet(vset);
517+
return 0;
518+
}

0 commit comments

Comments
 (0)