Skip to content

Commit

Permalink
Add replication/WAL test
Browse files Browse the repository at this point in the history
add requirements txt
  • Loading branch information
Ngalstyan4 committed May 4, 2024
1 parent 2138aae commit aa9b4c2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
2 changes: 0 additions & 2 deletions ci/scripts/build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ function install_platform_specific_dependencies() {
make -j && make install
popd

# dependencies of update tests
sudo pip install GitPython
apt install -y ruby-full
gem install bundler

Expand Down
3 changes: 3 additions & 0 deletions ci/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ function build_and_install() {
bundler
popd

# install update and WAL test dependencies
sudo pip install -r /tmp/lantern/scripts/requirements.txt

mkdir build
cd build

Expand Down
1 change: 1 addition & 0 deletions ci/scripts/run-tests-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function run_db_tests(){
make test && \
make test-parallel && \
make test-client && \
python3 ../scripts/test_wal.py && \
run_pgvector_tests && \
stop_current_postgres && \
if [[ "$ENABLE_COVERAGE" == "1" ]]
Expand Down
2 changes: 2 additions & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GitPython==3.1.43
testgres==1.10.0
53 changes: 53 additions & 0 deletions scripts/test_wal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import testgres
import os

print("Starting replication/WAL tests...")

VECTOR_QUERY = "SELECT * FROM small_world WHERE b = FALSE order by v <-> '{1,0,0}' LIMIT 3;"

with testgres.get_new_node() as primary:

# run inidb
primary.init()

primary.append_conf('enable_seqscan = off')

primary.start()

primary.execute('CREATE EXTENSION lantern')
# testgres safe_psql does not support specifying cwd, so we have to change the cwd of the current
# script to make sure relative paths in the target sql file work in testgres
os.chdir('../test/sql')
primary.safe_psql(filename='hnsw_delete.sql')
# create a backup
with primary.backup() as backup:

# create and start a new replica
replica = backup.spawn_replica('replica').start()

# catch up with master node
replica.catchup()

# make sure we are using the index
assert 'Index Scan using small_world_v_idx on small_world' in str(primary.safe_psql(f"EXPLAIN {VECTOR_QUERY}"))
assert 'Index Scan using small_world_v_idx on small_world' in str(replica.safe_psql(f"EXPLAIN {VECTOR_QUERY}"))

res = replica.execute(VECTOR_QUERY)
assert res[0][2] == [1.0, 0.0, 0.0]
# take only boolean columns
assert [i[1] for i in res] == [False]

# Now, let's delete data on primary and see how it propagates to replica
primary.execute("INSERT INTO small_world (id, b, v) VALUES (42, FALSE, '{42,42,42}'), (43, FALSE, '{42,42,42}'), (44, FALSE, '{42,42,42}');")

res = replica.execute(VECTOR_QUERY)
# changes have not propagated yet
assert res[0][2] == [1.0, 0.0, 0.0]
assert [i[1] for i in res] == [False]
replica.catchup()
res = replica.execute(VECTOR_QUERY)
assert res[0][2] == [1.0, 0.0, 0.0]
assert [i[1] for i in res] == [False, False, False], 'failed %s' % res

print("WAL tests completed successfully!")

0 comments on commit aa9b4c2

Please sign in to comment.