Skip to content

Commit

Permalink
Merge pull request #2574 from yanguoyu/fix-ckb-monitor
Browse files Browse the repository at this point in the history
fix: Sometimes RPC timeout but ckb is living
  • Loading branch information
Keith-CY authored Jan 20, 2023
2 parents a1d54d9 + 5f944df commit 80b5802
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/neuron-wallet/src/services/ckb-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ let lastLogTime: number
export const getLookingValidTargetStatus = () => isLookingValidTarget

export const startCkbNode = async () => {
if (ckb !== null) {
logger.info(`CKB:\tckb is not closed, close it before start...`)
await stopCkbNode()
}
await initCkb()

logger.info('CKB:\tstarting node...')
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-wallet/src/services/monitor/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default abstract class Monitor {
}
}

async startMonitor(intervalTime: number = 10000, startNow: boolean = false) {
async startMonitor(intervalTime: number = 30000, startNow: boolean = false) {
this.interval = interval(intervalTime)
if (!this.subcription?.closed) {
this.subcription?.unsubscribe()
Expand Down
13 changes: 12 additions & 1 deletion packages/neuron-wallet/tests/services/ckb-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('ckb runner', () => {
beforeEach(() => {
resetMocks()

stubbedCkb.kill = jest.fn()
stubbedCkb.stderr = new EventEmitter()
stubbedCkb.stdout = new EventEmitter()
stubbedSpawn.mockReturnValue(stubbedCkb)
Expand All @@ -95,7 +96,12 @@ describe('ckb runner', () => {
stubbedExistsSync.mockReturnValue(true)
await startCkbNode()
})
it('should not init ckb config', () => {
afterEach(async () => {
const promise = stopCkbNode()
stubbedCkb.emit('close')
await promise
})
it('should not init ckb config', async () => {
expect(stubbedSpawn).not.toHaveBeenCalledWith(expect.stringContaining('/ckb'), [
'init',
'--chain',
Expand Down Expand Up @@ -124,6 +130,11 @@ describe('ckb runner', () => {
stubbedCkb.emit('close')
await promise
})
afterEach(async () => {
const stopPromise = stopCkbNode()
stubbedCkb.emit('close')
await stopPromise
})
it('inits ckb config', () => {
expect(stubbedSpawn).toHaveBeenCalledWith(expect.stringContaining(path.join(platformPath, 'ckb')), [
'init',
Expand Down

1 comment on commit 80b5802

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 3963887809

Please sign in to comment.