Reputation: 3700
I bumped into a following problem while using the component library - whenever a given component depends on another, the associated dependency in the system map does not release it's resources (i.e. is not stopped) on 'stop-system'.
I would assume that both lifecycle methods work in the dependency order and call start / stop for each component and its dependencies in a tree traversal of the dependency graph.
I haven't yet looked in detail, but I made a simple application that reproduces the problem in a simple unit test (call lein test
):
https://github.com/fbielejec/component-app
Upvotes: 2
Views: 160
Reputation: 314
The reason your test fails is because you retrieve the database dependency from the :message-handlers
, instead of the database dependency directly. As you indicate yourself, the stop
function of the database is correctly invoked, so the resource would be released (in a real-life situation).
However, the database dependency of the message handler still refers to the old database. Due to the nature of immutability, that's not the same instance of the one that is the result of the stop
function.
If you were to write the test like this, it would work:
(is (nil? (-> the-system
system/start
system/stop
:database
:connection)))
This verification succeeds as expected.
I hope this answers your question?
Upvotes: 2
Reputation: 34820
FWIW, if you add printlns
to the start and stop methods you will see this:
On system/start
:
db start
message handler start
On system/stop
:
message handler stop
db stop
I don't know why the database reference in the message handler isn't updated.
Upvotes: 0