Skip to content

Commit

Permalink
Fix test_reclaimFilePageCache to avoid tmpfs (#1379)
Browse files Browse the repository at this point in the history
Avoid tmpfs as fadvise(FADV_DONTNEED) has no effect on memory-backed
filesystems.

Fixes #897

---------

Signed-off-by: Ran Shidlansik <[email protected]>
Signed-off-by: ranshid <[email protected]>
Co-authored-by: ranshid <[email protected]>
Co-authored-by: Ran Shidlansik <[email protected]>
  • Loading branch information
3 people authored Dec 17, 2024
1 parent 980a801 commit 7892bf8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/unit/test_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#include "../util.h"
#include "test_help.h"

#if defined(__linux__)
#include <sys/statfs.h>
#include <linux/magic.h>
#endif

int test_string2ll(int argc, char **argv, int flags) {
UNUSED(argc);
UNUSED(argv);
Expand Down Expand Up @@ -291,6 +296,15 @@ int test_reclaimFilePageCache(int argc, char **argv, int flags) {
if (flags & UNIT_TEST_VALGRIND) return 0;

#if defined(__linux__)
struct statfs stats;

/* Check if /tmp is memory-backed (e.g., tmpfs) */
if (statfs("/tmp", &stats) == 0) {
if (stats.f_type != TMPFS_MAGIC) { // Not tmpfs, use /tmp
return 0;
}
}

char *tmpfile = "/tmp/redis-reclaim-cache-test";
int fd = open(tmpfile, O_RDWR | O_CREAT, 0644);
TEST_ASSERT(fd >= 0);
Expand Down

0 comments on commit 7892bf8

Please sign in to comment.