Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for race condition in community gardens #1368

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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

20 * 100ms = 2s, so even is somebody messes up their solution so bad they trigger the timeout every time, they should still see some output of the test. I think the test runner only gets killed by exercism after 3 * average_run_time (which is 3 * 4s in our case)

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