diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4360dea --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,35 @@ +name: CI + +on: + pull_request: + push: + branches: [xmpp_only] + +permissions: + contents: read + +concurrency: + group: ci-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + eunit: + # x86_64: xmpp, the consumer of this fork, deploys on x86_64. + runs-on: ubuntu-26.04 + timeout-minutes: 15 + services: + redis: + image: redis:7@sha256:2e3eb11462c4e3759e6972678dd051d150ff54b1e60714b3c33b701260172a90 + ports: + - 6379:6379 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + # OTP 22.3 matches xmpp's build image. Host network because the tests + # connect to Redis on 127.0.0.1:6379. + - name: rebar3 eunit (OTP 22) + run: >- + docker run --rm --network host -v "$PWD:/w" -w /w + erlang:22@sha256:fe2c572ef1aaed67214c5529b57311f0806f58696fcb2f2a1c9bf33bdc75fe43 + rebar3 eunit diff --git a/rebar.config b/rebar.config index dd1c7f3..fea3f4b 100644 --- a/rebar.config +++ b/rebar.config @@ -6,4 +6,4 @@ %% This allows this project to be used as a dependency by other rebar projects %% that use xref. {xref_checks, []}. -{profiles, [{test, [{deps, [{meck, "1.2.0"}]}]}]}. +{profiles, [{test, [{deps, [{meck, "0.9.2"}]}]}]}. diff --git a/test/eredis_sub_tests.erl b/test/eredis_sub_tests.erl index f154417..2651adc 100644 --- a/test/eredis_sub_tests.erl +++ b/test/eredis_sub_tests.erl @@ -134,7 +134,9 @@ crash_queue_test() -> [eredis:q(Pub, [publish, foo, N]) || N <- lists:seq(1, 12)], receive M1 -> ?assertEqual({message,<<"foo">>,<<"1">>, Sub}, M1) end, - receive M2 -> ?assertEqual({'DOWN', Ref, process, Sub, max_queue_size}, M2) end. + %% The fork tells the controller before it exits (9427287). + receive M2 -> ?assertMatch({exited, _}, M2) end, + receive M3 -> ?assertEqual({'DOWN', Ref, process, Sub, max_queue_size}, M3) end. diff --git a/test/eredis_tests.erl b/test/eredis_tests.erl index 1e3244b..e247549 100644 --- a/test/eredis_tests.erl +++ b/test/eredis_tests.erl @@ -167,7 +167,9 @@ connection_failure_during_start_no_reconnect_test() -> connection_failure_during_start_reconnect_test() -> process_flag(trap_exit, true), - Res = eredis:start_link("localhost", 6378, 0, "", 100), + %% start_link/5 connects synchronously in this fork (49c714f), so ask for + %% the async start this test covers. + Res = eredis:start_link("localhost", 6378, 0, "", 100, 5000, false, [], false), ?assertMatch({ok, _}, Res), {ok, ClientPid} = Res, IsDead = receive {'EXIT', ClientPid, _} -> died @@ -184,24 +186,30 @@ tcp_closed_no_reconnect_test() -> tcp_closed_rig(C). tcp_closed_rig(C) -> - %% fire async requests to add to redis client queue and then trick - %% the client into thinking the connection to redis has been - %% closed. This behavior can be observed when Redis closes an idle - %% connection just as a traffic burst starts. - DoSend = fun(tcp_closed) -> - C ! {tcp_closed, fake_socket}; - (Cmd) -> - eredis:q(C, Cmd) - end, - %% attach an id to each message for later - Msgs = [{1, ["GET", "foo"]}, - {2, ["GET", "bar"]}, - {3, tcp_closed}], - Pids = [ remote_query(DoSend, M) || M <- Msgs ], + %% Queue two requests on the client, then trick it into thinking the + %% connection to redis has been closed. This behavior can be observed + %% when Redis closes an idle connection just as a traffic burst starts. + %% The client is suspended until both requests sit in its mailbox, so + %% the fake close always lands after them and before any Redis reply + %% (nothing reaches the socket until the client resumes). + ok = sys:suspend(C), + Pids = [ remote_query(fun(Cmd) -> eredis:q(C, Cmd) end, M) + || M <- [{1, ["GET", "foo"]}, {2, ["GET", "bar"]}] ], + ok = wait_for_queue_len(C, 2, 100), + C ! {tcp_closed, fake_socket}, + ok = sys:resume(C), Results = gather_remote_queries(Pids), ?assertEqual({error, tcp_closed}, proplists:get_value(1, Results)), ?assertEqual({error, tcp_closed}, proplists:get_value(2, Results)). +wait_for_queue_len(_Pid, _Len, 0) -> + {error, queue_len_timeout}; +wait_for_queue_len(Pid, Len, Tries) -> + case process_info(Pid, message_queue_len) of + {message_queue_len, N} when N >= Len -> ok; + _ -> timer:sleep(10), wait_for_queue_len(Pid, Len, Tries - 1) + end. + remote_query(Fun, {Id, Cmd}) -> Parent = self(), spawn(fun() ->