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
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ defmodule RustlerPrecompiled.MixProject do
defp deps do
[
{:rustler, "~> 0.23", optional: true},
{:ex_doc, "~> 0.27", only: :dev},
{:bypass, "~> 2.1", only: :test}
{:ex_doc, "~> 0.40", only: :dev},
{:passby, ">= 0.0.0", only: :test}
]
end

Expand Down
23 changes: 7 additions & 16 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
%{
"bypass": {:hex, :bypass, "2.1.0", "909782781bf8e20ee86a9cabde36b259d44af8b9f38756173e8f5e2e1fabb9b1", [:mix], [{:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "d9b5df8fa5b7a6efa08384e9bbecfe4ce61c77d28a4282f79e02f1ef78d96b80"},
"cowboy": {:hex, :cowboy, "2.13.0", "09d770dd5f6a22cc60c071f432cd7cb87776164527f205c5a6b0f24ff6b38990", [:make, :rebar3], [{:cowlib, ">= 2.14.0 and < 3.0.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, ">= 1.8.0 and < 3.0.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "e724d3a70995025d654c1992c7b11dbfea95205c047d86ff9bf1cda92ddc5614"},
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},
"cowlib": {:hex, :cowlib, "2.15.0", "3c97a318a933962d1c12b96ab7c1d728267d2c523c25a5b57b0f93392b6e9e25", [:make, :rebar3], [], "hexpm", "4f00c879a64b4fe7c8fcb42a4281925e9ffdb928820b03c3ad325a617e857532"},
"earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"},
"ex_doc": {:hex, :ex_doc, "0.40.1", "67542e4b6dde74811cfd580e2c0149b78010fd13001fda7cfeb2b2c2ffb1344d", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "bcef0e2d360d93ac19f01a85d58f91752d930c0a30e2681145feea6bd3516e00"},
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
"makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"},
"earmark_parser": {:hex, :earmark_parser, "1.4.46", "67607a0532e810c6f630a515c548d0b24949643f168cc556303bee4cf96105c7", [:mix], [], "hexpm", "9c44636e8a1c68c62f526b2dcd85d941dbbcee7ab82cf64ba06ce28bef8e89f5"},
"ex_doc": {:hex, :ex_doc, "0.40.4", "66f2e42bf588594d5a8aab31cad87f2ddad09d0da1b1a2f379340ec2c2e497cb", [:mix], [{:earmark_parser, "~> 1.4.46", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "6222b9e423d76584ee34df2c82a5ed72c2d53dc153f7f483ad28b378694186cc"},
"jason": {:hex, :jason, "1.4.5", "2e3a008590b0b8d7388c20293e9dcc9cf3e5d642fd2a114e4cbbb52e595d940a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b0c823996102bcd0239b3c2444eb00409b72f6a140c1950bc8b457d836b30684"},
"makeup": {:hex, :makeup, "1.2.2", "882d46dc0905e9ff7abf2aab61a7e6b3dcc555533977d8a23b06019e6c89ac94", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "9a1a24e5b343b8ae16abea0822c10a6f75da27af7fa802ada5251f7579bfccfa"},
"makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [: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", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"},
"makeup_erlang": {:hex, :makeup_erlang, "1.0.3", "4252d5d4098da7415c390e847c814bad3764c94a814a0b4245176215615e1035", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "953297c02582a33411ac6208f2c6e55f0e870df7f80da724ed613f10e6706afd"},
"mime": {:hex, :mime, "2.0.7", "b8d739037be7cd402aee1ba0306edfdef982687ee7e9859bee6198c1e7e2f128", [:mix], [], "hexpm", "6171188e399ee16023ffc5b76ce445eb6d9672e2e241d2df6050f3c771e80ccd"},
"makeup_erlang": {:hex, :makeup_erlang, "1.1.0", "835f7e60792e08824cda445639555d7bf1bbbddb1b60b306e33cb6f6db24dc74", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "1cd6780fb1dd1a03979abaed0fe82712b0625118fd5257d3ebbf73f960c73c3c"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"},
"plug": {:hex, :plug, "1.18.1", "5067f26f7745b7e31bc3368bc1a2b818b9779faa959b49c934c17730efc911cf", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "57a57db70df2b422b564437d2d33cf8d33cd16339c1edb190cd11b1a3a546cc2"},
"plug_cowboy": {:hex, :plug_cowboy, "2.7.4", "729c752d17cf364e2b8da5bdb34fb5804f56251e88bb602aff48ae0bd8673d11", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "9b85632bd7012615bae0a5d70084deb1b25d2bcbb32cab82d1e9a1e023168aa3"},
"plug_crypto": {:hex, :plug_crypto, "2.1.1", "19bda8184399cb24afa10be734f84a16ea0a2bc65054e23a62bb10f06bc89491", [:mix], [], "hexpm", "6470bce6ffe41c8bd497612ffde1a7e4af67f36a15eea5f921af71cf3e11247c"},
"ranch": {:hex, :ranch, "1.8.1", "208169e65292ac5d333d6cdbad49388c1ae198136e4697ae2f474697140f201c", [:make, :rebar3], [], "hexpm", "aed58910f4e21deea992a67bf51632b6d60114895eb03bb392bb733064594dd0"},
"rustler": {:hex, :rustler, "0.37.3", "5f4e6634d43b26f0a69834dd1d3ed4e1710b022a053bf4a670220c9540c92602", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "a6872c6f53dcf00486d1e7f9e046e20e01bf1654bdacc4193016c2e8002b32a2"},
"telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"},
"passby": {:hex, :passby, "0.2.0", "6dbcb9e0089d037b8a5d69b710384ffea9e2a5d14e72d63fb24f4f1f1f7d59be", [:mix], [], "hexpm", "39bef23c06a917b40f1858709f785c3aa8e77ff95bdeb816e431c4e2411f0707"},
"rustler": {:hex, :rustler, "0.38.0", "7a8906998ff0d28e3021c0a73264abcda719bda344b2e58307c6805b0f87c9b4", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "704c03c1bf66be12b031c5a389347b91c81c5cb819a24b068b0de36fe4a5652a"},
}
90 changes: 49 additions & 41 deletions test/rustler_precompiled_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -471,16 +471,21 @@ defmodule RustlerPrecompiledTest do
checksum_sample: checksum_sample,
nif_fixtures_dir: nif_fixtures_dir
} do
bypass = Bypass.open()
passby = Passby.open()
me = self()

in_tmp(tmp_dir, fn ->
File.write!("checksum-Elixir.RustlerPrecompilationExample.Native.exs", checksum_sample)

Bypass.expect_once(bypass, fn conn ->
Passby.expect_once(passby, fn conn ->
file_name = List.last(conn.path_info)

assert String.ends_with?(file_name, "tar.gz")
file = File.read!(Path.join([nif_fixtures_dir, "precompiled_nifs", file_name]))

Plug.Conn.resp(conn, 200, file)
send(me, {:req, file_name})

Passby.resp(conn, 200, file)
end)

result =
Expand All @@ -490,7 +495,7 @@ defmodule RustlerPrecompiledTest do
otp_app: :rustler_precompiled,
module: RustlerPrecompilationExample.Native,
base_cache_dir: tmp_dir,
base_url: "http://localhost:#{bypass.port}/download",
base_url: "http://localhost:#{passby.port}/download",
version: "0.2.0",
crate: "example",
targets: @available_targets,
Expand All @@ -510,9 +515,12 @@ defmodule RustlerPrecompiledTest do
end)

assert result =~ "Downloading"
assert result =~ "http://localhost:#{bypass.port}/download"
assert result =~ "http://localhost:#{passby.port}/download"
assert result =~ "NIF cached at"
end)

assert_received {:req, file_name}
assert String.ends_with?(file_name, "tar.gz")
end

@tag :tmp_dir
Expand All @@ -521,16 +529,16 @@ defmodule RustlerPrecompiledTest do
checksum_sample: checksum_sample,
nif_fixtures_dir: nif_fixtures_dir
} do
bypass = Bypass.open()
passby = Passby.open()

in_tmp(tmp_dir, fn ->
File.write!("checksum-Elixir.RustlerPrecompilationExample.Native.exs", checksum_sample)

Bypass.expect_once(bypass, fn conn ->
Passby.expect_once(passby, fn conn ->
file_name = List.last(conn.path_info)
file = File.read!(Path.join([nif_fixtures_dir, "precompiled_nifs", file_name]))

Plug.Conn.resp(conn, 200, file)
Passby.resp(conn, 200, file)
end)

capture_log(fn ->
Expand All @@ -539,7 +547,7 @@ defmodule RustlerPrecompiledTest do
otp_app: :rustler_precompiled,
module: RustlerPrecompilationExample.Native,
base_cache_dir: tmp_dir,
base_url: "http://localhost:#{bypass.port}/download",
base_url: "http://localhost:#{passby.port}/download",
version: "0.2.0",
crate: "example",
targets: @available_targets,
Expand Down Expand Up @@ -584,19 +592,19 @@ defmodule RustlerPrecompiledTest do
checksum_sample: checksum_sample,
nif_fixtures_dir: nif_fixtures_dir
} do
bypass = Bypass.open()
passby = Passby.open()

in_tmp(tmp_dir, fn ->
File.write!("checksum-Elixir.RustlerPrecompilationExample.Native.exs", checksum_sample)

Bypass.expect_once(bypass, fn conn ->
Passby.expect_once(passby, fn conn ->
file_name = List.last(conn.path_info)
file = File.read!(Path.join([nif_fixtures_dir, "precompiled_nifs", file_name]))

if Plug.Conn.get_req_header(conn, "authorization") == ["Token 123"] do
Plug.Conn.resp(conn, 200, file)
if Passby.get_req_header(conn, "authorization") == ["Token 123"] do
Passby.resp(conn, 200, file)
else
Plug.Conn.resp(conn, 401, "Unauthorized")
Passby.resp(conn, 401, "Unauthorized")
end
end)

Expand All @@ -608,7 +616,7 @@ defmodule RustlerPrecompiledTest do
module: RustlerPrecompilationExample.Native,
base_cache_dir: tmp_dir,
base_url:
{"http://localhost:#{bypass.port}/download", [{"authorization", "Token 123"}]},
{"http://localhost:#{passby.port}/download", [{"authorization", "Token 123"}]},
version: "0.2.0",
crate: "example",
targets: @available_targets,
Expand All @@ -628,7 +636,7 @@ defmodule RustlerPrecompiledTest do
end)

assert result =~ "Downloading"
assert result =~ "http://localhost:#{bypass.port}/download"
assert result =~ "http://localhost:#{passby.port}/download"
assert result =~ "NIF cached at"
end)
end
Expand All @@ -639,19 +647,19 @@ defmodule RustlerPrecompiledTest do
checksum_sample: checksum_sample,
nif_fixtures_dir: nif_fixtures_dir
} do
bypass = Bypass.open(port: 1234)
passby = Passby.open(port: 1234)

in_tmp(tmp_dir, fn ->
File.write!("checksum-Elixir.RustlerPrecompilationExample.Native.exs", checksum_sample)

Bypass.expect_once(bypass, fn conn ->
Passby.expect_once(passby, fn conn ->
%{"file_name" => file_name} = URI.decode_query(conn.query_string)
file = File.read!(Path.join([nif_fixtures_dir, "precompiled_nifs", file_name]))

if Plug.Conn.get_req_header(conn, "authorization") == ["Token 123"] do
Plug.Conn.resp(conn, 200, file)
if Passby.get_req_header(conn, "authorization") == ["Token 123"] do
Passby.resp(conn, 200, file)
else
Plug.Conn.resp(conn, 401, "Unauthorized")
Passby.resp(conn, 401, "Unauthorized")
end
end)

Expand Down Expand Up @@ -682,7 +690,7 @@ defmodule RustlerPrecompiledTest do
end)

assert result =~ "Downloading"
assert result =~ "http://localhost:#{bypass.port}/download"
assert result =~ "http://localhost:#{passby.port}/download"
assert result =~ "NIF cached at"
end)
end
Expand All @@ -693,24 +701,24 @@ defmodule RustlerPrecompiledTest do
checksum_sample: checksum_sample,
nif_fixtures_dir: nif_fixtures_dir
} do
bypass = Bypass.open()
passby = Passby.open()
{:ok, agent} = Agent.start_link(fn -> 1 end)

in_tmp(tmp_dir, fn ->
File.write!("checksum-Elixir.RustlerPrecompilationExample.Native.exs", checksum_sample)

Bypass.expect(bypass, fn conn ->
Passby.expect(passby, fn conn ->
current_attempt = Agent.get(agent, & &1)

if current_attempt == 2 do
file_name = List.last(conn.path_info)
file = File.read!(Path.join([nif_fixtures_dir, "precompiled_nifs", file_name]))

Plug.Conn.resp(conn, 200, file)
Passby.resp(conn, 200, file)
else
:ok = Agent.update(agent, &(&1 + 1))

Plug.Conn.resp(conn, 500, "Server is down")
Passby.resp(conn, 500, "Server is down")
end
end)

Expand All @@ -721,7 +729,7 @@ defmodule RustlerPrecompiledTest do
otp_app: :rustler_precompiled,
module: RustlerPrecompilationExample.Native,
base_cache_dir: tmp_dir,
base_url: "http://localhost:#{bypass.port}/download",
base_url: "http://localhost:#{passby.port}/download",
version: "0.2.0",
crate: "example",
targets: @available_targets,
Expand All @@ -746,7 +754,7 @@ defmodule RustlerPrecompiledTest do
assert result =~ "Internal Server Error"

assert result =~ "Downloading"
assert result =~ "http://localhost:#{bypass.port}/download"
assert result =~ "http://localhost:#{passby.port}/download"
assert result =~ "NIF cached at"
end)
end
Expand All @@ -756,16 +764,16 @@ defmodule RustlerPrecompiledTest do
tmp_dir: tmp_dir,
checksum_sample: checksum_sample
} do
bypass = Bypass.open()
passby = Passby.open()
{:ok, agent} = Agent.start_link(fn -> 0 end)

in_tmp(tmp_dir, fn ->
File.write!("checksum-Elixir.RustlerPrecompilationExample.Native.exs", checksum_sample)

Bypass.expect(bypass, fn conn ->
Passby.expect(passby, fn conn ->
:ok = Agent.update(agent, &(&1 + 1))

Plug.Conn.resp(conn, 500, "Server is down")
Passby.resp(conn, 500, "Server is down")
end)

capture_log(fn ->
Expand All @@ -774,7 +782,7 @@ defmodule RustlerPrecompiledTest do
otp_app: :rustler_precompiled,
module: RustlerPrecompilationExample.Native,
base_cache_dir: tmp_dir,
base_url: "http://localhost:#{bypass.port}/download",
base_url: "http://localhost:#{passby.port}/download",
version: "0.2.0",
crate: "example",
max_retries: 0,
Expand All @@ -799,14 +807,14 @@ defmodule RustlerPrecompiledTest do
tmp_dir: tmp_dir,
nif_fixtures_dir: nif_fixtures_dir
} do
bypass = Bypass.open()
passby = Passby.open()

in_tmp(tmp_dir, fn ->
Bypass.expect_once(bypass, fn conn ->
Passby.expect_once(passby, fn conn ->
file_name = List.last(conn.path_info)
file = File.read!(Path.join([nif_fixtures_dir, "precompiled_nifs", file_name]))

Plug.Conn.resp(conn, 200, file)
Passby.resp(conn, 200, file)
end)

capture_log(fn ->
Expand All @@ -815,7 +823,7 @@ defmodule RustlerPrecompiledTest do
otp_app: :rustler_precompiled,
module: RustlerPrecompilationExample.Native,
base_cache_dir: tmp_dir,
base_url: "http://localhost:#{bypass.port}/download",
base_url: "http://localhost:#{passby.port}/download",
version: "0.2.0",
crate: "example",
targets: @available_targets,
Expand Down Expand Up @@ -1095,16 +1103,16 @@ defmodule RustlerPrecompiledTest do
checksum_sample: checksum_sample,
nif_fixtures_dir: nif_fixtures_dir
} do
bypass = Bypass.open()
passby = Passby.open()

in_tmp(tmp_dir, fn ->
File.write!("checksum-Elixir.RustlerPrecompilationExample.Native.exs", checksum_sample)

Bypass.expect_once(bypass, fn conn ->
Passby.expect_once(passby, fn conn ->
file_name = List.last(conn.path_info)
file = File.read!(Path.join([nif_fixtures_dir, "precompiled_nifs", file_name]))

Plug.Conn.resp(conn, 200, file)
Passby.resp(conn, 200, file)
end)

result =
Expand All @@ -1114,7 +1122,7 @@ defmodule RustlerPrecompiledTest do
otp_app: :rustler_precompiled,
module: RustlerPrecompilationExample.Native,
base_cache_dir: tmp_dir,
base_url: "http://localhost:#{bypass.port}/download",
base_url: "http://localhost:#{passby.port}/download",
version: "0.2.0",
crate: "example",
targets: @available_targets,
Expand All @@ -1138,7 +1146,7 @@ defmodule RustlerPrecompiledTest do
end)

assert result =~ "Downloading"
assert result =~ "http://localhost:#{bypass.port}/download"
assert result =~ "http://localhost:#{passby.port}/download"
assert result =~ "NIF cached at"
end)
end
Expand Down
Loading