<div dir="ltr">Why is that? I was under the impression that one of the advantages was that you can test the handle call/cast/info functions without having to stand up a full server to do a small surface area unit test.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Mar 27, 2016 at 5:43 PM, Robert Virding <span dir="ltr"><<a href="mailto:rvirding@gmail.com" target="_blank">rvirding@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>To be even more specific all the 6 gen_server callbacks[*] must always be run within the gen_server process, this irrespective of whether you are testing or not.<br><br></div>Robert<br><br></div>[*] init/1, terminate/2, handle_call/3, handle-cast/2, handle_info/2, code_change/3.<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On 27 March 2016 at 15:13, Matthew Shapiro <span dir="ltr"><<a href="mailto:me@mshapiro.net" target="_blank">me@mshapiro.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Well duh, now I feel like an idiot.<div><br></div><div>Thanks,</div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Mar 27, 2016 at 5:31 AM, Vimal Kumar <span dir="ltr"><<a href="mailto:vimal7370@gmail.com" target="_blank">vimal7370@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Matthew,<div><br></div><div>Like Nathaniel said, the eunit test should involve gen_server. Do not test handle_cast/2 directly. Instead, run your test on an exported function (say: Module:accept/0) which in turn should execute: </div><div><br></div><div>gen_server:cast(?MODULE, accept)</div><div><br></div><div>You can start a gen_server process, execute such tests and shut it down properly using 'setup' Fixture: <a href="http://learnyousomeerlang.com/eunit#fixtures" target="_blank">http://learnyousomeerlang.com/eunit#fixtures</a></div><div><br></div><div>Regards,</div><div>Vimal</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Sun, Mar 27, 2016 at 10:15 AM, Nathaniel Waisbrot <span dir="ltr"><<a href="mailto:nathaniel@waisbrot.net" target="_blank">nathaniel@waisbrot.net</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>I don't know about your garbage-collection question, but:<br>
<span><br>
> Why does that io:format/3 call (only when after the spawn/3 call) keep the socket open and active for the spawned process? I wouldn't expect it to be garbage collected because the spawned process holds a reference to it (and even adding it to the State in the return doesn't fix it). Only other thing I could think of was that handle_cast is run in it's own process which closes the socket when it dies (since it has ownership), but that doesn't make sense from what I've read about OTP.<br>
<br>
<br>
</span>Normally handle_cast would be run in the gen_server's process (since that's the whole point), but it looks to me like in your test:<br>
<span><br>
<br>
> spawn_link(fun () -> tcp_listener_server:handle_cast(accept, State) end),<br>
<br>
<br>
</span>you are bypassing gen_server and instead ... telling handle_cast to run in its own one-off process.<br>
<br>
<br>
Do you mean to be doing this? In your test code, you could call gen_server:start/1 and then gen_server:cast/2 and get the actual gen_server behavior.<br>
<br></div></div>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>