Skip to content

Commit

Permalink
fix up test that assumed value as tie breaker
Browse files Browse the repository at this point in the history
  • Loading branch information
tantaman committed Oct 26, 2023
1 parent bec019b commit 0fc343d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion py/correctness/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# source env/bin/activate
# python -m pytest tests -s -k test_cl_merging
python3 -m pytest tests -s -k test_cl_merging.py
python3 -m pytest tests -s
22 changes: 20 additions & 2 deletions py/correctness/tests/test_cl_merging.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def make_simple_schema():
return c


def get_site_id(c):
return c.execute("SELECT crsql_site_id()").fetchone()[0]


def make_pko_schema():
c = connect(":memory:")
c.execute("CREATE TABLE foo (a INTEGER PRIMARY KEY NOT NULL) STRICT;")
Expand Down Expand Up @@ -812,11 +816,10 @@ def test_ordered_delta_merge_proxy(a_script, c_script):
close(b)
close(c)


# TODO: repeat above hypothesis tests with:
# 1. more tables
# 2. differing schemas (e.g., pk only tables, junction tables)


def test_larger_col_version_same_cl():
c1 = make_simple_schema()
c2 = make_simple_schema()
Expand All @@ -838,17 +841,32 @@ def test_larger_col_version_same_cl():
close(c2)


# should be a no-op.
# values do not break ties.
# site id loses on the merge
def test_larger_col_value_same_cl_and_col_version():
c1 = make_simple_schema()
c2 = make_simple_schema()

# greater site id wins so we need to swap
if get_site_id(c1) > get_site_id(c2):
temp = c1
c1 = c2
c2 = temp

c1.execute("INSERT INTO foo VALUES (1, 4)")
c1.commit()
c2.execute("INSERT INTO foo VALUES (1, 1)")
c2.commit()

sync_left_to_right(c1, c2, 0)

assert (c1.execute("SELECT * FROM foo").fetchall() !=
c2.execute("SELECT * FROM foo").fetchall())

sync_left_to_right(c2, c1, 0)

# swapping direcitons it'll merge because the other guy had the bigger site id
assert (c1.execute("SELECT * FROM foo").fetchall() ==
c2.execute("SELECT * FROM foo").fetchall())

Expand Down

0 comments on commit 0fc343d

Please sign in to comment.