From 32151fb32c3e8c528c2b297fb21055948200266a Mon Sep 17 00:00:00 2001 From: Janusz Jakubiec Date: Fri, 23 Aug 2024 12:35:20 +0200 Subject: [PATCH 1/2] Fixing GraphQL SSE crash with large stanza payloads --- big_tests/tests/graphql_sse_SUITE.erl | 4 ++++ src/graphql/mongoose_graphql_response.erl | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/big_tests/tests/graphql_sse_SUITE.erl b/big_tests/tests/graphql_sse_SUITE.erl index 8a7a097c3ea..a48b4e03894 100644 --- a/big_tests/tests/graphql_sse_SUITE.erl +++ b/big_tests/tests/graphql_sse_SUITE.erl @@ -145,6 +145,10 @@ sse_should_not_get_timeout(Config) -> timer:sleep(2000), escalus:send(Bob, escalus_stanza:chat(From, To, <<"Hello again!">>)), sse_helper:wait_for_event(Stream), + timer:sleep(2000), + Message = binary:copy(<<"0">>, 2000), + escalus:send(Bob, escalus_stanza:chat(From, To, Message)), + sse_helper:wait_for_event(Stream), sse_helper:stop_sse(Stream) end). diff --git a/src/graphql/mongoose_graphql_response.erl b/src/graphql/mongoose_graphql_response.erl index f8a44fec83b..64d5602393b 100644 --- a/src/graphql/mongoose_graphql_response.erl +++ b/src/graphql/mongoose_graphql_response.erl @@ -3,10 +3,10 @@ -export([term_to_json/1, term_to_pretty_json/1]). term_to_json(Term) -> - jiffy:encode(fixup(Term)). + iolist_to_binary(jiffy:encode(fixup(Term))). term_to_pretty_json(Term) -> - jiffy:encode(fixup(Term), [pretty]). + iolist_to_binary(jiffy:encode(fixup(Term), [pretty])). %% Ground types fixup(Term) when is_number(Term) -> Term; From 398fffd28fa25872c562b2d70ed3e6b8ad6eb432 Mon Sep 17 00:00:00 2001 From: Janusz Jakubiec Date: Mon, 26 Aug 2024 15:44:43 +0200 Subject: [PATCH 2/2] Fixing CR comments --- big_tests/tests/graphql_sse_SUITE.erl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/big_tests/tests/graphql_sse_SUITE.erl b/big_tests/tests/graphql_sse_SUITE.erl index a48b4e03894..6937e45f0cf 100644 --- a/big_tests/tests/graphql_sse_SUITE.erl +++ b/big_tests/tests/graphql_sse_SUITE.erl @@ -21,7 +21,7 @@ all() -> groups() -> [{admin, [parallel], admin_tests()}, {user, [parallel], user_tests()}, - {timeout, [], [sse_should_not_get_timeout]}]. + {timeout, [parallel], [sse_should_not_get_timeout, sse_works_with_long_messages]}]. init_per_suite(Config) -> Config1 = escalus:init_per_suite(Config), @@ -145,7 +145,14 @@ sse_should_not_get_timeout(Config) -> timer:sleep(2000), escalus:send(Bob, escalus_stanza:chat(From, To, <<"Hello again!">>)), sse_helper:wait_for_event(Stream), - timer:sleep(2000), + sse_helper:stop_sse(Stream) + end). + +sse_works_with_long_messages(Config) -> + escalus:fresh_story(Config, [{alice, 1}, {bob, 1}], fun (Alice, Bob) -> + From = escalus_client:full_jid(Bob), + To = escalus_client:short_jid(Alice), + {200, Stream} = graphql_helper:execute_user_command_sse(<<"stanza">>, <<"subscribeForMessages">>, Alice, #{}, Config), Message = binary:copy(<<"0">>, 2000), escalus:send(Bob, escalus_stanza:chat(From, To, Message)), sse_helper:wait_for_event(Stream),