@@ -136,3 +136,43 @@ def test_two_parallel_realtime_simultaneously(acfactory, path_to_webxdc):
136
136
137
137
wait_receive_realtime_data ([(ac1_webxdc_msg , [30 ]), (ac1_webxdc_msg2 , [40 ])])
138
138
wait_receive_realtime_data ([(ac2_webxdc_msg , [10 ]), (ac2_webxdc_msg2 , [20 ])])
139
+
140
+
141
+ def test_no_duplicate_messages (acfactory , path_to_webxdc ):
142
+ """Test that messages are received only once."""
143
+ ac1 , ac2 = acfactory .get_online_accounts (2 )
144
+
145
+ ac1_ac2_chat = ac1 .create_chat (ac2 )
146
+
147
+ ac1_webxdc_msg = ac1_ac2_chat .send_message (text = "webxdc" , file = path_to_webxdc )
148
+
149
+ ac1_webxdc_msg .send_webxdc_realtime_advertisement
150
+
151
+ ac2_webxdc_msg = ac2 .wait_for_incoming_msg ()
152
+ ac2_webxdc_msg .get_snapshot ().chat .accept ()
153
+ assert ac2_webxdc_msg .get_snapshot ().text == "webxdc"
154
+
155
+ # Issue a "send" call in parallel with sending advertisement.
156
+ # Previously due to a bug this caused subscribing to the channel twice.
157
+ future = ac2_webxdc_msg .send_webxdc_realtime_data .future (b"foobar" )
158
+ ac2_webxdc_msg .send_webxdc_realtime_advertisement ()
159
+
160
+ def thread_run ():
161
+ for i in range (10 ):
162
+ data = str (i ).encode ()
163
+ ac1_webxdc_msg .send_webxdc_realtime_data (data )
164
+ time .sleep (1 )
165
+
166
+ threading .Thread (target = thread_run , daemon = True ).start ()
167
+
168
+ while 1 :
169
+ event = ac2 .wait_for_event ()
170
+ if event .kind == EventType .WEBXDC_REALTIME_DATA :
171
+ n = int (bytes (event .data ).decode ())
172
+ break
173
+
174
+ while 1 :
175
+ event = ac2 .wait_for_event ()
176
+ if event .kind == EventType .WEBXDC_REALTIME_DATA :
177
+ assert int (bytes (event .data ).decode ()) > n
178
+ break
0 commit comments