From 81a6a23f65e2feba0f7bf5ed144bc552bd31d637 Mon Sep 17 00:00:00 2001 From: Michael lemito Date: Wed, 29 Jul 2026 15:57:31 +0300 Subject: [PATCH 1/6] fix (testsuite_ydb): Added the ydb startup time. YDB fails to create the database when running tests, which causes goose migrations to fail. Added a time limit for YDB to start, after which the tests are run --- .../pytest_userver/plugins/ydb/__init__.py | 1 + .../plugins/ydb/scripts/service-ydb | 21 +++++++++++++++++++ .../pytest_userver/plugins/ydb/service.py | 4 ++++ .../pytest_userver/plugins/ydb/ydbsupport.py | 2 ++ 4 files changed, 28 insertions(+) diff --git a/testsuite/pytest_plugins/pytest_userver/plugins/ydb/__init__.py b/testsuite/pytest_plugins/pytest_userver/plugins/ydb/__init__.py index d23f23ab0e23..fe8f5a314404 100644 --- a/testsuite/pytest_plugins/pytest_userver/plugins/ydb/__init__.py +++ b/testsuite/pytest_plugins/pytest_userver/plugins/ydb/__init__.py @@ -18,6 +18,7 @@ def pytest_addoption(parser): group.addoption('--ydb-grpc-port', type=int, help='YDB grpc host') group.addoption('--ydb-mon-port', type=int, help='YDB mon host') group.addoption('--ydb-ic-port', type=int, help='YDB ic host') + group.addoption('--ydb-wait-time', type=int, default=30, help='YDB container startup wait timeout in seconds (0 = no wait)') def pytest_configure(config): diff --git a/testsuite/pytest_plugins/pytest_userver/plugins/ydb/scripts/service-ydb b/testsuite/pytest_plugins/pytest_userver/plugins/ydb/scripts/service-ydb index d3a15f8b2ce3..87332c1373f6 100755 --- a/testsuite/pytest_plugins/pytest_userver/plugins/ydb/scripts/service-ydb +++ b/testsuite/pytest_plugins/pytest_userver/plugins/ydb/scripts/service-ydb @@ -30,6 +30,12 @@ fi if [ "x$YDB_DOCKER_IMAGE" = "x" ]; then die "YDB_DOCKER_IMAGE must be set" fi +if [ "x$YDB_WAIT_TIME" = "x" ]; then + die "YDB_WAIT_TIME must be set" +fi +if [ "$YDB_WAIT_TIME" -lt 0 ] 2>/dev/null; then + die "YDB_WAIT_TIME must be >= 0, but got $YDB_WAIT_TIME" +fi YDB_DATA_DIR=$YDB_TMPDIR/data @@ -48,6 +54,21 @@ start_ydb() { -e GRPC_PORT=$YDB_GRPC_PORT \ -e MON_PORT=$YDB_MON_PORT \ ${YDB_DOCKER_IMAGE} + + if [ "$YDB_WAIT_TIME" -gt 0 ]; then + echo "Waiting ${YDB_WAIT_TIME} seconds..." + for i in $(seq 1 "$YDB_WAIT_TIME"); do + if $DOCKER_BINPATH exec ${YDB_CONTAINER_NAME} test -f /ydb_database.txt 2>/dev/null; then + break + fi + + if [ "$i" -eq "$YDB_WAIT_TIME" ]; then + die "Timed out waiting for /ydb_database.txt in container ${YDB_CONTAINER_NAME}" + fi + + sleep 1 + done + fi } start() { diff --git a/testsuite/pytest_plugins/pytest_userver/plugins/ydb/service.py b/testsuite/pytest_plugins/pytest_userver/plugins/ydb/service.py index 50e08efe4f81..45df65764455 100644 --- a/testsuite/pytest_plugins/pytest_userver/plugins/ydb/service.py +++ b/testsuite/pytest_plugins/pytest_userver/plugins/ydb/service.py @@ -11,6 +11,7 @@ DEFAULT_MON_PORT = 8765 DEFAULT_DATABASE = 'local' DEFAULT_CONTAINER_NAME = 'ydb-local-testsuite' +# TODO (lemito): change to ydbplatform/local-ydb:latest DEFAULT_DOCKER_IMAGE = 'cr.yandex/yc/yandex-docker-local-ydb:latest' PLUGIN_DIR = pathlib.Path(__file__).parent @@ -24,6 +25,7 @@ class ServiceSettings: mon_port: int ic_port: int database: str + wait_time: int = 30 def create_ydb_service( @@ -47,6 +49,7 @@ def create_ydb_service( 'YDB_MON_PORT': str(settings.mon_port), 'YDB_CONTAINER_NAME': DEFAULT_CONTAINER_NAME, 'YDB_DOCKER_IMAGE': DEFAULT_DOCKER_IMAGE, + 'YDB_WAIT_TIME': str(settings.wait_time), **(env or {}), }, check_ports=[settings.grpc_port, settings.mon_port], @@ -63,4 +66,5 @@ def get_service_settings(): mon_port=utils.getenv_int('TESTSUITE_YDB_MON_PORT', DEFAULT_MON_PORT), ic_port=utils.getenv_int('TESTSUITE_YDB_IC_PORT', 0), database=os.getenv('TESTSUITE_YDB_DATABASE', DEFAULT_DATABASE), + wait_time=utils.getenv_int('TESTSUITE_YDB_WAIT_TIME', 30), ) diff --git a/testsuite/pytest_plugins/pytest_userver/plugins/ydb/ydbsupport.py b/testsuite/pytest_plugins/pytest_userver/plugins/ydb/ydbsupport.py index 0264fdfd9069..41b6c1654088 100644 --- a/testsuite/pytest_plugins/pytest_userver/plugins/ydb/ydbsupport.py +++ b/testsuite/pytest_plugins/pytest_userver/plugins/ydb/ydbsupport.py @@ -88,6 +88,7 @@ def ydb_service_settings(pytestconfig) -> service.ServiceSettings: mon_port=None, ic_port=None, database=database, + wait_time=0, ) if pytestconfig.option.ydb_host: @@ -97,6 +98,7 @@ def ydb_service_settings(pytestconfig) -> service.ServiceSettings: mon_port=pytestconfig.option.ydb_mon_port, ic_port=pytestconfig.option.ydb_ic_port, database=database, + wait_time=pytestconfig.option.ydb_wait_time, ) return service.get_service_settings() From f57f7831e595acef2a76073edb47e10fa1f1b41a Mon Sep 17 00:00:00 2001 From: Michael lemito Date: Wed, 29 Jul 2026 15:57:52 +0300 Subject: [PATCH 2/6] fix(ydb): db schema to goose migration --- .../migrations/00001_create_events_table.sql | 18 +++++++++++++++ .../basic/ydb/schemas/events.yaml | 23 ------------------- 2 files changed, 18 insertions(+), 23 deletions(-) create mode 100644 ydb/functional_tests/basic/ydb/migrations/00001_create_events_table.sql delete mode 100644 ydb/functional_tests/basic/ydb/schemas/events.yaml diff --git a/ydb/functional_tests/basic/ydb/migrations/00001_create_events_table.sql b/ydb/functional_tests/basic/ydb/migrations/00001_create_events_table.sql new file mode 100644 index 000000000000..0626ca1d042f --- /dev/null +++ b/ydb/functional_tests/basic/ydb/migrations/00001_create_events_table.sql @@ -0,0 +1,18 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE events ( + id String, + name Utf8, + service String, + channel Int64, + created Timestamp, + state Json, + PRIMARY KEY (id, name), + INDEX sample_index GLOBAL ON (service, channel, created) +); +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TABLE events; +-- +goose StatementEnd diff --git a/ydb/functional_tests/basic/ydb/schemas/events.yaml b/ydb/functional_tests/basic/ydb/schemas/events.yaml deleted file mode 100644 index 44b572a59265..000000000000 --- a/ydb/functional_tests/basic/ydb/schemas/events.yaml +++ /dev/null @@ -1,23 +0,0 @@ -- path: events - schema: - - name: id - type: String - - name: name - type: Utf8 - - name: service - type: String - - name: channel - type: Int64 - - name: created - type: Timestamp - - name: state - type: Json - primary_key: - - id - - name - indexes: - - name: sample_index - index_columns: - - service - - channel - - created From 240809b934607892f95792f55f450b51efe000a6 Mon Sep 17 00:00:00 2001 From: Michael lemito Date: Wed, 29 Jul 2026 21:00:40 +0300 Subject: [PATCH 3/6] fix(ydb testsuite): sleep order fixed --- .../pytest_userver/plugins/ydb/scripts/service-ydb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testsuite/pytest_plugins/pytest_userver/plugins/ydb/scripts/service-ydb b/testsuite/pytest_plugins/pytest_userver/plugins/ydb/scripts/service-ydb index 87332c1373f6..df0d30e0d8e3 100755 --- a/testsuite/pytest_plugins/pytest_userver/plugins/ydb/scripts/service-ydb +++ b/testsuite/pytest_plugins/pytest_userver/plugins/ydb/scripts/service-ydb @@ -62,11 +62,11 @@ start_ydb() { break fi + sleep 1 + if [ "$i" -eq "$YDB_WAIT_TIME" ]; then die "Timed out waiting for /ydb_database.txt in container ${YDB_CONTAINER_NAME}" fi - - sleep 1 done fi } From 988a837b7a083e748740d0937fccc835fedde4c7 Mon Sep 17 00:00:00 2001 From: Michael lemito Date: Wed, 29 Jul 2026 21:21:54 +0300 Subject: [PATCH 4/6] fix(1306#discussion_r3676655336): add wait time --- .../pytest_plugins/pytest_userver/plugins/ydb/ydbsupport.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testsuite/pytest_plugins/pytest_userver/plugins/ydb/ydbsupport.py b/testsuite/pytest_plugins/pytest_userver/plugins/ydb/ydbsupport.py index 41b6c1654088..60fc0c78948f 100644 --- a/testsuite/pytest_plugins/pytest_userver/plugins/ydb/ydbsupport.py +++ b/testsuite/pytest_plugins/pytest_userver/plugins/ydb/ydbsupport.py @@ -1,6 +1,7 @@ # pylint: disable=redefined-outer-name import concurrent.futures import contextlib +import dataclasses import os import pathlib import subprocess @@ -100,7 +101,8 @@ def ydb_service_settings(pytestconfig) -> service.ServiceSettings: database=database, wait_time=pytestconfig.option.ydb_wait_time, ) - return service.get_service_settings() + settings = service.get_service_settings() + return dataclasses.replace(settings, wait_time=pytestconfig.option.ydb_wait_time) @pytest.fixture(scope='session') From 9dacdf4a4931092cf123349b883c6b2a362eecef Mon Sep 17 00:00:00 2001 From: Michael lemito Date: Wed, 29 Jul 2026 22:10:52 +0300 Subject: [PATCH 5/6] fix(testsuite ydb): 1306#discussion_r3677117275 --- .../pytest_userver/plugins/ydb/scripts/service-ydb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/testsuite/pytest_plugins/pytest_userver/plugins/ydb/scripts/service-ydb b/testsuite/pytest_plugins/pytest_userver/plugins/ydb/scripts/service-ydb index df0d30e0d8e3..288d7918b422 100755 --- a/testsuite/pytest_plugins/pytest_userver/plugins/ydb/scripts/service-ydb +++ b/testsuite/pytest_plugins/pytest_userver/plugins/ydb/scripts/service-ydb @@ -61,13 +61,12 @@ start_ydb() { if $DOCKER_BINPATH exec ${YDB_CONTAINER_NAME} test -f /ydb_database.txt 2>/dev/null; then break fi - sleep 1 - - if [ "$i" -eq "$YDB_WAIT_TIME" ]; then - die "Timed out waiting for /ydb_database.txt in container ${YDB_CONTAINER_NAME}" - fi done + + if ! $DOCKER_BINPATH exec ${YDB_CONTAINER_NAME} test -f /ydb_database.txt 2>/dev/null; then + die "Timed out waiting for /ydb_database.txt in container ${YDB_CONTAINER_NAME}" + fi fi } From bd360bc47eb35e3943fc4183cdab7da527e14dd8 Mon Sep 17 00:00:00 2001 From: Michael lemito Date: Thu, 30 Jul 2026 15:56:42 +0300 Subject: [PATCH 6/6] fix(ydb_samples): fix test who ERROR in CI --- samples/ydb_service/tests/test_bson_reading.py | 2 +- samples/ydb_service/ydb/migrations/0001_orders.sql | 6 ------ .../ydb_service/ydb/migrations/0003_add_orders_table.sql | 6 ++++++ 3 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 samples/ydb_service/ydb/migrations/0003_add_orders_table.sql diff --git a/samples/ydb_service/tests/test_bson_reading.py b/samples/ydb_service/tests/test_bson_reading.py index 278b522971d6..73938505ef5c 100644 --- a/samples/ydb_service/tests/test_bson_reading.py +++ b/samples/ydb_service/tests/test_bson_reading.py @@ -4,7 +4,7 @@ # /// [YDB service sample - bson reading functional test] @pytest.mark.ydb(files=['fill_orders.sql']) -async def test_bson_reading(service_client): +async def test_bson_reading(service_client, ydb): response = await service_client.post( 'ydb/bson-reading', params={'id': 'id1'}, diff --git a/samples/ydb_service/ydb/migrations/0001_orders.sql b/samples/ydb_service/ydb/migrations/0001_orders.sql index cf2ed9fbfa45..37ed2c83be31 100644 --- a/samples/ydb_service/ydb/migrations/0001_orders.sql +++ b/samples/ydb_service/ydb/migrations/0001_orders.sql @@ -1,10 +1,4 @@ -- +goose Up -CREATE TABLE orders ( - id String, - doc String, - PRIMARY KEY(id) -); - CREATE TABLE events ( id String, name Utf8, diff --git a/samples/ydb_service/ydb/migrations/0003_add_orders_table.sql b/samples/ydb_service/ydb/migrations/0003_add_orders_table.sql new file mode 100644 index 000000000000..21fe8ef06793 --- /dev/null +++ b/samples/ydb_service/ydb/migrations/0003_add_orders_table.sql @@ -0,0 +1,6 @@ +-- +goose Up +CREATE TABLE `orders` ( + id String, + doc String, + PRIMARY KEY(id) +);