Skip to content

Commit d412a4f

Browse files
committed
Add test for whereis + send integration
Test that looks up a registered process using erlang.whereis() and then sends a message to it using erlang.send().
1 parent 4b44e53 commit d412a4f

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

test/py_pid_send_SUITE.erl

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
test_whereis_nonexistent/1,
4545
test_whereis_with_atom/1,
4646
test_whereis_with_bytes/1,
47-
test_whereis_invalid_type/1
47+
test_whereis_invalid_type/1,
48+
test_whereis_and_send/1
4849
]).
4950

5051
all() ->
@@ -75,7 +76,8 @@ all() ->
7576
test_whereis_nonexistent,
7677
test_whereis_with_atom,
7778
test_whereis_with_bytes,
78-
test_whereis_invalid_type
79+
test_whereis_invalid_type,
80+
test_whereis_and_send
7981
].
8082

8183
init_per_suite(Config) ->
@@ -346,6 +348,25 @@ test_whereis_invalid_type(_Config) ->
346348
{error, {'TypeError', _}} = py:eval(<<"erlang.whereis(123)">>),
347349
ok.
348350

351+
%% @doc Test looking up a process with whereis and sending a message to it.
352+
test_whereis_and_send(_Config) ->
353+
Self = self(),
354+
erlang:register(py_whereis_send_test, Self),
355+
try
356+
%% Use Python helper to look up process and send message
357+
{ok, true} = py:call(py_test_pid_send, whereis_and_send,
358+
[<<"py_whereis_send_test">>, {<<"hello_from_whereis">>, 42}]),
359+
%% Verify we received the message
360+
receive
361+
{<<"hello_from_whereis">>, 42} -> ok
362+
after 5000 ->
363+
ct:fail(timeout_waiting_for_message)
364+
end
365+
after
366+
erlang:unregister(py_whereis_send_test)
367+
end,
368+
ok.
369+
349370
%%% ============================================================================
350371
%%% Helper Functions
351372
%%% ============================================================================

test/py_test_pid_send.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,15 @@ async def async_interleaved():
183183
return loop.run_until_complete(async_interleaved())
184184
finally:
185185
loop.close()
186+
187+
188+
def whereis_and_send(name, msg):
189+
"""Look up a registered process by name and send it a message.
190+
191+
Returns True if the process was found and message sent, False otherwise.
192+
"""
193+
pid = erlang.whereis(name)
194+
if pid is not None:
195+
erlang.send(pid, msg)
196+
return True
197+
return False

0 commit comments

Comments
 (0)