-
Notifications
You must be signed in to change notification settings - Fork 18
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
[RTC-456] Add peerless room purge #150
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
68d704b
[RTC-385] Add peerless room purge
sgfn 2f9eee0
Add change from fix_metrics, update api spec
sgfn 73776de
Add log and guard
sgfn 94ce480
Remove guard
sgfn 7940673
Update controversial test name
sgfn e1fa6af
Mock timers in tests
sgfn 9262b6c
Restore Elixir to 1.14, remove calls to Map.intersect
sgfn fcc81f0
lint
sgfn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
defmodule Jellyfish.RoomTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias Jellyfish.{Peer, Room} | ||
|
||
@purge_timeout_s 60 | ||
@purge_timeout_ms @purge_timeout_s * 1000 | ||
@message_timeout_ms 20 | ||
|
||
setup do | ||
Klotho.Mock.reset() | ||
Klotho.Mock.freeze() | ||
end | ||
|
||
describe "peerless purge" do | ||
test "happens if peers never joined" do | ||
{:ok, config} = Room.Config.from_params(%{"peerlessPurgeTimeout" => @purge_timeout_s}) | ||
{:ok, pid, _id} = Room.start(config) | ||
Process.monitor(pid) | ||
|
||
Klotho.Mock.warp_by(@purge_timeout_ms + 10) | ||
|
||
assert_receive {:DOWN, _ref, :process, ^pid, :normal}, @message_timeout_ms | ||
end | ||
|
||
test "happens if peers joined, then left" do | ||
{:ok, config} = Room.Config.from_params(%{"peerlessPurgeTimeout" => @purge_timeout_s}) | ||
{:ok, pid, id} = Room.start(config) | ||
Process.monitor(pid) | ||
|
||
{:ok, peer} = Room.add_peer(id, Peer.WebRTC) | ||
|
||
Klotho.Mock.warp_by(@purge_timeout_ms + 10) | ||
refute_receive {:DOWN, _ref, :process, ^pid, :normal}, @message_timeout_ms | ||
|
||
:ok = Room.remove_peer(id, peer.id) | ||
|
||
Klotho.Mock.warp_by(@purge_timeout_ms + 10) | ||
assert_receive {:DOWN, _ref, :process, ^pid, :normal}, @message_timeout_ms | ||
end | ||
|
||
test "does not happen if peers rejoined quickly" do | ||
{:ok, config} = Room.Config.from_params(%{"peerlessPurgeTimeout" => @purge_timeout_s}) | ||
{:ok, pid, id} = Room.start(config) | ||
Process.monitor(pid) | ||
|
||
{:ok, peer} = Room.add_peer(id, Peer.WebRTC) | ||
|
||
Klotho.Mock.warp_by(@purge_timeout_ms + 10) | ||
refute_receive {:DOWN, _ref, :process, ^pid, :normal}, @message_timeout_ms | ||
|
||
:ok = Room.remove_peer(id, peer.id) | ||
|
||
Klotho.Mock.warp_by(@purge_timeout_ms |> div(2)) | ||
refute_receive {:DOWN, _ref, :process, ^pid, :normal}, @message_timeout_ms | ||
|
||
{:ok, _peer} = Room.add_peer(id, Peer.WebRTC) | ||
Klotho.Mock.warp_by(@purge_timeout_ms + 10) | ||
refute_receive {:DOWN, _ref, :process, ^pid, :normal}, @message_timeout_ms | ||
|
||
:ok = GenServer.stop(pid) | ||
end | ||
|
||
test "does not happen when not configured" do | ||
{:ok, config} = Room.Config.from_params(%{}) | ||
{:ok, pid, _id} = Room.start(config) | ||
|
||
Klotho.Mock.warp_by(@purge_timeout_ms + 10) | ||
refute_receive {:DOWN, _ref, :process, ^pid, :normal}, @message_timeout_ms | ||
|
||
:ok = GenServer.stop(pid) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stopping with normal won't cause other processes that are linked to the room process to exit. I am not sure if that's correct. I think I would go for {:shutdown, :peerless_purge}? See https://hexdocs.pm/elixir/1.16.0/Supervisor.html#module-exit-reasons-and-restarts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that's exactly how
RoomService
removes rooms -- hereWe're manually removing all of the linked processes in the
terminate
callback, no?