Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit 56957d0

Browse files
committedNov 10, 2021
Changed sessions initialization to setup_all
1 parent c715d17 commit 56957d0

File tree

2 files changed

+59
-33
lines changed

2 files changed

+59
-33
lines changed
 

‎integration/test_videoroom/lib/test_videoroom_web/channels/room_channel.ex

+5
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ defmodule TestVideoroomWeb.RoomChannel do
4141

4242
{:noreply, socket}
4343
end
44+
45+
@impl true
46+
def handle_info({:DOWN, _ref, :process, room, :normal}, %{assigns: %{room: room}} = state) do
47+
{:stop, :normal, state}
48+
end
4449
end

‎integration/test_videoroom/test/integration/client_test.exs

+54-33
Original file line numberDiff line numberDiff line change
@@ -75,29 +75,57 @@ defmodule TestVideoroom.Integration.ClientTest do
7575
@data Query.css("#data")
7676

7777
setup_all do
78-
{:ok, _pid} = TestVideoroom.Room.start(name: @room_name)
7978

80-
:ok
79+
# start 3 chrome and 3 firefox sessions for each test to
80+
# avoid high initialization time for each test
81+
sessions =
82+
1..3
83+
|> Enum.flat_map(fn _ ->
84+
[{:firefox, @firefox_capabilities}, {:chrome, @chrome_capabilities}]
85+
end)
86+
|> Enum.map(fn {browser, capabilities} ->
87+
{:ok, session} = Wallaby.start_session(capabilities)
88+
89+
{browser, session}
90+
end)
91+
|> Enum.group_by(& elem(&1, 0), & elem(&1, 1))
92+
93+
94+
on_exit(fn ->
95+
Map.values(sessions) |> List.flatten() |> Enum.each(& Wallaby.end_session(&1))
96+
end)
97+
98+
{:ok, browser_sessions: sessions}
99+
end
100+
101+
def sessions_for_browser(%{browser_sessions: sessions}, browser, n) when n <= 3 and browser in [:chrome, :firefox] do
102+
Enum.take(sessions[browser], n)
81103
end
82104

83-
setup do
105+
setup ctx do
106+
{:ok, _pid} = TestVideoroom.Room.start(name: @room_name)
84107
TestVideoroom.Room.register_new_peer_listener(@room_name, self())
108+
109+
on_exit(fn ->
110+
:ok = GenServer.stop(:global.whereis_name("room"))
111+
112+
ctx.browser_sessions
113+
|> Map.values()
114+
|> List.flatten()
115+
|> Enum.each(fn session ->
116+
visit(session, @page)
117+
end)
118+
119+
end)
85120
end
86121

87122
@join_interval 5_000
88123
@leave_interval 5_000
89124

90-
# run 3 sessions for chrome and 2 for firefox
91-
@sessions [
92-
@firefox_capabilities,
93-
@firefox_capabilities,
94-
@chrome_capabilities,
95-
@chrome_capabilities,
96-
@chrome_capabilities
97-
]
98125
@moduletag timeout: 180_000
99-
feature "Users gradually joining and leaving can hear and see each other", %{sessions: sessions} do
100-
user_entries = prepare_users(sessions)
126+
@sessions 0
127+
feature "Users gradually joining and leaving can hear and see each other", ctx do
128+
user_entries = prepare_users(sessions_for_browser(ctx, :chrome, 3) ++ sessions_for_browser(ctx, :firefox, 2))
101129

102130
# assert that users can see each other when others are gradually joining
103131
user_entries =
@@ -153,24 +181,18 @@ defmodule TestVideoroom.Integration.ClientTest do
153181
assert :global.whereis_name("room") |> Process.alive?()
154182
end
155183

156-
@sessions [
157-
@chrome_capabilities,
158-
@chrome_capabilities,
159-
@chrome_capabilities,
160-
@firefox_capabilities,
161-
@firefox_capabilities
162-
]
163184
@moduletag timeout: 180_000
164-
feature "Users joining all at once can hear and see each other", %{sessions: sessions} do
165-
user_entries = prepare_users(sessions)
185+
@sessions 0
186+
feature "Users joining all at once can hear and see each other", ctx do
187+
user_entries = prepare_users(sessions_for_browser(ctx, :chrome, 3) ++ sessions_for_browser(ctx, :firefox, 3))
166188

167189
# make all the users join the room
168190
for {user, _version} <- user_entries do
169191
join_room(user)
170192
end
171193

172194
# wait for everybody to load
173-
wait(10_000)
195+
wait(15_000)
174196

175197
total_users = length(user_entries)
176198

@@ -189,16 +211,10 @@ defmodule TestVideoroom.Integration.ClientTest do
189211
assert :global.whereis_name("room") |> Process.alive?()
190212
end
191213

192-
@sessions [
193-
@chrome_capabilities,
194-
@chrome_capabilities,
195-
@firefox_capabilities,
196-
@firefox_capabilities
197-
]
198214
@moduletag timeout: 180_000
199-
feature "Users joining without either microphone, camera or both can see or hear other users",
200-
%{sessions: sessions} do
201-
user_entries = prepare_users(sessions)
215+
@sessions 0
216+
feature "Users joining without either microphone, camera or both can see or hear other users", ctx do
217+
user_entries = prepare_users(sessions_for_browser(ctx, :chrome, 2) ++ sessions_for_browser(ctx, :firefox, 2))
202218

203219
# join all users
204220
user_entries
@@ -274,6 +290,11 @@ defmodule TestVideoroom.Integration.ClientTest do
274290
# can see the user with camera only
275291
assert Enum.any?(stats, &is_stream_playing(&1, %{audio: false, video: true}))
276292

293+
294+
Enum.each(user_entries, fn {user, _version} ->
295+
leave_room(user)
296+
end)
297+
277298
# make sure that the room is still alive
278299
assert :global.whereis_name("room") |> Process.alive?()
279300
end
@@ -323,7 +344,7 @@ defmodule TestVideoroom.Integration.ClientTest do
323344

324345
for stream <- streams do
325346
assert is_stream_playing(stream),
326-
"Session [#{inspect(session.capabilities.browserName)} -> #{inspect(session.id)}] expected a stream to be playing"
347+
"Session [#{inspect(session.capabilities.browserName)} -> #{inspect(session.id)}] expected a stream to be playing, got #{inspect stream}"
327348
end
328349

329350
{:ok, new_expected_data_version}

0 commit comments

Comments
 (0)