Skip to content

Commit 99f0fe8

Browse files
committed
Add replication test
1 parent b3b2836 commit 99f0fe8

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

ci/scripts/build-linux.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function install_platform_specific_dependencies() {
5353
popd
5454

5555
# dependencies of update tests
56-
sudo pip install GitPython
56+
sudo pip install GitPython testgres
5757
apt install -y ruby-full
5858
gem install bundler
5959

ci/scripts/run-tests-linux.sh

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function run_db_tests(){
5353
make test && \
5454
make test-parallel && \
5555
make test-client && \
56+
python3 ../scripts/test_wal.py && \
5657
run_pgvector_tests && \
5758
stop_current_postgres && \
5859
if [[ "$ENABLE_COVERAGE" == "1" ]]

scripts/test_wal.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import testgres
2+
import os
3+
4+
VECTOR_QUERY = "SELECT * FROM small_world WHERE b = FALSE order by v <-> '{1,0,0}' LIMIT 3;"
5+
6+
with testgres.get_new_node() as primary:
7+
8+
# run inidb
9+
primary.init()
10+
11+
primary.append_conf('enable_seqscan = off')
12+
13+
primary.start()
14+
15+
primary.execute('CREATE EXTENSION lantern')
16+
# testgres safe_psql does not support specifying cwd, so we have to change the cwd of the current
17+
# script to make sure relative paths in the target sql file work in testgres
18+
os.chdir('../test/sql')
19+
primary.safe_psql(filename='hnsw_delete.sql')
20+
# create a backup
21+
with primary.backup() as backup:
22+
23+
# create and start a new replica
24+
replica = backup.spawn_replica('replica').start()
25+
26+
# catch up with master node
27+
replica.catchup()
28+
29+
# make sure we are using the index
30+
assert 'Index Scan using small_world_v_idx on small_world' in str(primary.safe_psql(f"EXPLAIN {VECTOR_QUERY}"))
31+
assert 'Index Scan using small_world_v_idx on small_world' in str(replica.safe_psql(f"EXPLAIN {VECTOR_QUERY}"))
32+
33+
res = replica.execute(VECTOR_QUERY)
34+
assert res[0][2] == [1.0, 0.0, 0.0]
35+
# take only boolean columns
36+
assert [i[1] for i in res] == [False]
37+
38+
# Now, let's delete data on primary and see how it propagates to replica
39+
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}');")
40+
41+
res = replica.execute(VECTOR_QUERY)
42+
# changes have not propagated yet
43+
assert res[0][2] == [1.0, 0.0, 0.0]
44+
assert [i[1] for i in res] == [False]
45+
replica.catchup()
46+
res = replica.execute(VECTOR_QUERY)
47+
assert res[0][2] == [1.0, 0.0, 0.0]
48+
assert [i[1] for i in res] == [False, False, False], 'failed %s' % res
49+
50+
print("WAL tests completed successfully!")
51+

0 commit comments

Comments
 (0)