Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue in concurrent recreate table #99

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(TEST_API_OBJECTS
test_api.cpp
test_config.cpp
test_custom_allocator.cpp
test_concurrent_recreate.cpp
test_results.cpp
test_reset.cpp
test_get_table_names.cpp
Expand Down
43 changes: 43 additions & 0 deletions test/api/test_concurrent_recreate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "catch.hpp"
#include "test_helpers.hpp"
#include <iostream>
#include <thread>

using namespace duckdb;
using namespace std;

static void SelectTable(Connection con) {
idx_t i = 0;
while (true) {
auto prepare = con.Prepare("select * from foo");
REQUIRE_NO_FAIL(prepare->Execute());
std::cout << "select " << i++ << std::endl;
}
}

static void RecreateTable(Connection con) {
idx_t i = 0;
while (true) {
auto prepare = con.Prepare("create or replace table foo as select * from foo");
REQUIRE_NO_FAIL(prepare->Execute());
std::cout << "recreate " << i++ << std::endl;
}
}

TEST_CASE("Test concurrent prepared", "[api]") {
duckdb::unique_ptr<QueryResult> result;
DuckDB db(nullptr);
Connection con(db);
con.EnableQueryVerification();

REQUIRE_NO_FAIL(con.Query("create table foo as select unnest(generate_series(1, 10));"));

Connection select_conn(db);
Connection recreate_conn(db);

std::thread select_function(SelectTable, std::move(select_conn));
std::thread recreate_function(RecreateTable, std::move(recreate_conn));

select_function.join();
recreate_function.join();
}
Loading