mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-08 14:02:55 +00:00
- The 'pageserver' fixture now sets up the repository and starts up
the Page Server automatically. In other words, the 'pageserver'
fixture provides a Page Server that's up and running and ready to
use in tests.
- The 'pageserver' fixture now also creates a branch called 'empty',
right after initializing the repository. By convention, all the
tests start by createing a new branch off 'empty' for the test. This
allows running all the tests against the same Page Server
concurrently. (I haven't tested that though. pytest doensn't
provide an option to run tests in parallel but there are extensions
for that.)
- Remove the 'zen_simple' fixture. Now that 'pageserver' provides
server that's up and running, it's pretty simple to use the
'pageserver' and 'postgres' fixtures directly.
- Don't assume host name or ports in the tests. They now use the
fields in the fixtures for that. That allows assigning the ports
dynamically, making it possible to run multiple page servers in
parallel, or running the tests in parallel with another page
server. This commit still hard codes the Page Server's port in the
fixture, though, so more work is needed to actually make it
possible.
- I made some changes to the 'postgres' fixture in commit 532918e13d,
which broke the other tests. Fix them.
- Divide the tests into two "batches" of roughly equal runtime, which
can be run in parallel
- Merge the 'test_file' and 'test_filter' options in CircleCI config
into one 'test_selection' option, for simplicity.
68 lines
3.0 KiB
Python
68 lines
3.0 KiB
Python
import pytest
|
|
import getpass
|
|
import psycopg2
|
|
|
|
pytest_plugins = ("fixtures.zenith_fixtures")
|
|
|
|
#
|
|
# Create a couple of branches off the main branch, at a historical point in time.
|
|
#
|
|
def test_branch_behind(zenith_cli, pageserver, postgres, pg_bin):
|
|
# Branch at the point where only 100 rows were inserted
|
|
zenith_cli.run(["branch", "test_branch_behind", "empty"]);
|
|
|
|
pgmain = postgres.create_start('test_branch_behind')
|
|
print("postgres is running on 'test_branch_behind' branch")
|
|
|
|
main_pg_conn = psycopg2.connect(pgmain.connstr());
|
|
main_pg_conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
|
|
main_cur = main_pg_conn.cursor()
|
|
|
|
# Create table, and insert the first 100 rows
|
|
main_cur.execute('CREATE TABLE foo (t text)');
|
|
main_cur.execute("INSERT INTO foo SELECT 'long string to consume some space' || g FROM generate_series(1, 100) g");
|
|
main_cur.execute('SELECT pg_current_wal_insert_lsn()');
|
|
lsn_a = main_cur.fetchone()[0]
|
|
print('LSN after 100 rows: ' + lsn_a)
|
|
|
|
# Insert some more rows. (This generates enough WAL to fill a few segments.)
|
|
main_cur.execute("INSERT INTO foo SELECT 'long string to consume some space' || g FROM generate_series(1, 100000) g");
|
|
main_cur.execute('SELECT pg_current_wal_insert_lsn()');
|
|
lsn_b = main_cur.fetchone()[0]
|
|
print('LSN after 100100 rows: ' + lsn_b)
|
|
|
|
# Branch at the point where only 100 rows were inserted
|
|
zenith_cli.run(["branch", "test_branch_behind_hundred", "test_branch_behind@"+lsn_a]);
|
|
|
|
# Insert many more rows. This generates enough WAL to fill a few segments.
|
|
main_cur.execute("INSERT INTO foo SELECT 'long string to consume some space' || g FROM generate_series(1, 100000) g");
|
|
main_cur.execute('SELECT pg_current_wal_insert_lsn()');
|
|
|
|
main_cur.execute('SELECT pg_current_wal_insert_lsn()');
|
|
lsn_c = main_cur.fetchone()[0]
|
|
print('LSN after 200100 rows: ' + lsn_c)
|
|
|
|
# Branch at the point where only 200 rows were inserted
|
|
zenith_cli.run(["branch", "test_branch_behind_more", "test_branch_behind@"+lsn_b]);
|
|
|
|
pg_hundred = postgres.create_start("test_branch_behind_hundred")
|
|
pg_more = postgres.create_start("test_branch_behind_more")
|
|
|
|
# On the 'hundred' branch, we should see only 100 rows
|
|
hundred_pg_conn = psycopg2.connect(pg_hundred.connstr())
|
|
hundred_pg_conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
|
|
hundred_cur = hundred_pg_conn.cursor()
|
|
hundred_cur.execute('SELECT count(*) FROM foo');
|
|
assert(hundred_cur.fetchone()[0] == 100);
|
|
|
|
# On the 'more' branch, we should see 100200 rows
|
|
more_pg_conn = psycopg2.connect(pg_more.connstr())
|
|
more_pg_conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
|
|
more_cur = more_pg_conn.cursor()
|
|
more_cur.execute('SELECT count(*) FROM foo');
|
|
assert(more_cur.fetchone()[0] == 100100);
|
|
|
|
# All the rows are visible on the main branch
|
|
main_cur.execute('SELECT count(*) FROM foo');
|
|
assert(main_cur.fetchone()[0] == 200100);
|