Skip to content

Commit

Permalink
Verify behavior of concurrent registrations
Browse files Browse the repository at this point in the history
  • Loading branch information
tt committed Aug 12, 2019
1 parent 4b4e31d commit 4a4a117
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions test/conduit/accounts/accounts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ defmodule Conduit.AccountsTest do

@tag :integration
test "should fail when registering identical username at same time and return error" do
1..2
|> Enum.map(fn x -> Task.async(fn -> Accounts.register_user(build(:user, email: "jake#{x}@jake.jake")) end) end)
|> Enum.map(&Task.await/1)
[success, failure] =
1..2
|> Enum.map(fn x -> Task.async(fn -> Accounts.register_user(build(:user, email: "jake#{x}@jake.jake")) end) end)
|> Enum.map(&Task.await/1)
|> Enum.sort()

assert {:ok, %User{}} = success
assert {:error, :validation_failure, errors} = failure

assert errors == %{username: ["has already been taken"]}
end

@tag :integration
Expand All @@ -60,9 +67,16 @@ defmodule Conduit.AccountsTest do

@tag :integration
test "should fail when registering identical email addresses at same time and return error" do
1..2
|> Enum.map(fn x -> Task.async(fn -> Accounts.register_user(build(:user, username: "user#{x}")) end) end)
|> Enum.map(&Task.await/1)
[success, failure] =
1..2
|> Enum.map(fn x -> Task.async(fn -> Accounts.register_user(build(:user, username: "user#{x}")) end) end)
|> Enum.map(&Task.await/1)
|> Enum.sort()

assert {:ok, %User{}} = success
assert {:error, :validation_failure, errors} = failure

assert errors == %{email: ["has already been taken"]}
end

@tag :integration
Expand Down

0 comments on commit 4a4a117

Please sign in to comment.