Packages
exq
0.8.2
0.24.0
0.23.0
0.22.0
0.21.0
0.20.0
0.19.0
0.18.0
0.17.0
0.16.2
0.16.1
0.16.0
0.15.0
0.14.0
0.13.5
0.13.4
0.13.3
0.13.2
0.13.1
0.13.0
0.12.2
0.12.1
0.12.0
0.11.0
0.10.1
0.10.0
0.9.1
0.9.0
0.8.7
0.8.6
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.3
0.7.2
0.7.1
0.7.0
0.6.5
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.0
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.0
0.2.3
0.2.2
0.2.1
0.2.0
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
0.0.2
Exq is a job processing library compatible with Resque / Sidekiq for the Elixir language.
Current section
Files
Jump to
Current section
Files
test/failure_scenarios_test.exs
defmodule FailureScenariosTest do
use ExUnit.Case
import ExqTestUtil
@moduletag :failure_scenarios
defmodule PerformWorker do
def perform do
send :exqtest, {:worked}
end
end
defmodule SleepWorker do
def perform do
send :exqtest, {:worked}
Process.register(self, :sleep_worker )
:timer.sleep(:infinity)
end
end
setup do
TestRedis.setup
Application.start(:ranch)
on_exit fn ->
wait
TestRedis.teardown
end
:ok
end
test "handle Redis connection lost on manager" do
conn = FlakyConnection.start(redis_host, redis_port)
{:ok, _} = Exq.start_link(port: conn.port)
wait_long
# Stop Redis and wait for a bit
FlakyConnection.stop(conn)
# Not ideal - but seems to be min time for manager to die past supervision
:timer.sleep(5100)
# Restart Flakey connection manually, things should be back to normal
{:ok, agent} = Agent.start_link(fn -> [] end)
{:ok, _} = :ranch.start_listener(conn.ref, 100, :ranch_tcp, [port: conn.port],
FlakyConnectionHandler, ['127.0.0.1', redis_port, agent])
wait_long
assert_exq_up(Exq)
Exq.stop(Exq)
end
test "handle Redis connection lost on enqueue" do
conn = FlakyConnection.start(redis_host, redis_port)
# Start Exq but don't listen to any queues
{:ok, _} = Exq.start_link(port: conn.port)
wait_long
# Stop Redis
FlakyConnection.stop(conn)
wait_long
# enqueue with redis stopped
enq_result = Exq.enqueue(Exq, "default", "FakeWorker", [])
assert enq_result == {:error, :closed}
enq_result = Exq.enqueue_at(Exq, "default", DateTime.utc_now, ExqTest.PerformWorker, [])
assert enq_result == {:error, :closed}
# Starting Redis again and things should be back to normal
wait_long
# Restart Flakey connection manually
{:ok, agent} = Agent.start_link(fn -> [] end)
{:ok, _} = :ranch.start_listener(conn.ref, 100, :ranch_tcp, [port: conn.port],
FlakyConnectionHandler, ['127.0.0.1', redis_port, agent])
wait_long
assert_exq_up(Exq)
Exq.stop(Exq)
end
test "handle supervisor tree shutdown properly" do
{:ok, sup} = Exq.start_link
assert Process.alive?(sup) == true
# Create worker that sleeps infinitely with registered process
{:ok, _jid} = Exq.enqueue(Exq, "default", FailureScenariosTest.SleepWorker, [])
Process.register(self, :exqtest)
# wait until worker started
assert_receive {:worked}, 500
stop_process(sup)
# Takes 5500 for worker to stop
:timer.sleep(5500)
# Make sure everything is shut down properly
assert Process.alive?(sup) == false
assert Process.whereis(Exq.Manager.Server) == nil
assert Process.whereis(Exq.Stats.Server) == nil
assert Process.whereis(Exq.Scheduler.Server) == nil
assert Process.whereis(:sleep_worker) == nil
end
end