From a846593b5466148461922f76883c9d9e007fb222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poyraz=20K=C3=BC=C3=A7=C3=BCkarslan?= <83272398+PoyrazK@users.noreply.github.com> Date: Sat, 18 Apr 2026 14:21:03 +0300 Subject: [PATCH] test(server): add 3 new unit tests Add edge case tests for: - DoubleStop: stop() called twice is safe (idempotent) - StartTwice: start() when already running is idempotent - WaitMethod: wait() blocks until server stops Total: 8 tests (was 5). --- tests/server_tests.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/server_tests.cpp b/tests/server_tests.cpp index 1f3db662..8bcf2b84 100644 --- a/tests/server_tests.cpp +++ b/tests/server_tests.cpp @@ -213,4 +213,63 @@ TEST(ServerTests, InvalidHandshake) { static_cast(server->stop()); } +TEST(ServerTests, DoubleStop) { + auto catalog = Catalog::create(); + StorageManager disk_manager("./test_data"); + storage::BufferPoolManager sm(config::Config::DEFAULT_BUFFER_POOL_SIZE, disk_manager); + config::Config cfg; + uint16_t port = 6010; + + auto server = Server::create(port, *catalog, sm, cfg, nullptr); + ASSERT_TRUE(server->start()); + EXPECT_TRUE(server->is_running()); + + // First stop + EXPECT_TRUE(server->stop()); + EXPECT_FALSE(server->is_running()); + + // Second stop - should be safe (idempotent), is_running stays false + server->stop(); + EXPECT_FALSE(server->is_running()); +} + +TEST(ServerTests, StartTwice) { + auto catalog = Catalog::create(); + StorageManager disk_manager("./test_data"); + storage::BufferPoolManager sm(config::Config::DEFAULT_BUFFER_POOL_SIZE, disk_manager); + config::Config cfg; + uint16_t port = 6011; + + auto server = Server::create(port, *catalog, sm, cfg, nullptr); + ASSERT_TRUE(server->start()); + EXPECT_TRUE(server->is_running()); + + // Second start - should return false or be idempotent + server->start(); + EXPECT_TRUE(server->is_running()); + + static_cast(server->stop()); +} + +TEST(ServerTests, WaitMethod) { + auto catalog = Catalog::create(); + StorageManager disk_manager("./test_data"); + storage::BufferPoolManager sm(config::Config::DEFAULT_BUFFER_POOL_SIZE, disk_manager); + config::Config cfg; + uint16_t port = 6012; + + auto server = Server::create(port, *catalog, sm, cfg, nullptr); + ASSERT_TRUE(server->start()); + + // wait() should block until stop is called + std::thread waiter([&]() { server->wait(); }); + + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + EXPECT_TRUE(server->is_running()); + + server->stop(); + waiter.join(); + EXPECT_FALSE(server->is_running()); +} + } // namespace