@@ -75,29 +75,57 @@ defmodule TestVideoroom.Integration.ClientTest do
75
75
@ data Query . css ( "#data" )
76
76
77
77
setup_all do
78
- { :ok , _pid } = TestVideoroom.Room . start ( name: @ room_name )
79
78
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 )
81
103
end
82
104
83
- setup do
105
+ setup ctx do
106
+ { :ok , _pid } = TestVideoroom.Room . start ( name: @ room_name )
84
107
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 )
85
120
end
86
121
87
122
@ join_interval 5_000
88
123
@ leave_interval 5_000
89
124
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
- ]
98
125
@ 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 ) )
101
129
102
130
# assert that users can see each other when others are gradually joining
103
131
user_entries =
@@ -153,24 +181,18 @@ defmodule TestVideoroom.Integration.ClientTest do
153
181
assert :global . whereis_name ( "room" ) |> Process . alive? ( )
154
182
end
155
183
156
- @ sessions [
157
- @ chrome_capabilities ,
158
- @ chrome_capabilities ,
159
- @ chrome_capabilities ,
160
- @ firefox_capabilities ,
161
- @ firefox_capabilities
162
- ]
163
184
@ 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 ) )
166
188
167
189
# make all the users join the room
168
190
for { user , _version } <- user_entries do
169
191
join_room ( user )
170
192
end
171
193
172
194
# wait for everybody to load
173
- wait ( 10_000 )
195
+ wait ( 15_000 )
174
196
175
197
total_users = length ( user_entries )
176
198
@@ -189,16 +211,10 @@ defmodule TestVideoroom.Integration.ClientTest do
189
211
assert :global . whereis_name ( "room" ) |> Process . alive? ( )
190
212
end
191
213
192
- @ sessions [
193
- @ chrome_capabilities ,
194
- @ chrome_capabilities ,
195
- @ firefox_capabilities ,
196
- @ firefox_capabilities
197
- ]
198
214
@ 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 ) )
202
218
203
219
# join all users
204
220
user_entries
@@ -274,6 +290,11 @@ defmodule TestVideoroom.Integration.ClientTest do
274
290
# can see the user with camera only
275
291
assert Enum . any? ( stats , & is_stream_playing ( & 1 , % { audio: false , video: true } ) )
276
292
293
+
294
+ Enum . each ( user_entries , fn { user , _version } ->
295
+ leave_room ( user )
296
+ end )
297
+
277
298
# make sure that the room is still alive
278
299
assert :global . whereis_name ( "room" ) |> Process . alive? ( )
279
300
end
@@ -323,7 +344,7 @@ defmodule TestVideoroom.Integration.ClientTest do
323
344
324
345
for stream <- streams do
325
346
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 } "
327
348
end
328
349
329
350
{ :ok , new_expected_data_version }
0 commit comments