Skip to content

Commit 2a0bfb0

Browse files
authored
YQ kqprun added recipe (#9453)
1 parent a430757 commit 2a0bfb0

File tree

9 files changed

+154
-9
lines changed

9 files changed

+154
-9
lines changed

ydb/tests/tools/kqprun/kqprun.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,9 @@ void RunArgumentQueries(const TExecutionOptions& executionOptions, NKqpRun::TKqp
317317
void RunAsDaemon() {
318318
NColorizer::TColors colors = NColorizer::AutoColors(Cout);
319319

320-
Cout << colors.Yellow() << TInstant::Now().ToIsoStringLocal() << " Started reading commands" << colors.Default() << Endl;
320+
Cout << colors.Yellow() << TInstant::Now().ToIsoStringLocal() << " Initialization finished" << colors.Default() << Endl;
321321
while (true) {
322-
TString command;
323-
Cin >> command;
324-
325-
if (command == "exit") {
326-
break;
327-
}
328-
Cerr << colors.Red() << TInstant::Now().ToIsoStringLocal() << " Invalid command '" << command << "'" << colors.Default() << Endl;
322+
pause();
329323
}
330324
}
331325

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import argparse
2+
import logging
3+
import os
4+
5+
from library.python.testing.recipe import declare_recipe, set_env
6+
from library.recipes import common as recipes_common
7+
from yatest.common.network import PortManager
8+
from ydb.tests.library.common import yatest_common
9+
10+
11+
PID_FILENAME = "kqprun_daemon.pid"
12+
KQPRUN_PATH = os.getenv("KQPRUN_EXECUTABLE") or "ydb/tests/tools/kqprun/kqprun"
13+
INITIALIZATION_IMEOUT_RATIO = 2
14+
15+
16+
def is_kqprun_daemon_ready() -> bool:
17+
with open(yatest_common.output_path("kqprun_daemon.out.log"), "r") as outFile:
18+
return "Initialization finished" in outFile.read()
19+
20+
21+
def build_start_comand(argv: list[str], grpc_port: int) -> tuple[int, list[str]]:
22+
parser = argparse.ArgumentParser()
23+
parser.add_argument("--query", action="append", type=str, default=[])
24+
parser.add_argument("--config", action='store', type=str, default="ydb/tests/tools/kqprun/kqprun/configuration/app_config.conf")
25+
parser.add_argument("--timeout-ms", action='store', type=int, default=30000)
26+
parsed, _ = parser.parse_known_args(argv)
27+
28+
cmd = [
29+
yatest_common.binary_path(KQPRUN_PATH),
30+
"--log-file", yatest_common.output_path("kqprun_daemon.ydb.log"),
31+
"--app-config", yatest_common.source_path(parsed.config),
32+
"--grpc", str(grpc_port),
33+
"--timeout", str(parsed.timeout_ms)
34+
]
35+
36+
if parsed.query:
37+
cmd.append("--execution-case")
38+
cmd.append("query")
39+
40+
for query in parsed.query:
41+
cmd.append("--script-query")
42+
cmd.append(yatest_common.source_path(query))
43+
44+
return (parsed.timeout_ms, cmd)
45+
46+
47+
def start(argv: list[str]):
48+
logging.debug("Starting kqprun daemon")
49+
50+
portManager = PortManager()
51+
grpc_port = portManager.get_port()
52+
timeout_ms, cmd = build_start_comand(argv, grpc_port)
53+
54+
recipes_common.start_daemon(
55+
command=cmd,
56+
environment=None,
57+
is_alive_check=is_kqprun_daemon_ready,
58+
pid_file_name=PID_FILENAME,
59+
timeout=INITIALIZATION_IMEOUT_RATIO * (timeout_ms // 1000),
60+
daemon_name="kqprun_daemon"
61+
)
62+
63+
set_env("KQPRUN_ENDPOINT", f"grpc://localhost:{grpc_port}")
64+
logging.debug(f"kqprun daemon has been started on port: {grpc_port}")
65+
66+
67+
def stop(argv: list[str]):
68+
logging.debug("Stop kqprun daemon")
69+
with open(PID_FILENAME, "r") as pidFile:
70+
pid = int(pidFile.read())
71+
recipes_common.stop_daemon(pid)
72+
73+
74+
if __name__ == "__main__":
75+
declare_recipe(start, stop)

ydb/tests/tools/kqprun/recipe/ya.make

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
PY3_PROGRAM(kqprun_recipe)
2+
3+
PY_SRCS(__main__.py)
4+
5+
PEERDIR(
6+
library/python/testing/recipe
7+
library/python/testing/yatest_common
8+
library/recipes/common
9+
ydb/tests/library
10+
)
11+
12+
END()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
LogConfig {
2+
DefaultLevel: 5
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CREATE TABLE test_table (
2+
Key Int32,
3+
PRIMARY KEY (Key)
4+
);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
INSERT INTO test_table
2+
SELECT 42 AS Key;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
3+
from ydb.tests.oss.ydb_sdk_import import ydb
4+
5+
6+
class TestKqprunRecipe(object):
7+
def test_query_execution(self):
8+
with ydb.Driver(
9+
endpoint=os.getenv("KQPRUN_ENDPOINT"),
10+
database="/Root"
11+
) as driver:
12+
driver.wait(timeout=5, fail_fast=True)
13+
14+
with ydb.QuerySessionPool(driver) as pool:
15+
result_sets = pool.execute_with_retries("SELECT * FROM test_table")
16+
rows = result_sets[0].rows
17+
assert len(rows) == 1
18+
assert rows[0].Key == 42

ydb/tests/tools/kqprun/tests/ya.make

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
PY3TEST()
2+
3+
DATA(
4+
arcadia/ydb/tests/tools/kqprun/tests/cfg
5+
)
6+
7+
TEST_SRCS(
8+
test_kqprun_recipe.py
9+
)
10+
11+
PEERDIR(
12+
ydb/tests/oss/ydb_sdk_import
13+
)
14+
15+
DEPENDS(
16+
ydb/tests/tools/kqprun
17+
ydb/tests/tools/kqprun/recipe
18+
)
19+
20+
USE_RECIPE(
21+
ydb/tests/tools/kqprun/recipe/kqprun_recipe
22+
--config ydb/tests/tools/kqprun/tests/cfg/config.conf
23+
--query ydb/tests/tools/kqprun/tests/cfg/create_tables.sql
24+
--query ydb/tests/tools/kqprun/tests/cfg/fill_tables.sql
25+
)
26+
27+
SIZE(MEDIUM)
28+
29+
END()

ydb/tests/tools/kqprun/ya.make

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PROGRAM()
1+
PROGRAM(kqprun)
22

33
SRCS(
44
kqprun.cpp
@@ -24,3 +24,11 @@ PEERDIR(
2424
YQL_LAST_ABI_VERSION()
2525

2626
END()
27+
28+
RECURSE(
29+
recipe
30+
)
31+
32+
RECURSE_FOR_TESTS(
33+
tests
34+
)

0 commit comments

Comments
 (0)