-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RTC-456] Add peerless room purge (#150)
* [RTC-385] Add peerless room purge * Add change from fix_metrics, update api spec * Add log and guard * Remove guard * Update controversial test name * Mock timers in tests * Restore Elixir to 1.14, remove calls to Map.intersect * lint
- Loading branch information
Showing
17 changed files
with
202 additions
and
73 deletions.
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.