Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F112524
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
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
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Nov 23, 6:23 PM (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39047
Default Alt Text
(1 KB)
Attached To
Mode
R13 elixir-captcha
Attached
Detach File
Event Timeline
Log In to Comment