@@ -1204,21 +1204,24 @@ defmodule Realtime.Integration.RtChannelTest do
1204
1204
# token expires in between joins so it needs to be handled by the channel and not the socket
1205
1205
Process . sleep ( 1000 )
1206
1206
realtime_topic = "realtime:#{ topic } "
1207
- WebsocketClient . join ( socket , realtime_topic , % { config: config , access_token: access_token } )
1208
1207
1209
- assert_receive % Message {
1210
- event: "phx_reply" ,
1211
- payload: % {
1212
- "status" => "error" ,
1213
- "response" => % {
1214
- "reason" => "InvalidJWTToken: Token has expired 0 seconds ago"
1215
- }
1216
- } ,
1217
- topic: ^ realtime_topic
1218
- } ,
1219
- 500
1208
+ log =
1209
+ capture_log ( fn ->
1210
+ WebsocketClient . join ( socket , realtime_topic , % { config: config , access_token: access_token } )
1211
+
1212
+ assert_receive % Message {
1213
+ event: "phx_reply" ,
1214
+ payload: % {
1215
+ "status" => "error" ,
1216
+ "response" => % { "reason" => "InvalidJWTToken: Token has expired 0 seconds ago" }
1217
+ } ,
1218
+ topic: ^ realtime_topic
1219
+ } ,
1220
+ 500
1221
+ end )
1220
1222
1221
1223
assert_receive % Message { event: "phx_close" }
1224
+ assert log =~ "#{ tenant . external_id } "
1222
1225
end
1223
1226
1224
1227
test "token loses claims in between joins" , % { tenant: tenant , topic: topic } do
@@ -1759,36 +1762,27 @@ defmodule Realtime.Integration.RtChannelTest do
1759
1762
test "max_events_per_second limit respected" , % { tenant: tenant } do
1760
1763
% { max_events_per_second: max_concurrent_users } = Tenants . get_tenant_by_external_id ( tenant . external_id )
1761
1764
on_exit ( fn -> change_tenant_configuration ( tenant , :max_events_per_second , max_concurrent_users ) end )
1762
- change_tenant_configuration ( tenant , :max_events_per_second , 1 )
1763
1765
1764
1766
{ socket , _ } = get_connection ( tenant , "authenticated" )
1765
- config = % { broadcast: % { self: true } , private: false }
1767
+ config = % { broadcast: % { self: true } , private: false , presence: % { enabled: false } }
1766
1768
realtime_topic = "realtime:#{ random_string ( ) } "
1767
1769
1768
1770
WebsocketClient . join ( socket , realtime_topic , % { config: config } )
1771
+ assert_receive % Message { event: "phx_reply" , payload: % { "status" => "ok" } , topic: ^ realtime_topic } , 500
1769
1772
1770
- for _ <- 1 .. 1000 do
1771
- try do
1772
- WebsocketClient . send_event ( socket , realtime_topic , "broadcast" , % { } )
1773
- catch
1774
- _ , _ -> :ok
1775
- end
1776
-
1777
- 1 .. 5 |> Enum . random ( ) |> Process . sleep ( )
1778
- end
1773
+ log =
1774
+ capture_log ( fn ->
1775
+ for _ <- 1 .. 1000 , Process . alive? ( socket ) do
1776
+ WebsocketClient . send_event ( socket , realtime_topic , "broadcast" , % { } )
1777
+ Process . sleep ( 10 )
1778
+ end
1779
1779
1780
- assert_receive % Message {
1781
- event: "system" ,
1782
- payload: % {
1783
- "status" => "error" ,
1784
- "extension" => "system" ,
1785
- "message" => "Too many messages per second"
1786
- }
1787
- } ,
1788
- 2000
1780
+ # Wait for the rate counter to run logger function
1781
+ Process . sleep ( 1500 )
1782
+ end )
1789
1783
1790
1784
assert_receive % Message { event: "phx_close" }
1791
- assert_process_down ( socket )
1785
+ assert log =~ "MessagePerSecondRateLimitReached"
1792
1786
end
1793
1787
1794
1788
test "max_channels_per_client limit respected" , % { tenant: tenant } do
@@ -1849,7 +1843,7 @@ defmodule Realtime.Integration.RtChannelTest do
1849
1843
event: "phx_reply" ,
1850
1844
payload: % {
1851
1845
"response" => % {
1852
- "reason" => "Too many joins per second"
1846
+ "reason" => "ClientJoinRateLimitReached: Too many joins per second"
1853
1847
} ,
1854
1848
"status" => "error"
1855
1849
}
0 commit comments