0

I use exq in my Phoenix application with Phoenix 1.4.16 to run some background jobs.

One of them can be as simple as this:

defmodule PeopleJob do
  def perform(request) do
    IO.puts("Hello from PeopleJob:\n#{inspect(request)}")
  end
end

It runs with redis in dev environment perfectly.

The problem is that when I push the code to a CI server that has no redis, all the tests fail.

The test config is like this

In config/test.exs:

config :exq, queue_adapter: Exq.Adapters.Queue.Mock

In test/test_helper.exs:

Exq.Mock.start_link(mode: :inline)

When I run "mix test" on a machine without redis running, it fails like this:

** (Mix) Could not start application exq: Exq.start(:normal, []) returned an error: shutdown: failed to start child: Exq.Manager.Server
    ** (EXIT) an exception was raised:
        ** (RuntimeError)


====================================================================================================
ERROR! Could not connect to Redis!

Configuration passed in: [host: "127.0.0.1", port: 6379, database: 0, password: nil]
Error: :error
Reason: {:badmatch, {:error, %Redix.ConnectionError{reason: :closed}}}

Make sure Redis is running, and your configuration matches Redis settings.
====================================================================================================

            (exq) lib/exq/manager/server.ex:393: Exq.Manager.Server.check_redis_connection/1
            (exq) lib/exq/manager/server.ex:173: Exq.Manager.Server.init/1
            (stdlib) gen_server.erl:374: :gen_server.init_it/2
            (stdlib) gen_server.erl:342: :gen_server.init_it/6
            (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

Actually I try all 3 modes :redis, :fake and :inline, but all of them fail to start the mix test.

Question: Can I run "mix test" on a machine that has no redis?

The reason is that our company doesn't want to install redis on the Travis CI machine.

I expected that using Exq Mock in the test environment would allow the test to run without redis, but it is not the case.

Adam Millerchip
  • 20,844
  • 5
  • 51
  • 74
Châu Hồng Lĩnh
  • 1,986
  • 1
  • 20
  • 23
  • On which line have you placed `Exq.Mock.start_link(mode: :inline)` in `test_helper.exs`? Try to add it as the first line. – achempion Apr 18 '20 at 20:37
  • I add it at the last line of `test_helper.exs` Actually I solve this problem by adding this to `config/test.exs`: config :exq, start_on_application: false – Châu Hồng Lĩnh Apr 20 '20 at 01:59

1 Answers1

1

I figure it out.

In config/test.exs:

config :exq, queue_adapter: Exq.Adapters.Queue.Mock
config :exq, start_on_application: false

In test/test_helper.exs:

Exq.Mock.start_link(mode: :inline)

Adding config :exq, start_on_application: false to config/test.exs solved this problem.

Châu Hồng Lĩnh
  • 1,986
  • 1
  • 20
  • 23