Page MenuHomePhorge

No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None
diff --git a/lib/captcha.ex b/lib/captcha.ex
index 39cb0e3..caed0ca 100644
--- a/lib/captcha.ex
+++ b/lib/captcha.ex
@@ -1,19 +1,19 @@
defmodule Captcha do
# allow customize receive timeout, default: 10_000
def get(timeout \\ 1_000) do
pid = Port.open({:spawn, Path.join(:code.priv_dir(:captcha), "captcha")}, [:binary])
# Allow set receive timeout
receive do
{^pid, {:data, data}} ->
<<text::bytes-size(5), img::binary>> = data
{:ok, text, img}
other ->
other
after
timeout ->
- {:timeout}
+ {:error, :timeout}
end
end
end
diff --git a/test/elixir_captcha_test.exs b/test/elixir_captcha_test.exs
index 31003f5..ddf2620 100644
--- a/test/elixir_captcha_test.exs
+++ b/test/elixir_captcha_test.exs
@@ -1,8 +1,12 @@
defmodule CaptchaTest do
use ExUnit.Case
doctest Captcha
- test "generate image success" do
+ test "successfully generates an image" do
assert {:ok, _, _} = Captcha.get()
end
+
+ test "respects the timeout" do
+ assert {:error, :timeout} = Captcha.get(0)
+ end
end

File Metadata

Mime Type
text/x-diff
Expires
Mon, Nov 25, 2:44 AM (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39047
Default Alt Text
(1 KB)

Event Timeline