Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -48,6 +54,20 @@ 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
sleep 1
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
}

start() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,6 +25,7 @@ class ServiceSettings:
mon_port: int
ic_port: int
database: str
wait_time: int = 30


def create_ydb_service(
Expand All @@ -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],
Expand All @@ -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),
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable=redefined-outer-name
import concurrent.futures
import contextlib
import dataclasses
import os
import pathlib
import subprocess
Expand Down Expand Up @@ -88,6 +89,7 @@ def ydb_service_settings(pytestconfig) -> service.ServiceSettings:
mon_port=None,
ic_port=None,
database=database,
wait_time=0,
)

if pytestconfig.option.ydb_host:
Expand All @@ -97,8 +99,10 @@ 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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing something, or is --ydb-wait-time ignored for a locally started YDB instance? With --ydb-host, _ydb_service does not start a container. Without it, this fixture falls back to service.get_service_settings(), which gets the timeout from TESTSUITE_YDB_WAIT_TIME instead of the CLI option.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing something, or is --ydb-wait-time ignored for a locally started YDB instance? With --ydb-host, _ydb_service does not start a container. Without it, this fixture falls back to service.get_service_settings(), which gets the timeout from TESTSUITE_YDB_WAIT_TIME instead of the CLI option.

Fixed

)
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')
Expand Down
Original file line number Diff line number Diff line change
@@ -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
23 changes: 0 additions & 23 deletions ydb/functional_tests/basic/ydb/schemas/events.yaml

This file was deleted.

Loading