- I fixed some problems with remove_waiter and wrote the notify_wait function.
- I finished coding up the megaphone module.
- I came up with a plan for testing.
To simplify testing a bit I created a couple of functions that exercise the code to be tested in megaphone:
test_start_server(Port) ->
{ok, LSocket} = gen_tcp:listen(Port, [{packet, 0}, {active, false}]),
io:format("megaphone is now listening on port ~p~n", [Port]),
{ok, Sock} = gen_tcp:accept(LSocket),
io:format("megaphone now has a connection on port ~p, starting...~n", [Port]),
megaphone:start({gen_tcp, Sock}, undefined).
test_start_client(Port) ->
{ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {packet, 0}]),
gen_tcp:send(Socket, "hi there"),
receive after 15000 -> ok end.
test_start() ->
spawn(megaphone, test_start_server, [4567]),
receive after 2500 -> ok end,
spawn(megaphone, test_start_client, [4567]).
Upon running my simple tests, I discovered a simple truth: my system did not work. I got the following messages:
1> megaphone:test_start().
megaphone is now listening on port 4567
<0.35.0>
megaphone now has a connection on port 4567, starting...
2>
=ERROR REPORT==== 1-Feb-2012::19:21:20 ===
Error in process <0.34.0> with exit value: {undef,[{megaphone_sender,start,[#Port<0.523>]},{megaphone,start,2}]}
=ERROR REPORT==== 1-Feb-2012::19:21:20 ===
Error in process <0.39.0> with exit value: {undef,[{megaphone,start_receive,[#Port<0.523>,{megaphone_state,undefined,#Port<0.523>},undefined]}]}
However, that which does not kill us makes us stronger. By this reckoning I feel I should have super-hero like strength, thus demonstrating that this proverb is either not true or the margin by which we are made stronger is surpassing slim.
At any rate, this initial failure makes me think that I should regroup with a simpler test. Specifically, I should test the receiver and the sender separately. This also means less work, which fits in with my revised proverb: that which does not stress me out, makes me less stressed.
Next time: testing the receiver.
No comments:
Post a Comment