Исправить U+0000 и гонку готовности PostgreSQL; добавить проверки

This commit is contained in:
2026-10-23 12:26:15 +03:00
parent 400e62ffdc
commit 01ecc8567e
20 changed files with 1123 additions and 717 deletions
+4 -2
View File
@@ -34,13 +34,15 @@ started_bootstrap = time.perf_counter()
restore_id = subprocess.check_output(['docker', 'run', '-d', '--name', restore_container, '--network', network, '--cpus=1', '--memory=512m', '-e', 'POSTGRES_USER=messenger', '-e', 'POSTGRES_DB=' + restore, '-e', 'POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password', '--mount', 'type=volume,src=' + restore_volume + ',dst=/var/lib/postgresql/data', '--mount', 'type=bind,src=' + str(ROOT / 'secrets/postgres_password') + ',dst=/run/secrets/postgres_password,readonly', image], text=True).strip()
try:
deadline = time.monotonic() + 45
while subprocess.run(['docker', 'exec', restore_container, 'pg_isready', '-U', 'messenger', '-d', restore], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode:
# The entrypoint's temporary init server accepts Unix sockets only.
# TCP becomes ready only after initialization has finished and it is replaced.
while subprocess.run(['docker', 'exec', restore_container, 'pg_isready', '-h', '127.0.0.1', '-U', 'messenger', '-d', restore], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode:
assert time.monotonic() < deadline, 'new PostgreSQL did not become ready'
time.sleep(0.3)
bootstrap_seconds = time.perf_counter() - started_bootstrap
started = time.perf_counter()
with backup.open('rb') as data:
subprocess.run(['docker', 'exec', '-i', restore_container, 'pg_restore', '-U', 'messenger', '--no-owner', '--exit-on-error', '-d', restore], stdin=data, check=True)
subprocess.run(['docker', 'exec', '-i', restore_container, 'pg_restore', '-h', '127.0.0.1', '-U', 'messenger', '--no-owner', '--exit-on-error', '-d', restore], stdin=data, check=True)
restore_seconds = time.perf_counter() - started
verified = json.loads(subprocess.check_output(RUN + ['-e', 'RESEARCH_DATABASE=' + restore, '-e', 'RESEARCH_HOST=' + restore_container, 'api', 'python', 'student-tests/index_study.py', '--verify'], text=True))
finally: