From 3f89016bd7ad0b248b3e7db81f5d32d147d4f683 Mon Sep 17 00:00:00 2001 From: anastasia Date: Tue, 25 May 2021 17:14:55 +0300 Subject: [PATCH] add test_oldestXid to check value after node restart --- test_runner/batch_others/test_oldestXid.py | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test_runner/batch_others/test_oldestXid.py diff --git a/test_runner/batch_others/test_oldestXid.py b/test_runner/batch_others/test_oldestXid.py new file mode 100644 index 0000000000..92d5f3e791 --- /dev/null +++ b/test_runner/batch_others/test_oldestXid.py @@ -0,0 +1,51 @@ +import pytest +import getpass +import psycopg2 +import time +import os + +pytest_plugins = ("fixtures.zenith_fixtures") + +# +# Test pg_control values after recreating a postgres instance +# +def test_oldestxid(zenith_cli, pageserver, postgres, pg_bin, repo_dir): + zenith_cli.run(["branch", "test_oldestxid", "empty"]); + + pg = postgres.create_start('test_oldestxid') + print("postgres is running on 'test_oldestxid' branch") + + pg_conn = psycopg2.connect(pg.connstr()); + pg_conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) + cur = pg_conn.cursor() + + # Create table, and insert a row + cur.execute('CREATE TABLE foo (t text)'); + cur.execute("INSERT INTO foo VALUES ('bar')"); + + cur.execute('checkpoint') + cur.execute('SELECT oldest_xid FROM pg_control_checkpoint();') + oldest_xid = cur.fetchone()[0] + + # Stop, and destroy the Postgres instance. Then recreate and restart it. + pg_conn.close(); + pg.stop(); + + # capture old pg_controldata output for debugging purposes + pgdatadir = os.path.join(repo_dir, 'pgdatadirs/test_oldestxid') + pg_bin.run_capture(['pg_controldata', pgdatadir]) + + pg.destroy(); + pg.create_start('test_oldestxid'); + pg_conn = psycopg2.connect(pg.connstr()); + pg_conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) + cur = pg_conn.cursor() + + cur.execute('SELECT oldest_xid FROM pg_control_checkpoint();') + oldest_xid_new = cur.fetchone()[0] + + assert(oldest_xid_new == oldest_xid) + + # capture new pg_controldata output for debugging purposes + pgdatadir = os.path.join(repo_dir, 'pgdatadirs/test_oldestxid') + pg_bin.run_capture(['pg_controldata', pgdatadir]) \ No newline at end of file