Skip to content

Commit

Permalink
Introduce test_myxql env
Browse files Browse the repository at this point in the history
In order to test code with both postgreqsl and myxql adapters, we use
a separate MIX_ENV `test_myxql`.

* test Repo adapter is determined at compile time.
* docker-compose-test adds a MySQL container
* to run the tests with myxql adapter, simply run `MIX_ENV=test_myxql
  mix test`
  • Loading branch information
Jean Parpaillon committed Aug 31, 2020
1 parent a69cf7a commit b655296
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ defmodule MyApp.Repo.Migrations.CreateJobQueue do
end
```

### Compatibility

`EctoJob` leverages specific PostgreSQL features, like notification mechanism
when inserting a new job into a queue.

However, a non-optimized version of `EctoJob` can be used on top of MySQL >=
8.0.1. Prior version of MySQL is not supported because of the following feature:
* `FOR UPDATE SKIP LOCKED`

### Upgrading to version 3.0

To upgrade your project to 3.0 version of `ecto_job` you must add a migration to update the pre-existent job queue tables:
Expand Down
16 changes: 16 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,19 @@ if Mix.env() == :test do

config :logger, level: :warn
end

if Mix.env() == :test_myxql do
config :ecto_job, EctoJob.Test.Repo,
adapter: Ecto.Adapters.MyXQL,
username: "mysql",
password: "password",
database: "ecto_job_test",
hostname: "localhost",
port: 13306,
pool: Ecto.Adapters.SQL.Sandbox,
priv: "test/support/"

config :ecto_job, ecto_repos: [EctoJob.Test.Repo]

config :logger, level: :warn
end
11 changes: 11 additions & 0 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ services:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
- POSTGRES_DB=ecto_job_test

ecto-job-test-mysql:
image: mysql:latest
ports:
- "13306:3306"
environment:
- MYSQL_USER=mysql
- MYSQL_PASSWORD=password
- MYSQL_DATABASE=ecto_job_test
- MYSQL_ROOT_PASSWORD=mysql
- MYSQL_ROOT_HOST=%
11 changes: 8 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ defmodule EctoJob.Mixfile do
end

def application do
[extra_applications: [:logger]]
[extra_applications: [:logger] ++ extra_applications(Mix.env())]
end

defp elixirc_paths(:test), do: ["lib", "test/support"]
defp extra_applications(:test), do: [:postgrex]
defp extra_applications(:test_myxql), do: [:myxql]
defp extra_applications(_), do: []

defp elixirc_paths(test) when test in [:test, :test_myxql], do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]

defp package do
Expand Down Expand Up @@ -56,7 +60,8 @@ defmodule EctoJob.Mixfile do
defp deps do
[
{:ecto_sql, "~> 3.2"},
{:postgrex, "~> 0.15"},
{:postgrex, "~> 0.15", optional: true},
{:myxql, "~> 0.2", optional: true},
{:jason, "~> 1.0"},
{:gen_stage, "~> 1.0"},
{:credo, "~> 1.0", only: :dev, runtime: false},
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fdf843bca858203ae1de16da2ee206f53416bbda5dc8c9e78f43243de4bc3afe"},
"makeup": {:hex, :makeup, "1.0.0", "671df94cf5a594b739ce03b0d0316aa64312cee2574b6a44becb83cd90fb05dc", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "a10c6eb62cca416019663129699769f0c2ccf39428b3bb3c0cb38c718a0c186d"},
"makeup_elixir": {:hex, :makeup_elixir, "0.14.0", "cf8b7c66ad1cff4c14679698d532f0b5d45a3968ffbcbfd590339cb57742f1ae", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "d4b316c7222a85bbaa2fd7c6e90e37e953257ad196dc229505137c5e505e9eff"},
"myxql": {:hex, :myxql, "0.2.10", "18fb7ce67dd8ab6f5672e94a944ae90157231b637db14fc92ab77c50e33cd83a", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "b9d48449845378693dca7367694cbd75a192d5674bf7d19ca4c924c96818d275"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.1", "c90796ecee0289dbb5ad16d3ad06f957b0cd1199769641c961cfe0b97db190e0", [:mix], [], "hexpm", "00e3ebdc821fb3a36957320d49e8f4bfa310d73ea31c90e5f925dc75e030da8f"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
"postgrex": {:hex, :postgrex, "0.15.1", "23ce3417de70f4c0e9e7419ad85bdabcc6860a6925fe2c6f3b1b5b1e8e47bf2f", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "12cd418e207b8ed787dfe0f520fccd6c001f58d9108233feae7df36462593d1f"},
Expand Down
3 changes: 2 additions & 1 deletion test/support/repo.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
defmodule EctoJob.Test.Repo do
use Ecto.Repo, otp_app: :ecto_job, adapter: Ecto.Adapters.Postgres
adapter = Application.compile_env!(:ecto_job, __MODULE__)[:adapter]
use Ecto.Repo, otp_app: :ecto_job, adapter: adapter
end

0 comments on commit b655296

Please sign in to comment.