Conversation
When soft limit is reached couch_proc_manager evicts idle processes by casting on them `stop` message. Since mango_native_proc doesn't handle this message it results to its crash with `invalid_cast` reason.
| erlang:yield(), | ||
| ?assertEqual({noreply, []}, handle_cast(garbage_collect, [])), | ||
| receive | ||
| {'DOWN', TracerRef, _, _, Msg} -> ?assertEqual(gc_start, Msg) |
There was a problem hiding this comment.
So iiuc, when the spawned process starts garbage collection, it'll exit with gc_start which would then cause our mango_native_proc to exit with an {invalid_cast, gc_start}
There was a problem hiding this comment.
No, no, it's different.
We spawn and monitor a new process that sets a trace on the test process, because process can't trace itself. Then in the test process we call a garbage collection by executing handle_cast(garbage_collect, []) and asserting that we are getting proper noreply response. The tracer receives gc_start trace message, indicating that its target (the test process) started a garbage collection and exits with reason gc_start. Because we are monitoring it in our test process, we are receiving its exit reason and can assert that it was indeed for a garbage collection.
Interesting bit here is erlang:yield() - we need to give a scheduler a chance to run the tracer process or gc will be finished before the trace set.
Conceptually it's is not different from when we are mocking module with meck and then waiting for some of its functions to be called, but I had to use trace here because you can't mock garbage_collection. Plus, unlike mock, this is a real deal, we are checking actual, not simulated functionality.
There was a problem hiding this comment.
@eiri : I completely forgot to check that we have handle_cast(garbage_collect, St) in the source. That's what confused me. This test was for that functionality. Got it!
|
The fix lgtm. The garbage collection test is a little tricky, just want to understand it a bit better. |
|
Hey @tonysun83 , was my explanation sufficient? Do you want me to change anything in the tests? |
|
+1 |
Overview
When soft limit is reached couch_proc_manager evicts idle processes by casting on them
stopmessage. Since mango_native_proc doesn't handle this message it results to its crash with
invalid_castreason.Testing recommendations
make eunit apps=mangoormake eunit apps=mango suites=mango_native_procfor isolated test.make mango-testfor integration test.Checklist