Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,27 @@ jobs:
matrix:
include:
- pair:
elixir: 1.18
otp: 27
elixir: 1.20.x
otp: 29.x
- pair:
elixir: 1.17
otp: 27
elixir: 1.19.x
otp: 28.x
- pair:
elixir: 1.17
otp: 26
elixir: 1.18.x
otp: 27.x
- pair:
elixir: 1.16
otp: 26
elixir: 1.17.x
otp: 27.x
- pair:
elixir: 1.15
otp: 26
elixir: 1.17.x
otp: 26.x
- pair:
elixir: 1.16.x
otp: 26.x
- pair:
elixir: 1.15.x
otp: 26.x

steps:
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule EctoPSQLExtras.Mixfile do
{:ecto_sql, "~> 3.7"},
{:postgrex, "~> 0.16 or ~> 1.0"},
{:ex_doc, ">= 0.30.0", only: :dev, runtime: false},
{:mock, "~> 0.3.0", only: :test}
{:meck, "~> 1.2", only: :test}
]
end

Expand Down
5 changes: 1 addition & 4 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
%{
"connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"},
"db_connection": {:hex, :db_connection, "2.7.0", "b99faa9291bb09892c7da373bb82cba59aefa9b36300f6145c5f201c7adf48ec", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "dcf08f31b2701f857dfc787fbad78223d61a32204f217f15e881dd93e4bdd3ff"},
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
"earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"},
Expand All @@ -9,10 +8,8 @@
"makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"},
"makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"},
"meck": {:hex, :meck, "0.9.2", "85ccbab053f1db86c7ca240e9fc718170ee5bda03810a6292b5306bf31bae5f5", [:rebar3], [], "hexpm", "81344f561357dc40a8344afa53767c32669153355b626ea9fcbc8da6b3045826"},
"mock": {:hex, :mock, "0.3.8", "7046a306b71db2488ef54395eeb74df0a7f335a7caca4a3d3875d1fc81c884dd", [:mix], [{:meck, "~> 0.9.2", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm", "7fa82364c97617d79bb7d15571193fc0c4fe5afd0c932cef09426b3ee6fe2022"},
"meck": {:hex, :meck, "1.2.0", "c3618447506589a2931be80d006ea883aff156dd56e8822f7c1bb49896e94edb", [:rebar3], [], "hexpm", "a2cfd08306ef4992db7cd2aa3521b797456abec9f562f3f0341633052dee4af9"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"number": {:hex, :number, "1.0.3", "932c8a2d478a181c624138958ca88a78070332191b8061717270d939778c9857", [:mix], [{:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "dd397bbc096b2ca965a6a430126cc9cf7b9ef7421130def69bcf572232ca0f18"},
"postgrex": {:hex, :postgrex, "0.19.0", "f7d50e50cb42e0a185f5b9a6095125a9ab7e4abccfbe2ab820ab9aa92b71dbab", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "dba2d2a0a8637defbf2307e8629cb2526388ba7348f67d04ec77a5d6a72ecfae"},
"table_rex": {:hex, :table_rex, "4.0.0", "3c613a68ebdc6d4d1e731bc973c233500974ec3993c99fcdabb210407b90959b", [:mix], [], "hexpm", "c35c4d5612ca49ebb0344ea10387da4d2afe278387d4019e4d8111e815df8f55"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
Expand Down
58 changes: 37 additions & 21 deletions test/diagnose_logic_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ defmodule DiagnoseLogicTest do
alias EctoPSQLExtras.TestRepo

import ExUnit.CaptureIO
import Mock

setup do
start_supervised!(TestRepo)
Expand All @@ -16,8 +15,10 @@ defmodule DiagnoseLogicTest do
:ok
end

test_with_mock "it works", EctoPSQLExtras, [:passthrough],
unused_indexes: fn _repo, _opts ->
test "it works" do
:meck.new(EctoPSQLExtras, [:passthrough])

:meck.expect(EctoPSQLExtras, :unused_indexes, fn _repo, _opts ->
%Postgrex.Result{
columns: ["schema", "table", "index", "index_size", "index_scans"],
command: :select,
Expand All @@ -30,8 +31,9 @@ defmodule DiagnoseLogicTest do
["public", "public.channels", "index_channels_on_slack_id", 1_000_001, 7]
]
}
end,
null_indexes: fn _repo, _opts ->
end)

:meck.expect(EctoPSQLExtras, :null_indexes, fn _repo, _opts ->
%Postgrex.Result{
columns: [
"oid",
Expand Down Expand Up @@ -61,8 +63,9 @@ defmodule DiagnoseLogicTest do
]
]
}
end,
bloat: fn _repo, _opts ->
end)

:meck.expect(EctoPSQLExtras, :bloat, fn _repo, _opts ->
%Postgrex.Result{
columns: ["type", "schemaname", "object_name", "bloat", "waste"],
command: :select,
Expand All @@ -74,8 +77,9 @@ defmodule DiagnoseLogicTest do
["table", "public", "less_bloated_table_1", Decimal.from_float(1.4), 800]
]
}
end,
duplicate_indexes: fn _repo, _opts ->
end)

:meck.expect(EctoPSQLExtras, :duplicate_indexes, fn _repo, _opts ->
%Postgrex.Result{
columns: ["size", "idx1", "idx2", "idx3", "idx4"],
command: :select,
Expand All @@ -86,8 +90,9 @@ defmodule DiagnoseLogicTest do
["128 kb", "users_pkey", "index_users_id", nil, nil]
]
}
end,
outliers: fn _repo, _opts ->
end)

:meck.expect(EctoPSQLExtras, :outliers, fn _repo, _opts ->
%Postgrex.Result{
columns: ["query", "exec_time", "prop_exec_time", "ncalls", "sync_io_time"],
command: :select,
Expand All @@ -111,22 +116,33 @@ defmodule DiagnoseLogicTest do
]
]
}
end do
capture_io(fn ->
EctoPSQLExtras.diagnose(EctoPSQLExtras.TestRepo)
end)

result = EctoPSQLExtras.DiagnoseLogic.run(EctoPSQLExtras.TestRepo)
try do
{result, _} =
with_io(fn ->
EctoPSQLExtras.diagnose(EctoPSQLExtras.TestRepo, format: :raw)
end)

assert length(result.columns) == 3
assert Enum.at(Enum.at(result.rows, 0), 1) == "table_cache_hit"
assert Enum.at(Enum.at(result.rows, 0), 1) == "table_cache_hit"
assert length(result.columns) == 3
after
:meck.unload(EctoPSQLExtras)
end
end

@tag capture_log: true
test_with_mock "rescues random database errors", EctoPSQLExtras, [:passthrough],
unused_indexes: fn _repo, _opts ->
test "rescues random database errors" do
:meck.new(EctoPSQLExtras, [:passthrough])

:meck.expect(EctoPSQLExtras, :unused_indexes, fn _repo, _opts ->
raise "random error"
end do
EctoPSQLExtras.DiagnoseLogic.run(EctoPSQLExtras.TestRepo)
end)

try do
EctoPSQLExtras.DiagnoseLogic.run(EctoPSQLExtras.TestRepo)
after
:meck.unload(EctoPSQLExtras)
end
end
end
Loading