- I came up with a plan for testing.
- After some initial tests, I resolved to test the different components in turn.
- I started testing the megaphone_receiver component.
I finished testing the megaphone_receiver component. I had to add some additional code to create a simple megaphone process to which megaphone_receiver could hand off packets. Here is the code:
test_megaphone() ->
register(megaphone, self()),
io:format("test_megaphone is now waiting for packets~n"),
test_megaphone_loop().
test_megaphone_loop() ->
receive
Packet ->
io:format("test megaphone process has received ~p~n", [Packet])
end,
test_megaphone_loop().
The test function now includes a call to start up the fake megaphone process:
test() ->
Port = 4567,
spawn(megaphone_receiver, test_megaphone, []),
spawn(megaphone_receiver, test_server, [Port]),
receive after 100 -> ok end,
spawn(megaphone_receiver, test_client, [Port]).
This does not mean that my code works, only that it seems to work in this one case. To paraphrase from Dune by Frank Herbert, "Never count a bug dead until you have seen the body; and even then, you can make a mistake."
Next time: megaphone_sender
No comments:
Post a Comment