Skip to content

Commit

Permalink
fix test_merge_same_w_tie_breaker
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegn committed Dec 21, 2023
1 parent 4241005 commit 110df2d
Showing 1 changed file with 11 additions and 33 deletions.
44 changes: 11 additions & 33 deletions py/correctness/tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,46 +381,24 @@ def make_dbs():
assert (changes == [('foo', b'\x01\t\x01', 'b', 2, 1, 1, site_id, 1, 0)])

def test_merge_same_w_tie_breaker():
def make_dbs():
db1 = create_basic_db()
db2 = create_basic_db()
db1 = create_basic_db()
db2 = create_basic_db()

db1.execute("INSERT INTO foo (a,b) VALUES (1,2);")
db1.execute("SELECT crsql_config_set('merge-equal-values', 1);")
db1.commit()
db1.execute("INSERT INTO foo (a,b) VALUES (1,2);")
db1.execute("SELECT crsql_config_set('merge-equal-values', 1);")
db1.commit()

db2.execute("INSERT INTO foo (a,b) VALUES (1,2);")
db2.execute("SELECT crsql_config_set('merge-equal-values', 1);")
db2.commit()
return (db1, db2)
db2.execute("INSERT INTO foo (a,b) VALUES (1,2);")
db2.execute("SELECT crsql_config_set('merge-equal-values', 1);")
db2.commit()

(db1, db2) = make_dbs()
sync_left_to_right(db1, db2, 0)
changes = db2.execute("SELECT * FROM crsql_changes").fetchall()
changes12 = db2.execute("SELECT \"table\", pk, cid, val, col_version, site_id FROM crsql_changes").fetchall()

site_id1 = get_site_id(db1)
site_id2 = get_site_id(db2)

max_site_id = max(site_id1, site_id2)
version = 1;
if max_site_id != site_id1:
version = 2

assert (changes == [('foo', b'\x01\t\x01', 'b', 2, 1, version, max_site_id, 1, 0)])

(db1, db2) = make_dbs()
sync_left_to_right(db2, db1, 0)
changes = db2.execute("SELECT * FROM crsql_changes").fetchall()

site_id1 = get_site_id(db1)
site_id2 = get_site_id(db2)

max_site_id = max(site_id1, site_id2)
version = 1;
if max_site_id != site_id2:
version = 2
changes21 = db1.execute("SELECT \"table\", pk, cid, val, col_version, site_id FROM crsql_changes").fetchall()

assert (changes == [('foo', b'\x01\t\x01', 'b', 2, 1, version, max_site_id, 1, 0)])
assert (changes12 == changes21)


def test_merge_matching_clocks_lesser_value():
Expand Down

0 comments on commit 110df2d

Please sign in to comment.