Bug: service goes wrong (including not accessible) when call app.stop and app.start repeatedly
TimeBather opened this issue · 6 comments
TimeBather commented
最小复现:
向tests/service.spec.js
的normal service
测试结尾加入下列两行
app.plugin(Foo)
expect(app.foo).to.be.instanceOf(Foo)
运行结果:
31 passing (70ms)
1 failing
1) Service
normal service:
AssertionError: expected undefined to be an instance of Foo
at Context.<anonymous> (tests\service.spec.ts:25:27)
版本:
- cordis
1.4.2
(fromgit clone
,master branch)
shigma commented
It is working as expected. A normal service waits for an asynchronous service.start()
, so it is not available until next tick.
app.plugin(Foo)
await new Promise(resolve => setTimeout(resolve, 0))
expect(app.foo).to.be.instanceOf(Foo)
TimeBather commented
那我想请问一下,是不是每一次app.plugin完成之后都需要start
我感觉可能是我刚刚的最小复现给错了
shigma commented
app.start()
only needs to be called once.
TimeBather commented
我再去检查一下,这个问题确实是存在的,我使用了多次app.start()和app.stop()之后,service确实没有被启动,constructor也没有被执行,但包裹这个service插件是正常被执行的
shigma commented
I haven't tested whether services continue to work after app.stop()
. By current design, you really should not call these two methods repeatedly.
TimeBather commented
OK.I think that I can use the dispose
API to dispose all plugins mounted on the instance instead of app.stop()
.It seems to work.,thank you for your answer.