Skip to content

Commit

Permalink
Add test for race condition in community gardens (#1368)
Browse files Browse the repository at this point in the history
Co-authored-by: Angelika Tyborska <[email protected]>
  • Loading branch information
cshintov and angelikatyborska authored Nov 23, 2023
1 parent 5357e96 commit 4dc3f9b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Please keep the following in mind:
- Each problem should have a test suite, an example solution, and a template
file for the real implementation. Read about [the anatomy of practice exercises](https://github.com/exercism/docs/blob/main/building/tracks/practice-exercises.md) or [the anatomy of concept exercises](https://github.com/exercism/docs/blob/main/building/tracks/concept-exercises.md), depending on to which type of exercise you want to contribute.

- For practice exercises, `instructions.md` come from the [problem specifications](https://github.com/exercism/problem-specifications) repository. They cannot be changed without updating them in that repository first. If Elixir-specific changes are necessary, than can be appended to the instructions by creating a `instructions.append.md` file.
- For practice exercises, `instructions.md` come from the [problem specifications](https://github.com/exercism/problem-specifications) repository. They cannot be changed without updating them in that repository first. If Elixir-specific changes are necessary, they can be appended to the instructions by creating a `instructions.append.md` file.

- For practice exercises, use typespecs in the example and template files as described [here](https://elixir-lang.org/getting-started/typespecs-and-behaviours.html).

Expand Down
26 changes: 26 additions & 0 deletions exercises/concept/community-garden/test/community_garden_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@ defmodule CommunityGardenTest do
assert plot_3.plot_id == 3
end

@tag task_id: 3
test "registered plots have incremental unique id when registered concurrently" do
{:ok, pid} = CommunityGarden.start()

total_plots = 20
test_process_pid = self()

Enum.each(1..total_plots, fn n ->
spawn(fn ->
plot = CommunityGarden.register(pid, "Mary Bumblebee #{n}")
send(test_process_pid, {n, plot})
end)
end)

plot_ids =
Enum.map(1..total_plots, fn n ->
receive do
{^n, plot} -> plot.plot_id
after
100 -> nil
end
end)

assert Enum.sort(plot_ids) == Enum.to_list(1..total_plots)
end

@tag task_id: 4
test "can release a plot" do
assert {:ok, pid} = CommunityGarden.start()
Expand Down

0 comments on commit 4dc3f9b

Please sign in to comment.