Skip to content

Commit 3545ede

Browse files
[python] Fix flaky test_concurrent_updates_overlapping_rows_last_writer_wins
The test derived the winner from completion_order[-1] (the order threads returned in), which is not the commit order, so under CI load it diverged from the persisted data and failed intermittently. Tag each thread's commits with a distinct commit.user-prefix and read the true winner from the latest snapshot's commit_user, then assert the persisted rows equal that thread's whole update and the untouched rows keep their seed values.
1 parent 7234e4c commit 3545ede

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

paimon-python/pypaimon/tests/table_update_test.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,9 +1093,12 @@ def _run_concurrent_updates(self, table, thread_specs, max_retries):
10931093
)
10941094

10951095
def worker(idx, spec):
1096+
# Tag each thread's commits so the durable winner can be read back from the
1097+
# latest snapshot's commit_user (the order threads return in is not the commit order).
1098+
worker_table = table.copy({'commit.user-prefix': 'w%d' % idx})
10961099
for _ in range(max_retries):
10971100
try:
1098-
self._do_update(table, pa.Table.from_pydict({
1101+
self._do_update(worker_table, pa.Table.from_pydict({
10991102
'_ROW_ID': spec['row_ids'],
11001103
'age': spec['ages'],
11011104
}), ['age'])
@@ -1142,13 +1145,11 @@ def test_concurrent_updates_overlapping_rows_last_writer_wins(self):
11421145
{'row_ids': [0, 1, 2], 'ages': [102, 202, 302]},
11431146
{'row_ids': [0, 1, 2], 'ages': [103, 203, 303]},
11441147
]
1145-
completion_order = self._run_concurrent_updates(
1146-
table, specs, max_retries=30
1147-
)
1148-
winner = specs[completion_order[-1]]['ages']
1148+
self._run_concurrent_updates(table, specs, max_retries=30)
11491149
ages = self._read_all(table)['age'].to_pylist()
1150-
self.assertEqual(winner, ages[:3])
1151-
# Rows 3 & 4 must remain at seed values
1150+
# The real winner is the thread whose commit produced the latest snapshot.
1151+
winner = int(table.snapshot_manager().get_latest_snapshot().commit_user[1:].split('_')[0])
1152+
self.assertEqual(specs[winner]['ages'], ages[:3])
11521153
self.assertEqual([40, 45], ages[3:])
11531154

11541155
def test_update_list_and_map_columns(self):

0 commit comments

Comments
 (0)