11//! Test Erlang/Elixir interoperability.
22//!
33//! To run this test:
4- //! 1. Start the Elixir test server:
4+ //! 1. Start the Elixir test server with @localhost :
55//! ```
66//! cd crates/ambitious/tests/elixir_interop
7- //! elixir --sname elixir_test --cookie test_cookie test_server.exs
7+ //! elixir --sname elixir_test@localhost --cookie test_cookie test_server.exs
88//! ```
99//! 2. Run this test:
1010//! ```
11- //! cargo test -p ambitious --features erlang-dist erlang_interop -- --nocapture
11+ //! cargo test -p ambitious --features erlang-dist --test erlang_interop_test -- --nocapture
1212//! ```
1313
1414#![ cfg( feature = "erlang-dist" ) ]
1515
1616use ambitious:: distribution:: erlang:: { ErlangConfig , ErlangConnection } ;
1717use erltf:: { OwnedTerm , erl_atom, erl_tuple} ;
1818
19+ /// Create a node name with localhost (for local testing).
20+ fn node_name ( name : & str ) -> String {
21+ format ! ( "{}@localhost" , name)
22+ }
23+
24+ /// Create a config for connecting to the local Elixir test server.
25+ fn test_config ( local_name : & str ) -> ErlangConfig {
26+ ErlangConfig :: new (
27+ & node_name ( local_name) ,
28+ & node_name ( "elixir_test" ) ,
29+ "test_cookie" ,
30+ )
31+ }
32+
1933/// Test connecting to an Elixir node and sending a ping.
2034#[ tokio:: test]
2135async fn test_connect_to_elixir ( ) {
2236 // Skip if EPMD isn't running or Elixir node isn't up
23- let config = ErlangConfig :: new (
24- "rust_test@localhost" ,
25- "elixir_test@localhost" ,
26- "test_cookie" ,
27- ) ;
37+ let config = test_config ( "rust_test" ) ;
2838
2939 let conn_result = ErlangConnection :: connect ( config) . await ;
3040
@@ -39,9 +49,11 @@ async fn test_connect_to_elixir() {
3949 println ! ( ) ;
4050 println ! ( " To run this test:" ) ;
4151 println ! ( " 1. cd crates/ambitious/tests/elixir_interop" ) ;
42- println ! ( " 2. elixir --sname elixir_test --cookie test_cookie test_server.exs" ) ;
4352 println ! (
44- " 3. cargo test -p ambitious --features erlang-dist erlang_interop -- --nocapture"
53+ " 2. elixir --sname elixir_test@localhost --cookie test_cookie test_server.exs"
54+ ) ;
55+ println ! (
56+ " 3. cargo test -p ambitious --features erlang-dist --test erlang_interop_test -- --nocapture"
4557 ) ;
4658 // Don't fail - just skip if Elixir isn't running
4759 return ;
@@ -52,11 +64,7 @@ async fn test_connect_to_elixir() {
5264/// Test sending a message to a registered process.
5365#[ tokio:: test]
5466async fn test_send_to_named_process ( ) {
55- let config = ErlangConfig :: new (
56- "rust_test2@localhost" ,
57- "elixir_test@localhost" ,
58- "test_cookie" ,
59- ) ;
67+ let config = test_config ( "rust_test2" ) ;
6068
6169 let mut conn = match ErlangConnection :: connect ( config) . await {
6270 Ok ( c) => c,
@@ -83,11 +91,7 @@ async fn test_send_to_named_process() {
8391/// Test making a gen_server call.
8492#[ tokio:: test]
8593async fn test_gen_server_call ( ) {
86- let config = ErlangConfig :: new (
87- "rust_test3@localhost" ,
88- "elixir_test@localhost" ,
89- "test_cookie" ,
90- ) ;
94+ let config = test_config ( "rust_test3" ) ;
9195
9296 let mut conn = match ErlangConnection :: connect ( config) . await {
9397 Ok ( c) => c,
@@ -140,11 +144,7 @@ async fn test_gen_server_call() {
140144/// Test receiving messages.
141145#[ tokio:: test]
142146async fn test_receive_cast ( ) {
143- let config = ErlangConfig :: new (
144- "rust_test4@localhost" ,
145- "elixir_test@localhost" ,
146- "test_cookie" ,
147- ) ;
147+ let config = test_config ( "rust_test4" ) ;
148148
149149 let mut conn = match ErlangConnection :: connect ( config) . await {
150150 Ok ( c) => c,
@@ -178,11 +178,7 @@ async fn test_receive_cast() {
178178/// automatically encoded to ETF and sent to BEAM nodes.
179179#[ tokio:: test]
180180async fn test_transparent_beam_interop ( ) {
181- let config = ErlangConfig :: new (
182- "rust_test5@localhost" ,
183- "elixir_test@localhost" ,
184- "test_cookie" ,
185- ) ;
181+ let config = test_config ( "rust_test5" ) ;
186182
187183 let mut conn = match ErlangConnection :: connect ( config) . await {
188184 Ok ( c) => c,
@@ -268,11 +264,7 @@ async fn receive_skipping_rex(conn: &mut ErlangConnection, timeout_secs: u64) ->
268264/// works correctly, setting up for cross-runtime linking/monitoring tests.
269265#[ tokio:: test]
270266async fn test_elixir_spawn_and_kill ( ) {
271- let config = ErlangConfig :: new (
272- "rust_test6@localhost" ,
273- "elixir_test@localhost" ,
274- "test_cookie" ,
275- ) ;
267+ let config = test_config ( "rust_test6" ) ;
276268
277269 let mut conn = match ErlangConnection :: connect ( config) . await {
278270 Ok ( c) => c,
@@ -379,11 +371,7 @@ async fn test_elixir_spawn_and_kill() {
379371/// process and observing the EXIT message when it dies.
380372#[ tokio:: test]
381373async fn test_elixir_link_behavior ( ) {
382- let config = ErlangConfig :: new (
383- "rust_test7@localhost" ,
384- "elixir_test@localhost" ,
385- "test_cookie" ,
386- ) ;
374+ let config = test_config ( "rust_test7" ) ;
387375
388376 let mut conn = match ErlangConnection :: connect ( config) . await {
389377 Ok ( c) => c,
@@ -505,11 +493,8 @@ async fn test_elixir_spawn_on_rust() {
505493 }
506494 } ) ;
507495
508- let config = ErlangConfig :: new (
509- "rust_test8@localhost" ,
510- "elixir_test@localhost" ,
511- "test_cookie" ,
512- ) ;
496+ let rust_node_name = node_name ( "rust_test8" ) ;
497+ let config = test_config ( "rust_test8" ) ;
513498
514499 let mut conn = match ErlangConnection :: connect ( config) . await {
515500 Ok ( c) => c,
@@ -524,7 +509,7 @@ async fn test_elixir_spawn_on_rust() {
524509
525510 // Ask Elixir to spawn a process on our node
526511 // Format: {:spawn_on_node, node, module, function, args}
527- let rust_node = OwnedTerm :: Atom ( erltf:: types:: Atom :: new ( "rust_test8@localhost" ) ) ;
512+ let rust_node = OwnedTerm :: Atom ( erltf:: types:: Atom :: new ( & rust_node_name ) ) ;
528513 let module = erl_atom ! ( "test_module" ) ;
529514 let function = erl_atom ! ( "test_func" ) ;
530515 let args = OwnedTerm :: List ( vec ! [ ] ) ; // Empty args list
0 commit comments