Packages
exq
0.4.4
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/test_helper.exs
defmodule TestStats do
alias Exq.Redis.Connection
alias Exq.Redis.JobQueue
def processed_count(redis, namespace) do
count = Connection.get!(redis, JobQueue.full_key(namespace, "stat:processed"))
{:ok, count}
end
def failed_count(redis, namespace) do
count = Connection.get!(redis, JobQueue.full_key(namespace, "stat:failed"))
{:ok, count}
end
end
defmodule ExqTestUtil do
@timeout 20
@long_timeout 100
def redis_host do
Exq.Support.Config.get(:host)
end
def redis_port do
Exq.Support.Config.get(:port)
end
import ExUnit.Assertions
defmodule SendWorker do
def perform(pid) do
send String.to_atom(pid), {:worked}
end
end
def assert_exq_up(exq) do
my_pid = String.to_atom(UUID.uuid4)
Process.register(self, my_pid)
{:ok, _} = Exq.enqueue(exq, "default", "ExqTestUtil.SendWorker", [my_pid])
wait_long
ExUnit.Assertions.assert_received {:worked}
Process.unregister(my_pid)
end
def stop_process(pid) do
try do
Process.exit(pid, :shutdown)
rescue
e in RuntimeError -> e
end
end
def wait do
:timer.sleep(@timeout)
end
def wait_long do
:timer.sleep(@long_timeout)
end
def reset_config do
config = Mix.Config.read!(Path.join([Path.dirname(__DIR__), "config", "config.exs"]))
Mix.Config.persist(config)
end
end
defmodule TestRedis do
import ExqTestUtil
alias Exq.Redis.Connection
#TODO: Automate config
def start do
unless Exq.Support.Config.get(:test_with_local_redis) == false do
[] = :os.cmd('redis-server test/test-redis.conf')
:timer.sleep(100)
end
end
def stop do
unless Exq.Support.Config.get(:test_with_local_redis) == false do
[] = :os.cmd('redis-cli -p 6555 shutdown')
end
end
def setup do
{:ok, redis} = :eredis.start_link(redis_host, redis_port)
Process.register(redis, :testredis)
flush_all
:ok
end
def flush_all do
Connection.flushdb! :testredis
end
def teardown do
if !Process.whereis(:testredis) do
# For some reason at the end of test the link is down, before we acutally stop and unregister?
{:ok, redis} = :eredis.start_link(redis_host, redis_port)
Process.register(redis, :testredis)
end
Process.unregister(:testredis)
:ok
end
end
# Don't run parallel tests to prevent redis issues
# Exclude longer running failure condition tests by default
ExUnit.configure(seed: 0, max_cases: 1, exclude: [failure_scenarios: true])
# Start logger
:application.start(:logger)
TestRedis.start
System.at_exit fn(status) ->
TestRedis.stop
end
ExUnit.start