Skip to content

Commit 4d7b462

Browse files
committed
Unflake the test
Unfortunately, the underlying race condition is a bit tricky to fix elegantly. `mod_carboncopy:remove_connection` is a handler for the `unset_presence` hook, and it removes CC state from the ejabberd_sm info field in the session record. This is however done in an async manner by the C2S process, and when the user terminates, the request is never handled. This doesn't matter much, as the user process exits shortly, and is removed from ejabberd_sm altogether. However, if it receives a message in this short time, CC might run, and see the process still with the CC state in the ejabberd_sm info field. This results in a CC copy sent on behalf of this exiting process. Since a fix would be overly complicated, and to proceed with unflaking the tests, the test will now wait for C2S process exit.
1 parent 952be3c commit 4d7b462

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

big_tests/tests/carboncopy_SUITE.erl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,20 @@ dropped_client_doesnt_create_duplicate_carbons(Config) ->
180180
fun(Alice1, Alice2, Bob) ->
181181
enable_carbons([Alice1, Alice2]),
182182
Msg = escalus_stanza:chat_to(Bob, ?BODY),
183+
C2SPid = mongoose_helper:get_session_pid(Alice2),
183184
escalus_client:stop(Config, Alice2),
184185
escalus:assert(is_presence_with_type, [<<"unavailable">>],
185186
escalus_client:wait_for_stanza(Alice1)),
187+
%% Ensure there is no session so that the test doesn't flake and fail by chance.
188+
%% The issue comes from the fact that mod_presence sends the "unavailable" stanza
189+
%% just before removing the is removed from ejabberd_sm. If the msg is received by
190+
%% mod_carboncopy in this short window, it still considers the resource enabled.
191+
%% It's a race condition, but from the user's perspective it shouldn't be a big issue.
192+
mongoose_helper:wait_for_pid_to_die(C2SPid),
186193
escalus_client:send(Alice1, Msg),
187194
escalus:assert(is_chat_message, [?BODY],
188195
escalus_client:wait_for_stanza(Bob)),
189-
[] = escalus_client:peek_stanzas(Alice1)
196+
escalus_assert:has_no_stanzas(Alice1)
190197
end).
191198

192199
prop_forward_received_chat_messages(Config) ->

0 commit comments

Comments
 (0)