Skip to content

Commit

Permalink
Merge pull request #4437 from esl/carboncopy-flaky-test
Browse files Browse the repository at this point in the history
Unflake the`dropped_client_doesnt_create_duplicate_carbons` test

The description of #4423 was not entirely correct, and this PR should unlflake the tests for good. The reason why the tests are changed, and not the implementation is because 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 they 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.
  • Loading branch information
NelsonVides authored Dec 17, 2024
2 parents a7c95ad + 4d7b462 commit c92b6b6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion big_tests/tests/carboncopy_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,20 @@ dropped_client_doesnt_create_duplicate_carbons(Config) ->
fun(Alice1, Alice2, Bob) ->
enable_carbons([Alice1, Alice2]),
Msg = escalus_stanza:chat_to(Bob, ?BODY),
C2SPid = mongoose_helper:get_session_pid(Alice2),
escalus_client:stop(Config, Alice2),
escalus:assert(is_presence_with_type, [<<"unavailable">>],
escalus_client:wait_for_stanza(Alice1)),
%% Ensure there is no session so that the test doesn't flake and fail by chance.
%% The issue comes from the fact that mod_presence sends the "unavailable" stanza
%% just before removing the is removed from ejabberd_sm. If the msg is received by
%% mod_carboncopy in this short window, it still considers the resource enabled.
%% It's a race condition, but from the user's perspective it shouldn't be a big issue.
mongoose_helper:wait_for_pid_to_die(C2SPid),
escalus_client:send(Alice1, Msg),
escalus:assert(is_chat_message, [?BODY],
escalus_client:wait_for_stanza(Bob)),
[] = escalus_client:peek_stanzas(Alice1)
escalus_assert:has_no_stanzas(Alice1)
end).

prop_forward_received_chat_messages(Config) ->
Expand Down

0 comments on commit c92b6b6

Please sign in to comment.