File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 11# pylint: disable=missing-docstring,redefined-outer-name
2+ import threading
3+ import time
24from datetime import datetime
35
46import pytest
@@ -85,3 +87,28 @@ def test_create_collection_with_collation_with_shard_key_index_prefix(
8587 )
8688
8789 t .compare_all_sharded ()
90+
91+ @pytest .mark .parametrize ("phase" , [Runner .Phase .APPLY , Runner .Phase .CLONE ])
92+ def test_shard_key_update_duplicate_key_error (t : Testing , phase : Runner .Phase ):
93+ """
94+ Test to reproduce pcsm duplicate key error when handling shard key updates
95+ """
96+ db_name = "test_db"
97+ collection_name = "test_collection"
98+ coll = t .source [db_name ][collection_name ]
99+ t .source .admin .command ("shardCollection" , f"{ db_name } .{ collection_name } " , key = {"key_id" : 1 })
100+ coll .insert_one ({"key_id" : 0 , "name" : "item_0" , "value" : "value_0" })
101+ def perform_shard_key_updates ():
102+ num_updates = 20
103+ for i in range (1 , num_updates + 1 ):
104+ key_id = 100 + i
105+ new_key_id = 5000 + i
106+ coll .insert_one ({"key_id" : key_id , "name" : f"test_doc_{ i } " , "value" : f"value_{ key_id } " })
107+ coll .update_one ({"key_id" : key_id }, {"$set" : {"key_id" : new_key_id , "shard_key_updated" : True }})
108+ time .sleep (0.05 )
109+ update_thread = threading .Thread (target = perform_shard_key_updates )
110+ update_thread .start ()
111+ with t .run (phase ):
112+ update_thread .join ()
113+ time .sleep (5 )
114+ t .compare_all_sharded ()
You can’t perform that action at this time.
0 commit comments