Skip to content

Commit a991d9f

Browse files
authored
Merge pull request #41 from mukesh-2096/consolidate-tests
#39
2 parents b001b4b + c8a52a0 commit a991d9f

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/tidesdb.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ ffi.cdef[[
9393
size_t max_open_sstables;
9494
int log_to_file;
9595
size_t log_truncation_at;
96+
size_t max_memory_usage;
9697
} tidesdb_config_t;
9798

9899
typedef struct {
@@ -361,6 +362,7 @@ function tidesdb.default_config()
361362
max_open_sstables = 256,
362363
log_to_file = false,
363364
log_truncation_at = 24 * 1024 * 1024,
365+
max_memory_usage = 0,
364366
}
365367
end
366368

@@ -848,6 +850,7 @@ function TidesDB.new(config)
848850
c_config.max_open_sstables = config.max_open_sstables or 256
849851
c_config.log_to_file = config.log_to_file and 1 or 0
850852
c_config.log_truncation_at = config.log_truncation_at or 24 * 1024 * 1024
853+
c_config.max_memory_usage = config.max_memory_usage or 0
851854

852855
local db_ptr = ffi.new("void*[1]")
853856
local result = lib.tidesdb_open(c_config, db_ptr)
@@ -868,6 +871,7 @@ function TidesDB.open(path, options)
868871
max_open_sstables = options.max_open_sstables or 256,
869872
log_to_file = options.log_to_file or false,
870873
log_truncation_at = options.log_truncation_at or 24 * 1024 * 1024,
874+
max_memory_usage = options.max_memory_usage or 0,
871875
}
872876
return TidesDB.new(config)
873877
end

tests/test_tidesdb.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,43 @@ function tests.test_commit_hook()
762762
print("PASS: test_commit_hook")
763763
end
764764

765+
function tests.test_max_memory_usage()
766+
local path = "./test_db_max_mem"
767+
cleanup_db(path)
768+
769+
-- Test default config includes max_memory_usage
770+
local default_cfg = tidesdb.default_config()
771+
assert_true(default_cfg.max_memory_usage ~= nil, "max_memory_usage should exist in default config")
772+
773+
-- Test opening database with default max_memory_usage (0 = unlimited)
774+
local db1 = tidesdb.TidesDB.open(path)
775+
assert_true(db1 ~= nil, "database should open with default max_memory_usage")
776+
db1:close()
777+
cleanup_db(path)
778+
779+
-- Test opening database with custom max_memory_usage
780+
local db2 = tidesdb.TidesDB.open(path, {
781+
max_memory_usage = 512 * 1024 * 1024 -- 512 MB
782+
})
783+
assert_true(db2 ~= nil, "database should open with custom max_memory_usage")
784+
db2:close()
785+
cleanup_db(path)
786+
787+
-- Test with TidesDB.new() constructor
788+
local config = {
789+
db_path = path,
790+
num_flush_threads = 2,
791+
num_compaction_threads = 2,
792+
max_memory_usage = 256 * 1024 * 1024 -- 256 MB
793+
}
794+
local db3 = tidesdb.TidesDB.new(config)
795+
assert_true(db3 ~= nil, "database should be created with TidesDB.new() and max_memory_usage")
796+
db3:close()
797+
798+
cleanup_db(path)
799+
print("PASS: test_max_memory_usage")
800+
end
801+
765802
-- Run all tests
766803
local function run_tests()
767804
print("Running TidesDB Lua tests...")

0 commit comments

Comments
 (0)