diff --git a/mix.exs b/mix.exs index 698e90c..f3f7a0b 100644 --- a/mix.exs +++ b/mix.exs @@ -25,7 +25,7 @@ defmodule Mariaex.Mixfile do defp deps do [{:decimal, "~> 1.2"}, - {:db_connection, "~> 1.1", github: "elixir-ecto/db_connection", ref: "4947966"}, + {:db_connection, "~> 2.0.0-dev", github: "elixir-ecto/db_connection", ref: "6d477c"}, {:coverex, "~> 1.4.10", only: :test}, {:ex_doc, ">= 0.0.0", only: :dev}, {:poison, ">= 0.0.0", optional: true}] diff --git a/mix.lock b/mix.lock index 8b1958d..a069ae4 100644 --- a/mix.lock +++ b/mix.lock @@ -2,7 +2,7 @@ "certifi": {:hex, :certifi, "0.7.0", "861a57f3808f7eb0c2d1802afeaae0fa5de813b0df0979153cbafcd853ababaf", [:rebar3], [], "hexpm"}, "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"}, "coverex": {:hex, :coverex, "1.4.10", "f6b68f95b3d51d04571a09dd2071c980e8398a38cf663db22b903ecad1083d51", [:mix], [{:httpoison, "~> 0.9", [hex: :httpoison, repo: "hexpm", optional: false]}, {:poison, "~> 1.5 or ~> 2.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, - "db_connection": {:git, "https://github.com/elixir-ecto/db_connection.git", "49479667131329376adf1c2c0e9a16bcf470aa84", [ref: "4947966"]}, + "db_connection": {:git, "https://github.com/elixir-ecto/db_connection.git", "6d477c1030cd527fb87b01e2ca61b73bc4a9cd21", [ref: "6d477c"]}, "decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"}, "earmark": {:hex, :earmark, "1.0.3", "89bdbaf2aca8bbb5c97d8b3b55c5dd0cff517ecc78d417e87f1d0982e514557b", [:mix], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.14.5", "c0433c8117e948404d93ca69411dd575ec6be39b47802e81ca8d91017a0cf83c", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, diff --git a/test/query_test.exs b/test/query_test.exs index 36f3948..4ff50e3 100644 --- a/test/query_test.exs +++ b/test/query_test.exs @@ -1,8 +1,9 @@ defmodule QueryTest do use ExUnit.Case, async: true import Mariaex.TestHelper + import ExUnit.CaptureLog - @opts [database: "mariaex_test", username: "mariaex_user", password: "mariaex_pass", cache_size: 2, backoff_type: :stop] + @opts [database: "mariaex_test", username: "mariaex_user", password: "mariaex_pass", cache_size: 2, backoff_type: :stop, max_restarts: 0] setup context do connection_opts = context[:connection_opts] || [] @@ -36,14 +37,16 @@ defmodule QueryTest do end test "queries are dequeued after previous query is processed", context do + Process.flag(:trap_exit, true) conn = context[:pid] - Process.flag(:trap_exit, true) - capture_log fn -> - assert_raise DBConnection.ConnectionError, "tcp recv: closed", - fn -> query("DO SLEEP(10)", [], timeout: 50) end - assert_receive {:EXIT, ^conn, {:shutdown, %DBConnection.ConnectionError{}}} - end + assert capture_log(fn -> + assert_raise DBConnection.ConnectionError, "tcp recv: closed", fn -> + query("DO SLEEP(10)", [], timeout: 50) + end + + assert_receive {:EXIT, ^conn, :killed}, 5000 + end) =~ "** (DBConnection.ConnectionError)" end test "support primitive data types using prepared statements", context do diff --git a/test/start_test.exs b/test/start_test.exs index 9b79cf5..8e03c9a 100644 --- a/test/start_test.exs +++ b/test/start_test.exs @@ -1,14 +1,25 @@ defmodule StartTest do use ExUnit.Case, async: true + import ExUnit.CaptureLog test "connection_errors" do - Process.flag :trap_exit, true - assert {:error, {%Mariaex.Error{mariadb: %{message: "Unknown database 'non_existing'"}}, _}} = - Mariaex.Connection.start_link(username: "mariaex_user", password: "mariaex_pass", database: "non_existing", sync_connect: true, backoff_type: :stop) - assert {:error, {%Mariaex.Error{mariadb: %{message: "Access denied for user " <> _}}, _}} = - Mariaex.Connection.start_link(username: "non_existing", database: "mariaex_test", sync_connect: true, backoff_type: :stop) - assert {:error, {%Mariaex.Error{message: "tcp connect: econnrefused"}, _}} = - Mariaex.Connection.start_link(username: "mariaex_user", password: "mariaex_pass", database: "mariaex_test", port: 60999, sync_connect: true, backoff_type: :stop) + Process.flag(:trap_exit, true) + opts = [sync_connect: true, backoff_type: :stop, max_restarts: 0] + + assert capture_log(fn -> + {:ok, pid} = Mariaex.start_link([username: "mariaex_user", password: "mariaex_pass", database: "non_existing"] ++ opts) + assert_receive {:EXIT, ^pid, :killed}, 5000 + end) =~ "** (Mariaex.Error) (1049): Unknown database 'non_existing'" + + assert capture_log(fn -> + {:ok, pid} = Mariaex.start_link([username: "non_existing", database: "mariaex_test"] ++ opts) + assert_receive {:EXIT, ^pid, :killed}, 5000 + end) =~ "** (Mariaex.Error) (1045): Access denied for user 'non_existing'@'localhost'" + + assert capture_log(fn -> + {:ok, pid} = Mariaex.start_link([username: "mariaex_user", password: "mariaex_pass", database: "mariaex_test", port: 60999] ++ opts) + assert_receive {:EXIT, ^pid, :killed}, 5000 + end) =~ "** (Mariaex.Error) tcp connect: econnrefused" end ## Tests tagged with :ssl_tests are excluded from running by default (see test_helper.exs) diff --git a/test/test_helper.exs b/test/test_helper.exs index 0834724..eb192ff 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -158,12 +158,6 @@ defmodule Mariaex.TestHelper do end end - def capture_log(fun) do - Logger.remove_backend(:console) - fun.() - Logger.add_backend(:console, flush: true) - end - def length_encode_row(row) do Enum.map_join(row, &(<> <> &1)) end diff --git a/test/transaction_test.exs b/test/transaction_test.exs index c650784..ffac103 100644 --- a/test/transaction_test.exs +++ b/test/transaction_test.exs @@ -30,7 +30,6 @@ defmodule TransactionTest do {conn, _} = DBConnection.begin!(pid, opts) assert {:error, %DBConnection.TransactionError{status: :transaction}} = DBConnection.begin(conn, opts) - DBConnection.commit!(conn, opts) end test "can not commit or rollback transaction if not begun", context do