提交 b11a6b0c 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

strict check current to equla to target, or throw exception

上级 4a5a618a
......@@ -63,3 +63,13 @@ test('StateMonitor client & stable/inprocess', t => {
t.true(sm.stable(), 'should be stable')
t.false(sm.inprocess(), 'should be not inprocess')
})
test('current() strict check with target', t => {
const CLIENT_NAME = 'StateMonitorTest'
const sm = new StateMonitor<'A', 'B'>(CLIENT_NAME, 'A')
t.throws(() => sm.current('B'), Error, 'should thorw for unmatch current & target')
sm.target('B')
t.notThrows(() => sm.current('B'), 'should not throws for matched current & target')
})
......@@ -58,6 +58,20 @@ export class StateMonitor <A, B>{
, this._current, this._stable
)
/**
* strict check current is equal to target
*/
if (this._target !== newState) {
log.warn('StateMonitor', '%s:current(%s,%s) current is different with target. call state.target(%s) first.'
, this._client
, newState, stable
, newState
)
const e = new Error('current not match target')
log.verbose('StateMonitor', e.stack)
throw e
}
/**
* warn for inprocess current state change twice, mostly like a logic bug outside
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册