Skip to content

Commit

Permalink
Enable read only DB tests on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminwinger committed Sep 12, 2024
1 parent 796f70d commit ce4de37
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 33 deletions.
3 changes: 2 additions & 1 deletion src/common/file_system/local_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ std::unique_ptr<FileInfo> LocalFileSystem::openFile(const std::string& path, int
LOCKFILE_FAIL_IMMEDIATELY | LOCKFILE_EXCLUSIVE_LOCK;
OVERLAPPED overlapped = {0};
overlapped.Offset = 0;
BOOL rc = LockFileEx(handle, dwFlags, 0, 0, 0, &overlapped);
BOOL rc = LockFileEx(handle, dwFlags, 0 /*reserved*/, 1 /*numBytesLow*/, 0 /*numBytesHigh*/,
&overlapped);
if (!rc) {
throw IOException("Could not set lock on file : " + fullPath);
}
Expand Down
4 changes: 0 additions & 4 deletions test/c_api/database_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ TEST_F(CApiDatabaseTest, CreationAndDestroy) {
}

TEST_F(CApiDatabaseTest, CreationReadOnly) {
// TODO: Enable this test on Windows when the read-only mode is implemented.
#ifdef _WIN32
return;
#endif
kuzu_database database;
kuzu_connection connection;
kuzu_query_result queryResult;
Expand Down
1 change: 1 addition & 0 deletions test/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
if(MSVC)
add_kuzu_api_test(main_test
system_config_test.cpp
arrow_test.cpp
connection_test.cpp
prepare_test.cpp
Expand Down
1 change: 1 addition & 0 deletions test/main/connection_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ TEST_F(ApiTest, Prepare) {
}

TEST_F(ApiTest, CreateTableAfterClosingDatabase) {
database.reset();
database = std::make_unique<Database>(databasePath, *systemConfig);
conn = std::make_unique<Connection>(database.get());

Expand Down
4 changes: 3 additions & 1 deletion test/main/system_config_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ using namespace kuzu::common;
using namespace kuzu::testing;
using namespace kuzu::main;

class SystemConfigTest : public ApiTest {};
class SystemConfigTest : public ApiTest {
void SetUp() override { BaseGraphTest::SetUp(); }
};

void assertQuery(QueryResult& result) {
auto a = result.toString();
Expand Down
14 changes: 2 additions & 12 deletions tools/nodejs_api/test/test_database.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ describe("Database constructor", function () {
});

it("should create a database in read-only mode", async function () {
// TODO: Enable this test on Windows when the read-only mode is implemented.
if (process.platform === "win32") {
this._runnable.title += " (skipped: not implemented on Windows)";
this.skip();
}

const tmpDbPath = await new Promise((resolve, reject) => {
tmp.dir({ unsafeCleanup: true }, (err, path, _) => {
if (err) {
Expand All @@ -89,7 +83,7 @@ describe("Database constructor", function () {
assert.exists(testDb._database);
assert.isTrue(testDb._isInitialized);
assert.notExists(testDb._initPromise);
delete testDb;
await testDb.close();
const testDbReadOnly = new kuzu.Database(
tmpDbPath,
1 << 28 /* 256MB */,
Expand Down Expand Up @@ -193,7 +187,7 @@ describe("Database constructor", function () {
it("should create an in-memory database when no path is provided", async function () {
const testDb = new kuzu.Database();
const conn = new kuzu.Connection(testDb);
let res = await conn.query("CREATE NODE TABLE person(name STRING, age INT64, PRIMARY KEY(name));");
let res = await conn.query("CREATE NODE TABLE person(name STRING, age INT64, PRIMARY KEY(name));");
res.close();
res = await conn.query("CREATE (:person {name: 'Alice', age: 30});");
res.close();
Expand Down Expand Up @@ -235,10 +229,6 @@ describe("Database constructor", function () {

describe("Database close", function () {
it("should allow initializing a new database after closing", async function () {
if (process.platform === "win32") {
this._runnable.title += " (skipped: not implemented on Windows)";
this.skip();
}
const tmpDbPath = await new Promise((resolve, reject) => {
tmp.dir({ unsafeCleanup: true }, (err, path, _) => {
if (err) {
Expand Down
6 changes: 1 addition & 5 deletions tools/python_api/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,7 @@ def conn_db_readonly(tmp_path: Path) -> ConnDB:
"""Return a cached read-only connection and database."""
global _READONLY_CONN_DB_
if _READONLY_CONN_DB_ is None:
# On Windows, the read-only mode is not implemented yet.
# Therefore, we create a writable database on Windows.
# However, the caller should ensure that the database is not modified.
# TODO: Remove this workaround when the read-only mode is implemented on Windows.
_READONLY_CONN_DB_ = create_conn_db(init_db(tmp_path), read_only=sys.platform != "win32")
_READONLY_CONN_DB_ = create_conn_db(init_db(tmp_path), read_only=True)
return _READONLY_CONN_DB_


Expand Down
12 changes: 5 additions & 7 deletions tools/python_api/test/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ def test_database_close(tmp_path: Path, build_dir: Path) -> None:
assert db._database is not None

# Open the database on a subprocess. It should raise an exception.
# TODO: Enable this test on Windows when the read-only mode is implemented.
if sys.platform != "win32":
with pytest.raises(
RuntimeError,
match=r"RuntimeError: IO exception: Could not set lock on file",
):
open_database_on_subprocess(db_path, build_dir)
with pytest.raises(
Exception,
match=r"RuntimeError: IO exception: Could not set lock on file",
):
open_database_on_subprocess(db_path, build_dir)

db.close()
assert db.is_closed
Expand Down
3 changes: 0 additions & 3 deletions tools/python_api/test/test_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ def test_db_path_exception() -> None:


def test_read_only_exception(conn_db_readonly: ConnDB) -> None:
# TODO: Enable this test on Windows when the read-only mode is implemented.
if sys.platform == "win32":
pytest.skip("Read-only mode has not been implemented on Windows yet")
_, db = conn_db_readonly
path = db.database_path
read_only_db = kuzu.Database(path, read_only=True)
Expand Down

0 comments on commit ce4de37

Please sign in to comment.