Skip to content

Commit d4ad98f

Browse files
authored
YQ-2670 switch generic tests to docker compose (#691)
* Switched KQP generic provider tests to docker-compose * Fixed retries
1 parent c59860b commit d4ad98f

8 files changed

+95
-24
lines changed

ydb/core/kqp/ut/federated_query/generic/ch_recipe_ut_helpers.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
namespace NTestUtils {
77

88
TString GetChHost() {
9-
return GetEnv("RECIPE_CLICKHOUSE_HOST", "localhost");
9+
return "localhost";
1010
}
1111

1212
ui32 GetChPort() {
13-
return FromString<ui32>(GetEnv("RECIPE_CLICKHOUSE_NATIVE_PORT", "1234"));
13+
return 19000;
1414
}
1515

1616
TString GetChUser() {
17-
return GetEnv("RECIPE_CLICKHOUSE_USER");
17+
return "user";
1818
}
1919

2020
TString GetChPassword() {
21-
return GetEnv("RECIPE_CLICKHOUSE_PASSWORD");
21+
return "password";
2222
}
2323

2424
TString GetChDatabase() {
@@ -32,7 +32,20 @@ namespace NTestUtils {
3232
.SetPort(GetChPort())
3333
.SetUser(GetChUser())
3434
.SetPassword(GetChPassword());
35-
return NClickHouse::TClient(opt);
35+
36+
TInstant start = TInstant::Now();
37+
ui32 attempt = 0;
38+
while ((TInstant::Now() - start).Seconds() < 60) {
39+
attempt += 1;
40+
try {
41+
return NClickHouse::TClient(opt);
42+
} catch (const TSystemError& e) {
43+
Cerr << "Attempt " << attempt << ": " << e.what() << Endl;
44+
Sleep(TDuration::MilliSeconds(100));
45+
}
46+
}
47+
48+
throw yexception() << "Failed to connect ClickHouse in " << attempt << " attempt(s)";
3649
}
3750

3851
} // namespace NTestUtils

ydb/core/kqp/ut/federated_query/generic/connector_recipe_ut_helpers.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
namespace NTestUtils {
77

88
TString GetConnectorHost() {
9-
return GetEnv("YDB_CONNECTOR_RECIPE_GRPC_HOST", "localhost");
9+
return "localhost";
1010
}
1111

1212
ui32 GetConnectorPort() {
13-
const TString port = GetEnv("YDB_CONNECTOR_RECIPE_GRPC_PORT");
14-
UNIT_ASSERT_C(port, "No connector port specified");
15-
return FromString<ui32>(port);
13+
return 50051;
1614
}
1715

1816
std::shared_ptr<NKikimr::NKqp::TKikimrRunner> MakeKikimrRunnerWithConnector() {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: '3.4'
2+
services:
3+
postgresql:
4+
image: postgres:15-bullseye@sha256:3411b9f2e5239cd7867f34fcf22fe964230f7d447a71d63c283e3593d3f84085
5+
environment:
6+
POSTGRES_DB: db
7+
POSTGRES_USER: user
8+
POSTGRES_PASSWORD: password
9+
ports:
10+
- 15432:5432
11+
clickhouse:
12+
image: clickhouse/clickhouse-server:23-alpine@sha256:b078c1cd294632afa2aeba3530e7ba2e568513da23304354f455a25fab575c06
13+
environment:
14+
CLICKHOUSE_DB: db
15+
CLICKHOUSE_USER: user
16+
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
17+
CLICKHOUSE_PASSWORD: password
18+
ports:
19+
- 19000:9000
20+
- 18123:8123
21+
fq-connector-go:
22+
image: ghcr.io/ydb-platform/fq-connector-go:v0.0.6-rc.8@sha256:74ebae0530d916c1842a7fddfbddc6c018763a0401f2f627a44e8829692fe41f
23+
ports:
24+
- 50051:50051
25+
network_mode: host

ydb/core/kqp/ut/federated_query/generic/kqp_generic_plan_ut.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Y_UNIT_TEST_SUITE(KqpGenericPlanTest) {
4343
{
4444
const TString sql = fmt::format(
4545
R"sql(
46-
CREATE OBJECT pg_password_obj (TYPE SECRET) WITH (value="");
46+
CREATE OBJECT pg_password_obj (TYPE SECRET) WITH (value="{pg_password}");
4747
CREATE EXTERNAL DATA SOURCE pg_data_source WITH (
4848
SOURCE_TYPE="PostgreSQL",
4949
LOCATION="{pg_host}:{pg_port}",
@@ -58,6 +58,7 @@ Y_UNIT_TEST_SUITE(KqpGenericPlanTest) {
5858
"pg_host"_a = GetPgHost(),
5959
"pg_port"_a = GetPgPort(),
6060
"pg_user"_a = GetPgUser(),
61+
"pg_password"_a = GetPgPassword(),
6162
"pg_database"_a = GetPgDatabase());
6263
auto result = session.ExecuteSchemeQuery(sql).GetValueSync();
6364
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());

ydb/core/kqp/ut/federated_query/generic/kqp_generic_provider_join_ut.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Y_UNIT_TEST_SUITE(FederatedQueryJoin) {
7171
{
7272
const TString sql = fmt::format(
7373
R"sql(
74-
CREATE OBJECT pg_password_obj (TYPE SECRET) WITH (value="");
74+
CREATE OBJECT pg_password_obj (TYPE SECRET) WITH (value="{pg_password}");
7575
CREATE EXTERNAL DATA SOURCE pg_data_source WITH (
7676
SOURCE_TYPE="PostgreSQL",
7777
LOCATION="{pg_host}:{pg_port}",
@@ -97,6 +97,7 @@ Y_UNIT_TEST_SUITE(FederatedQueryJoin) {
9797
"pg_host"_a = GetPgHost(),
9898
"pg_port"_a = GetPgPort(),
9999
"pg_user"_a = GetPgUser(),
100+
"pg_password"_a = GetPgPassword(),
100101
"pg_database"_a = GetPgDatabase(),
101102
"ch_host"_a = GetChHost(),
102103
"ch_port"_a = GetChPort(),

ydb/core/kqp/ut/federated_query/generic/pg_recipe_ut_helpers.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,47 @@ using namespace fmt::literals;
1010
namespace NTestUtils {
1111

1212
TString GetPgHost() {
13-
return GetEnv("POSTGRES_RECIPE_HOST", "localhost");
13+
return "localhost";
1414
}
1515

1616
ui32 GetPgPort() {
17-
const TString port = GetEnv("POSTGRES_RECIPE_PORT");
18-
UNIT_ASSERT_C(port, "No postgresql port specified");
19-
return FromString<ui32>(port);
17+
return 15432;
2018
}
2119

2220
TString GetPgUser() {
23-
return GetEnv("POSTGRES_RECIPE_USER");
21+
return "user";
2422
}
2523

2624
TString GetPgDatabase() {
27-
return GetEnv("POSTGRES_RECIPE_DBNAME");
25+
return "db";
26+
}
27+
28+
TString GetPgPassword() {
29+
return "password";
2830
}
2931

3032
pqxx::connection CreatePostgresqlConnection() {
3133
const TString connectionString = fmt::format(
32-
"host={host} port={port} dbname={database} user={user}",
34+
"host={host} port={port} dbname={database} user={user} password={password}",
3335
"host"_a = GetPgHost(),
3436
"port"_a = GetPgPort(),
3537
"database"_a = GetPgDatabase(),
36-
"user"_a = GetPgUser());
37-
return pqxx::connection{connectionString};
38+
"user"_a = GetPgUser(),
39+
"password"_a = GetPgPassword());
40+
41+
TInstant start = TInstant::Now();
42+
ui32 attempt = 0;
43+
while ((TInstant::Now() - start).Seconds() < 60) {
44+
attempt += 1;
45+
try {
46+
return pqxx::connection{connectionString};
47+
} catch (const pqxx::broken_connection& e) {
48+
Cerr << "Attempt " << attempt << ": " << e.what() << Endl;
49+
Sleep(TDuration::MilliSeconds(100));
50+
}
51+
}
52+
53+
throw yexception() << "Failed to connect PostgreSQL in " << attempt << " attempt(s)";
3854
}
3955

4056
} // namespace NTestUtils

ydb/core/kqp/ut/federated_query/generic/pg_recipe_ut_helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace NTestUtils {
99
ui32 GetPgPort();
1010
TString GetPgUser();
1111
TString GetPgDatabase();
12+
TString GetPgPassword();
1213

1314
pqxx::connection CreatePostgresqlConnection();
1415

ydb/core/kqp/ut/federated_query/generic/ya.make

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
UNITTEST_FOR(ydb/core/kqp)
22

3-
FORK_SUBTESTS()
3+
IF (AUTOCHECK)
4+
# Split tests to chunks only when they're running on different machines with distbuild,
5+
# otherwise this directive will slow down local test execution.
6+
# Look through https://st.yandex-team.ru/DEVTOOLSSUPPORT-39642 for more information.
7+
FORK_SUBTESTS()
8+
9+
# TAG and REQUIREMENTS are copied from: https://docs.yandex-team.ru/devtools/test/environment#docker-compose
10+
TAG(
11+
ya:external
12+
ya:force_sandbox
13+
ya:fat
14+
)
15+
16+
REQUIREMENTS(
17+
container:4467981730
18+
cpu:all
19+
dns:dns64
20+
)
21+
ENDIF()
422

523
SRCS(
624
ch_recipe_ut_helpers.cpp
@@ -20,9 +38,7 @@ PEERDIR(
2038
ydb/library/yql/sql/pg_dummy
2139
)
2240

23-
INCLUDE(${ARCADIA_ROOT}/library/recipes/clickhouse/recipe.inc)
24-
INCLUDE(${ARCADIA_ROOT}/library/recipes/postgresql/recipe.inc)
25-
INCLUDE(${ARCADIA_ROOT}/ydb/library/yql/providers/generic/connector/recipe/recipe.inc)
41+
INCLUDE(${ARCADIA_ROOT}/library/recipes/docker_compose/recipe.inc)
2642

2743
YQL_LAST_ABI_VERSION()
2844

0 commit comments

Comments
 (0)