@@ -28,6 +28,10 @@ def make_simple_schema():
2828 return c
2929
3030
31+ def get_site_id (c ):
32+ return c .execute ("SELECT crsql_site_id()" ).fetchone ()[0 ]
33+
34+
3135def make_pko_schema ():
3236 c = connect (":memory:" )
3337 c .execute ("CREATE TABLE foo (a INTEGER PRIMARY KEY NOT NULL) STRICT;" )
@@ -812,11 +816,10 @@ def test_ordered_delta_merge_proxy(a_script, c_script):
812816 close (b )
813817 close (c )
814818
819+
815820# TODO: repeat above hypothesis tests with:
816821# 1. more tables
817822# 2. differing schemas (e.g., pk only tables, junction tables)
818-
819-
820823def test_larger_col_version_same_cl ():
821824 c1 = make_simple_schema ()
822825 c2 = make_simple_schema ()
@@ -838,17 +841,32 @@ def test_larger_col_version_same_cl():
838841 close (c2 )
839842
840843
844+ # should be a no-op.
845+ # values do not break ties.
846+ # site id loses on the merge
841847def test_larger_col_value_same_cl_and_col_version ():
842848 c1 = make_simple_schema ()
843849 c2 = make_simple_schema ()
844850
851+ # greater site id wins so we need to swap
852+ if get_site_id (c1 ) > get_site_id (c2 ):
853+ temp = c1
854+ c1 = c2
855+ c2 = temp
856+
845857 c1 .execute ("INSERT INTO foo VALUES (1, 4)" )
846858 c1 .commit ()
847859 c2 .execute ("INSERT INTO foo VALUES (1, 1)" )
848860 c2 .commit ()
849861
850862 sync_left_to_right (c1 , c2 , 0 )
851863
864+ assert (c1 .execute ("SELECT * FROM foo" ).fetchall () !=
865+ c2 .execute ("SELECT * FROM foo" ).fetchall ())
866+
867+ sync_left_to_right (c2 , c1 , 0 )
868+
869+ # swapping direcitons it'll merge because the other guy had the bigger site id
852870 assert (c1 .execute ("SELECT * FROM foo" ).fetchall () ==
853871 c2 .execute ("SELECT * FROM foo" ).fetchall ())
854872
0 commit comments