File: test_concurrent_prepared.cpp

package info (click to toggle)
duckdb 1.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 299,196 kB
  • sloc: cpp: 865,414; ansic: 57,292; python: 18,871; sql: 12,663; lisp: 11,751; yacc: 7,412; lex: 1,682; sh: 747; makefile: 558
file content (46 lines) | stat: -rw-r--r-- 1,151 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "catch.hpp"
#include "test_helpers.hpp"
#include <iostream>
#include <thread>

using namespace duckdb;
using namespace std;

static void SelectTable(Connection con) {
	for (idx_t i = 0; i < 1000; i++) {
		auto prepare = con.Prepare("select * from foo");
		auto result = prepare->Execute();
		if (result->HasError()) {
			FAIL();
		}
	}
}

static void RecreateTable(Connection con) {
	for (idx_t i = 0; i < 1000; i++) {
		auto prepare = con.Prepare("create or replace table foo as select * from foo");
		auto result = prepare->Execute();
		if (result->HasError()) {
			FAIL();
		}
	}
}

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);
	select_conn.EnableQueryVerification();

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

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