@@ -45,84 +45,76 @@ defmodule Realtime.GenRpcPubSubTest do
4545
4646 @ topic "gen-rpc-pub-sub-test-topic"
4747
48- for regional_broadcasting <- [ true , false ] do
49- describe "regional balancing = #{ regional_broadcasting } " do
50- setup do
51- previous_region = Application . get_env ( :realtime , :region )
52- Application . put_env ( :realtime , :region , "us-east-1" )
53- on_exit ( fn -> Application . put_env ( :realtime , :region , previous_region ) end )
48+ describe "regional broadcasting" do
49+ setup do
50+ previous_region = Application . get_env ( :realtime , :region )
51+ Application . put_env ( :realtime , :region , "us-east-1" )
52+ on_exit ( fn -> Application . put_env ( :realtime , :region , previous_region ) end )
5453
55- previous_regional_broadcast = Application . get_env ( :realtime , :regional_broadcasting )
56- Application . put_env ( :realtime , :regional_broadcasting , unquote ( regional_broadcasting ) )
57- on_exit ( fn -> Application . put_env ( :realtime , :regional_broadcasting , previous_regional_broadcast ) end )
58-
59- :ok
60- end
61-
62- @ describetag regional_broadcasting: regional_broadcasting
54+ :ok
55+ end
6356
64- test "all messages are received" do
65- # start 1 node in us-east-1 to test my region broadcasting
66- # start 2 nodes in ap-southeast-2 to test other region broadcasting
57+ test "all messages are received" do
58+ # start 1 node in us-east-1 to test my region broadcasting
59+ # start 2 nodes in ap-southeast-2 to test other region broadcasting
6760
68- us_node = :us_node
69- ap2_nodeX = :ap2_nodeX
70- ap2_nodeY = :ap2_nodeY
61+ us_node = :us_node
62+ ap2_nodeX = :ap2_nodeX
63+ ap2_nodeY = :ap2_nodeY
7164
72- # Avoid port collision
73- gen_rpc_port = Application . fetch_env! ( :gen_rpc , :tcp_server_port )
65+ # Avoid port collision
66+ gen_rpc_port = Application . fetch_env! ( :gen_rpc , :tcp_server_port )
7467
75- client_config_per_node = % {
76- node ( ) => gen_rpc_port ,
77- :"#{ us_node } @127.0.0.1" => 16970 ,
78- :"#{ ap2_nodeX } @127.0.0.1" => 16971 ,
79- :"#{ ap2_nodeY } @127.0.0.1" => 16972
80- }
68+ client_config_per_node = % {
69+ node ( ) => gen_rpc_port ,
70+ :"#{ us_node } @127.0.0.1" => 16970 ,
71+ :"#{ ap2_nodeX } @127.0.0.1" => 16971 ,
72+ :"#{ ap2_nodeY } @127.0.0.1" => 16972
73+ }
8174
82- extra_config = [ { :gen_rpc , :client_config_per_node , { :internal , client_config_per_node } } ]
75+ extra_config = [ { :gen_rpc , :client_config_per_node , { :internal , client_config_per_node } } ]
8376
84- on_exit ( fn -> Application . put_env ( :gen_rpc , :client_config_per_node , { :internal , % { } } ) end )
85- Application . put_env ( :gen_rpc , :client_config_per_node , { :internal , client_config_per_node } )
77+ on_exit ( fn -> Application . put_env ( :gen_rpc , :client_config_per_node , { :internal , % { } } ) end )
78+ Application . put_env ( :gen_rpc , :client_config_per_node , { :internal , client_config_per_node } )
8679
87- us_extra_config =
88- [ { :realtime , :region , "us-east-1" } , { :gen_rpc , :tcp_server_port , 16970 } ] ++ extra_config
80+ us_extra_config =
81+ [ { :realtime , :region , "us-east-1" } , { :gen_rpc , :tcp_server_port , 16970 } ] ++ extra_config
8982
90- { :ok , _ } = Clustered . start ( @ aux_mod , name: us_node , extra_config: us_extra_config , phoenix_port: 4014 )
83+ { :ok , _ } = Clustered . start ( @ aux_mod , name: us_node , extra_config: us_extra_config , phoenix_port: 4014 )
9184
92- ap2_nodeX_extra_config =
93- [ { :realtime , :region , "ap-southeast-2" } , { :gen_rpc , :tcp_server_port , 16971 } ] ++ extra_config
85+ ap2_nodeX_extra_config =
86+ [ { :realtime , :region , "ap-southeast-2" } , { :gen_rpc , :tcp_server_port , 16971 } ] ++ extra_config
9487
95- { :ok , _ } = Clustered . start ( @ aux_mod , name: ap2_nodeX , extra_config: ap2_nodeX_extra_config , phoenix_port: 4015 )
88+ { :ok , _ } = Clustered . start ( @ aux_mod , name: ap2_nodeX , extra_config: ap2_nodeX_extra_config , phoenix_port: 4015 )
9689
97- ap2_nodeY_extra_config =
98- [ { :realtime , :region , "ap-southeast-2" } , { :gen_rpc , :tcp_server_port , 16972 } ] ++ extra_config
90+ ap2_nodeY_extra_config =
91+ [ { :realtime , :region , "ap-southeast-2" } , { :gen_rpc , :tcp_server_port , 16972 } ] ++ extra_config
9992
100- { :ok , _ } = Clustered . start ( @ aux_mod , name: ap2_nodeY , extra_config: ap2_nodeY_extra_config , phoenix_port: 4016 )
93+ { :ok , _ } = Clustered . start ( @ aux_mod , name: ap2_nodeY , extra_config: ap2_nodeY_extra_config , phoenix_port: 4016 )
10194
102- # Ensuring that syn had enough time to propagate to all nodes the group information
103- Process . sleep ( 3000 )
95+ # Ensuring that syn had enough time to propagate to all nodes the group information
96+ Process . sleep ( 3000 )
10497
105- RealtimeWeb.Endpoint . subscribe ( @ topic )
106- :erpc . multicall ( Node . list ( ) , Subscriber , :subscribe , [ self ( ) , @ topic ] )
98+ RealtimeWeb.Endpoint . subscribe ( @ topic )
99+ :erpc . multicall ( Node . list ( ) , Subscriber , :subscribe , [ self ( ) , @ topic ] )
107100
108- assert length ( Realtime.Nodes . region_nodes ( "us-east-1" ) ) == 2
109- assert length ( Realtime.Nodes . region_nodes ( "ap-southeast-2" ) ) == 2
101+ assert length ( Realtime.Nodes . region_nodes ( "us-east-1" ) ) == 2
102+ assert length ( Realtime.Nodes . region_nodes ( "ap-southeast-2" ) ) == 2
110103
111- assert_receive { :ready , "us-east-1" }
112- assert_receive { :ready , "ap-southeast-2" }
113- assert_receive { :ready , "ap-southeast-2" }
104+ assert_receive { :ready , "us-east-1" }
105+ assert_receive { :ready , "ap-southeast-2" }
106+ assert_receive { :ready , "ap-southeast-2" }
114107
115- message = % Phoenix.Socket.Broadcast { topic: @ topic , event: "an event" , payload: [ "a" , % { "b" => "c" } , 1 , 23 ] }
116- Phoenix.PubSub . broadcast ( Realtime.PubSub , @ topic , message )
108+ message = % Phoenix.Socket.Broadcast { topic: @ topic , event: "an event" , payload: [ "a" , % { "b" => "c" } , 1 , 23 ] }
109+ Phoenix.PubSub . broadcast ( Realtime.PubSub , @ topic , message )
117110
118- assert_receive ^ message
111+ assert_receive ^ message
119112
120- # Remote nodes received the broadcast
121- assert_receive { :relay , :"us_node@127.0.0.1" , ^ message } , 5000
122- assert_receive { :relay , :"ap2_nodeX@127.0.0.1" , ^ message } , 1000
123- assert_receive { :relay , :"ap2_nodeY@127.0.0.1" , ^ message } , 1000
124- refute_receive _any
125- end
113+ # Remote nodes received the broadcast
114+ assert_receive { :relay , :"us_node@127.0.0.1" , ^ message } , 5000
115+ assert_receive { :relay , :"ap2_nodeX@127.0.0.1" , ^ message } , 1000
116+ assert_receive { :relay , :"ap2_nodeY@127.0.0.1" , ^ message } , 1000
117+ refute_receive _any
126118 end
127119 end
128120end
0 commit comments