From 8b2a895641ad1c1bca1378fbfab4ce712e14bed1 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Mon, 12 Dec 2022 13:26:20 +0200 Subject: [PATCH 01/11] Add ability to estimate sync time --- workers/loc.api/sync/progress/index.js | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/workers/loc.api/sync/progress/index.js b/workers/loc.api/sync/progress/index.js index d4323bf94..fd0287f29 100644 --- a/workers/loc.api/sync/progress/index.js +++ b/workers/loc.api/sync/progress/index.js @@ -70,6 +70,48 @@ class Progress extends EventEmitter { ? tryParseJSON(progress.value, true) : 'SYNCHRONIZATION_HAS_NOT_STARTED_YET' } + + async _estimateSyncTime (params) { + const { + progress, + syncStartedAt + } = params ?? {} + + const nowMts = Date.now() + + if ( + !Number.isFinite(syncStartedAt) || + syncStartedAt > nowMts + ) { + return { + syncStartedAt: null, + spentTime: null, + leftTime: null + } + } + + const spentTime = nowMts - syncStartedAt + + if ( + !Number.isFinite(progress) || + progress <= 0 || + progress > 100 + ) { + return { + syncStartedAt, + spentTime, + leftTime: null + } + } + + const leftTime = (spentTime / progress) * (100 - progress) + + return { + syncStartedAt, + spentTime, + leftTime + } + } } decorateInjectable(Progress, depsTypes) From 08b84073d341f67cce33d05462670391423b4607 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Mon, 2 Jan 2023 08:28:12 +0200 Subject: [PATCH 02/11] Emit estimated sync time by ws --- workers/loc.api/sync/progress/index.js | 33 +++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/workers/loc.api/sync/progress/index.js b/workers/loc.api/sync/progress/index.js index fd0287f29..a5f39f8a9 100644 --- a/workers/loc.api/sync/progress/index.js +++ b/workers/loc.api/sync/progress/index.js @@ -1,7 +1,6 @@ 'use strict' const EventEmitter = require('events') -const { isEmpty } = require('lodash') const { tryParseJSON @@ -44,8 +43,12 @@ class Progress extends EventEmitter { this.TABLES_NAMES.PROGRESS, { value: JSON.stringify(_progress) } ) - this.emit(_progress) - await this.wsEventEmitter.emitProgress(() => _progress) + const estimatedSyncTime = this._estimateSyncTime({ + progress: _progress + }) + + this.emit(estimatedSyncTime) + await this.wsEventEmitter.emitProgress(() => estimatedSyncTime) } catch (e) { this.logger.error( `PROGRESS:SYNC:SET: ${e.stack || e}` @@ -60,23 +63,23 @@ class Progress extends EventEmitter { } async getProgress () { - const progress = await this.dao + const progressObj = await this.dao .getElemInCollBy(this.TABLES_NAMES.PROGRESS) - return ( - !isEmpty(progress) && - typeof progress.value === 'string' - ) - ? tryParseJSON(progress.value, true) + const progress = typeof progressObj?.value === 'string' + ? tryParseJSON(progressObj.value, true) : 'SYNCHRONIZATION_HAS_NOT_STARTED_YET' + const estimatedSyncTime = this._estimateSyncTime({ progress }) + + return estimatedSyncTime } async _estimateSyncTime (params) { const { - progress, - syncStartedAt + progress } = params ?? {} + const syncStartedAt = this._getSyncStartedAt() const nowMts = Date.now() if ( @@ -84,6 +87,7 @@ class Progress extends EventEmitter { syncStartedAt > nowMts ) { return { + progress, syncStartedAt: null, spentTime: null, leftTime: null @@ -98,6 +102,7 @@ class Progress extends EventEmitter { progress > 100 ) { return { + progress, syncStartedAt, spentTime, leftTime: null @@ -107,11 +112,17 @@ class Progress extends EventEmitter { const leftTime = (spentTime / progress) * (100 - progress) return { + progress, syncStartedAt, spentTime, leftTime } } + + // TODO: + _getSyncStartedAt () { + return Date.now() + } } decorateInjectable(Progress, depsTypes) From 23de4754f27e31c442aa7edf4fd3a274cb2b2520 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Mon, 2 Jan 2023 08:28:37 +0200 Subject: [PATCH 03/11] Add ability to activate/deactivate sync time estimate --- workers/loc.api/sync/progress/index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/workers/loc.api/sync/progress/index.js b/workers/loc.api/sync/progress/index.js index a5f39f8a9..5f8d109cc 100644 --- a/workers/loc.api/sync/progress/index.js +++ b/workers/loc.api/sync/progress/index.js @@ -27,6 +27,8 @@ class Progress extends EventEmitter { this.TABLES_NAMES = TABLES_NAMES this.wsEventEmitter = wsEventEmitter this.logger = logger + + this._syncStartedAt = null } async setProgress (progress) { @@ -74,6 +76,14 @@ class Progress extends EventEmitter { return estimatedSyncTime } + activateSyncTimeEstimate () { + this._syncStartedAt = Date.now() + } + + deactivateSyncTimeEstimate () { + this._syncStartedAt = null + } + async _estimateSyncTime (params) { const { progress @@ -119,9 +129,8 @@ class Progress extends EventEmitter { } } - // TODO: _getSyncStartedAt () { - return Date.now() + return this._syncStartedAt ?? null } } From faf9c11c63a4f0cb138d48b0469bac2f88672dd4 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Mon, 2 Jan 2023 08:28:44 +0200 Subject: [PATCH 04/11] Activate/deactivate sync time estimate for sync queue --- workers/loc.api/sync/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/workers/loc.api/sync/index.js b/workers/loc.api/sync/index.js index b4b4e3ed8..7f4656b02 100644 --- a/workers/loc.api/sync/index.js +++ b/workers/loc.api/sync/index.js @@ -37,8 +37,11 @@ class Sync { let progressForInterrupter = this.syncInterrupter .INITIAL_PROGRESS + this.progress.deactivateSyncTimeEstimate() + if (!error) { try { + this.progress.activateSyncTimeEstimate() progressForInterrupter = await this.syncQueue.process(params) } catch (err) { errorForInterrupter = err @@ -142,7 +145,9 @@ class Sync { } async stop () { - const currProgress = await this.progress.getProgress() + const currProgress = await this.progress + .deactivateSyncTimeEstimate() + .getProgress() if (currProgress < 100) { return this.syncInterrupter.interrupt() From c0c2228cb6b69034c11ae2ccdb2d57501ad04b27 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Mon, 2 Jan 2023 08:28:50 +0200 Subject: [PATCH 05/11] Change sync entrypoint for new progress interface --- workers/loc.api/sync/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/workers/loc.api/sync/index.js b/workers/loc.api/sync/index.js index 7f4656b02..773895617 100644 --- a/workers/loc.api/sync/index.js +++ b/workers/loc.api/sync/index.js @@ -67,7 +67,9 @@ class Sync { ) } - const currProgress = await this.progress.getProgress() + const { + progress: currProgress + } = await this.progress.getProgress() if (this.syncInterrupter.hasInterrupted()) { this.syncInterrupter.emitInterrupted( @@ -102,7 +104,9 @@ class Sync { } const isEnable = await this.rService.isSchedulerEnabled() - const currProgress = await this.progress.getProgress() + const { + progress: currProgress + } = await this.progress.getProgress() if (isEnable) { await this.syncQueue.add({ @@ -115,7 +119,7 @@ class Sync { (currProgress < 100) || !isEnable ) { - return this.progress.getProgress() + return this.progress.getProgress()?.progress } await this.rService.pingApi() @@ -145,7 +149,9 @@ class Sync { } async stop () { - const currProgress = await this.progress + const { + progress: currProgress + } = await this.progress .deactivateSyncTimeEstimate() .getProgress() From f607e07c9f7e396c00e3a4513a4e6f349404d28b Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Mon, 2 Jan 2023 08:28:55 +0200 Subject: [PATCH 06/11] Change data consistency checker for new progress interface --- workers/loc.api/sync/data.consistency.checker/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/workers/loc.api/sync/data.consistency.checker/index.js b/workers/loc.api/sync/data.consistency.checker/index.js index fedbb2529..d74f15b1f 100644 --- a/workers/loc.api/sync/data.consistency.checker/index.js +++ b/workers/loc.api/sync/data.consistency.checker/index.js @@ -40,7 +40,9 @@ class DataConsistencyChecker { const isValid = await check(auth) if (!isValid) { - const currProgress = await this.progress.getProgress() + const { + progress: currProgress + } = await this.progress.getProgress() const isDBSyncing = currProgress < 100 if (isDBSyncing) { From 379b5eecb102174cbdf3f0dc245cb8dc17ae9fdd Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Mon, 2 Jan 2023 08:28:59 +0200 Subject: [PATCH 07/11] Change getSyncProgress endpoint for new progress interface --- workers/loc.api/service.report.framework.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/workers/loc.api/service.report.framework.js b/workers/loc.api/service.report.framework.js index 72499745a..b8900f965 100644 --- a/workers/loc.api/service.report.framework.js +++ b/workers/loc.api/service.report.framework.js @@ -331,7 +331,12 @@ class FrameworkReportService extends ReportService { isSchedulerEnabled ) ? this._progress.getProgress() - : false + : { + progress: false, + syncStartedAt: null, + spentTime: null, + leftTime: null + } }, 'getSyncProgress', args, cb) } From 0bf6fa30acba591f073d8fe034da1c136ea92840 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Mon, 2 Jan 2023 08:29:04 +0200 Subject: [PATCH 08/11] Fix method chaining for progress service --- workers/loc.api/sync/progress/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/workers/loc.api/sync/progress/index.js b/workers/loc.api/sync/progress/index.js index 5f8d109cc..6503c5deb 100644 --- a/workers/loc.api/sync/progress/index.js +++ b/workers/loc.api/sync/progress/index.js @@ -78,10 +78,14 @@ class Progress extends EventEmitter { activateSyncTimeEstimate () { this._syncStartedAt = Date.now() + + return this } deactivateSyncTimeEstimate () { this._syncStartedAt = null + + return this } async _estimateSyncTime (params) { From b8cd14d755d1a81a6bd3818ca73104b945e722fd Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Mon, 2 Jan 2023 08:29:12 +0200 Subject: [PATCH 09/11] Fix returning progress when force pushing sync --- workers/loc.api/sync/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workers/loc.api/sync/index.js b/workers/loc.api/sync/index.js index 773895617..4cfc9642d 100644 --- a/workers/loc.api/sync/index.js +++ b/workers/loc.api/sync/index.js @@ -119,7 +119,7 @@ class Sync { (currProgress < 100) || !isEnable ) { - return this.progress.getProgress()?.progress + return (await this.progress.getProgress())?.progress } await this.rService.pingApi() From a64f16d9d56ef7e6362df9a355329aefd01b10c3 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Mon, 2 Jan 2023 08:29:19 +0200 Subject: [PATCH 10/11] Add common test case for getting sync progress finished state --- .../test-cases/get-sync-progress-test-case.js | 55 +++++++++++++++++++ test/test-cases/index.js | 4 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 test/test-cases/get-sync-progress-test-case.js diff --git a/test/test-cases/get-sync-progress-test-case.js b/test/test-cases/get-sync-progress-test-case.js new file mode 100644 index 000000000..ff1b7566f --- /dev/null +++ b/test/test-cases/get-sync-progress-test-case.js @@ -0,0 +1,55 @@ +'use strict' + +const { assert } = require('chai') + +const { delay } = require('../helpers/helpers.core') + +module.exports = ( + agent, + params = {} +) => { + const { + basePath, + auth + } = params + + it('it should be successfully performed by the getSyncProgress method', async function () { + this.timeout(60000) + + while (true) { + const res = await agent + .post(`${basePath}/json-rpc`) + .type('json') + .send({ + auth, + method: 'getSyncProgress', + id: 5 + }) + .expect('Content-Type', /json/) + .expect(200) + + assert.isObject(res.body) + assert.propertyVal(res.body, 'id', 5) + assert.isObject(res.body.result) + assert.isNumber(res.body.result.progress) + assert.isNumber(res.body.result.syncStartedAt) + assert.isNumber(res.body.result.spentTime) + + if ( + !Number.isFinite(res.body.result.progress) || + res.body.result.progress <= 0 || + res.body.result.progress > 100 + ) { + assert.isNull(res.body.result.leftTime) + } else { + assert.isNumber(res.body.result.leftTime) + } + + if (res.body.result.progress === 100) { + break + } + + await delay() + } + }) +} diff --git a/test/test-cases/index.js b/test/test-cases/index.js index d76609ef1..4470bccb9 100644 --- a/test/test-cases/index.js +++ b/test/test-cases/index.js @@ -7,9 +7,11 @@ const additionalApiSyncModeSqliteTestCases = require( './additional-api-sync-mode-sqlite-test-cases' ) const signUpTestCase = require('./sign-up-test-case') +const getSyncProgressTestCase = require('./get-sync-progress-test-case') module.exports = { apiSyncModeSqliteTestCases, additionalApiSyncModeSqliteTestCases, - signUpTestCase + signUpTestCase, + getSyncProgressTestCase } From 95f583336f14541c7c7443e2eb25acf4eb7ca78a Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Mon, 2 Jan 2023 08:29:24 +0200 Subject: [PATCH 11/11] Add new sync progress test case to test flows --- test/3-api-filter-sync-mode-sqlite.spec.js | 98 +----- test/6-update-sub-account.spec.js | 96 +----- ...itional-api-sync-mode-sqlite-test-cases.js | 33 +-- .../api-sync-mode-sqlite-test-cases.js | 278 +----------------- 4 files changed, 32 insertions(+), 473 deletions(-) diff --git a/test/3-api-filter-sync-mode-sqlite.spec.js b/test/3-api-filter-sync-mode-sqlite.spec.js index da9841198..e55ae8e86 100644 --- a/test/3-api-filter-sync-mode-sqlite.spec.js +++ b/test/3-api-filter-sync-mode-sqlite.spec.js @@ -20,8 +20,7 @@ const { startEnvironment } = require('./helpers/helpers.boot') const { - emptyDB, - delay + emptyDB } = require('./helpers/helpers.core') const { createMockRESTv2SrvWithDate @@ -31,7 +30,10 @@ process.env.NODE_CONFIG_DIR = path.join(__dirname, 'config') const { app } = require('bfx-report-express') const agent = request.agent(app) -const { signUpTestCase } = require('./test-cases') +const { + signUpTestCase, + getSyncProgressTestCase +} = require('./test-cases') let wrkReportServiceApi = null let processorQueue = null @@ -120,35 +122,7 @@ describe('API filter', () => { ) }) - it('it should be successfully performed by the getSyncProgress method', async function () { - this.timeout(60000) - - while (true) { - const res = await agent - .post(`${basePath}/json-rpc`) - .type('json') - .send({ - auth, - method: 'getSyncProgress', - id: 5 - }) - .expect('Content-Type', /json/) - .expect(200) - - assert.isObject(res.body) - assert.propertyVal(res.body, 'id', 5) - assert.isNumber(res.body.result) - - if ( - typeof res.body.result !== 'number' || - res.body.result === 100 - ) { - break - } - - await delay() - } - }) + getSyncProgressTestCase(agent, { basePath, auth }) it('it should be successfully performed by the editPublicTradesConf method', async function () { this.timeout(5000) @@ -175,35 +149,7 @@ describe('API filter', () => { assert.isOk(res.body.result) }) - it('it should be successfully performed by the getSyncProgress method', async function () { - this.timeout(60000) - - while (true) { - const res = await agent - .post(`${basePath}/json-rpc`) - .type('json') - .send({ - auth, - method: 'getSyncProgress', - id: 5 - }) - .expect('Content-Type', /json/) - .expect(200) - - assert.isObject(res.body) - assert.propertyVal(res.body, 'id', 5) - assert.isNumber(res.body.result) - - if ( - typeof res.body.result !== 'number' || - res.body.result === 100 - ) { - break - } - - await delay() - } - }) + getSyncProgressTestCase(agent, { basePath, auth }) it('it should be successfully performed by the editTickersHistoryConf method', async function () { this.timeout(5000) @@ -230,35 +176,7 @@ describe('API filter', () => { assert.isOk(res.body.result) }) - it('it should be successfully performed by the getSyncProgress method', async function () { - this.timeout(60000) - - while (true) { - const res = await agent - .post(`${basePath}/json-rpc`) - .type('json') - .send({ - auth, - method: 'getSyncProgress', - id: 5 - }) - .expect('Content-Type', /json/) - .expect(200) - - assert.isObject(res.body) - assert.propertyVal(res.body, 'id', 5) - assert.isNumber(res.body.result) - - if ( - typeof res.body.result !== 'number' || - res.body.result === 100 - ) { - break - } - - await delay() - } - }) + getSyncProgressTestCase(agent, { basePath, auth }) it('it should be successfully performed by the api methods', async function () { this.timeout(10000) diff --git a/test/6-update-sub-account.spec.js b/test/6-update-sub-account.spec.js index 30b9a40c4..e3ee1440c 100644 --- a/test/6-update-sub-account.spec.js +++ b/test/6-update-sub-account.spec.js @@ -17,8 +17,7 @@ const { } = require('./helpers/helpers.boot') const { emptyDB, - getRServiceProxy, - delay + getRServiceProxy } = require('./helpers/helpers.core') const { createMockRESTv2SrvWithDate, @@ -31,7 +30,8 @@ const { app } = require('bfx-report-express') const agent = request.agent(app) const { - signUpTestCase + signUpTestCase, + getSyncProgressTestCase } = require('./test-cases') let wrkReportServiceApi = null @@ -289,35 +289,7 @@ describe('Update sub-account', () => { assert.isOk(res.body.result) }) - it('it should be successfully performed by the getSyncProgress method', async function () { - this.timeout(60000) - - while (true) { - const res = await agent - .post(`${basePath}/json-rpc`) - .type('json') - .send({ - auth: subAccountAuth, - method: 'getSyncProgress', - id: 5 - }) - .expect('Content-Type', /json/) - .expect(200) - - assert.isObject(res.body) - assert.propertyVal(res.body, 'id', 5) - assert.isNumber(res.body.result) - - if ( - typeof res.body.result !== 'number' || - res.body.result === 100 - ) { - break - } - - await delay() - } - }) + getSyncProgressTestCase(agent, { basePath, auth: subAccountAuth }) it('it should be successfully performed by the getLedgers method, without params', async function () { this.timeout(5000) @@ -517,35 +489,7 @@ describe('Update sub-account', () => { assert.isString(res.body.result.token) }) - it('it should be successfully performed by the getSyncProgress method', async function () { - this.timeout(60000) - - while (true) { - const res = await agent - .post(`${basePath}/json-rpc`) - .type('json') - .send({ - auth: subAccountAuth, - method: 'getSyncProgress', - id: 5 - }) - .expect('Content-Type', /json/) - .expect(200) - - assert.isObject(res.body) - assert.propertyVal(res.body, 'id', 5) - assert.isNumber(res.body.result) - - if ( - typeof res.body.result !== 'number' || - res.body.result === 100 - ) { - break - } - - await delay() - } - }) + getSyncProgressTestCase(agent, { basePath, auth: subAccountAuth }) it('it should be successfully performed by the getUsers method', async function () { this.timeout(5000) @@ -587,35 +531,7 @@ describe('Update sub-account', () => { }) }) - it('it should be successfully performed by the getSyncProgress method', async function () { - this.timeout(60000) - - while (true) { - const res = await agent - .post(`${basePath}/json-rpc`) - .type('json') - .send({ - auth: subAccountAuth, - method: 'getSyncProgress', - id: 5 - }) - .expect('Content-Type', /json/) - .expect(200) - - assert.isObject(res.body) - assert.propertyVal(res.body, 'id', 5) - assert.isNumber(res.body.result) - - if ( - typeof res.body.result !== 'number' || - res.body.result === 100 - ) { - break - } - - await delay() - } - }) + getSyncProgressTestCase(agent, { basePath, auth: subAccountAuth }) it('it should be successfully performed by the getLedgers method, without params', async function () { this.timeout(5000) diff --git a/test/test-cases/additional-api-sync-mode-sqlite-test-cases.js b/test/test-cases/additional-api-sync-mode-sqlite-test-cases.js index 6cbb6975b..d692479aa 100644 --- a/test/test-cases/additional-api-sync-mode-sqlite-test-cases.js +++ b/test/test-cases/additional-api-sync-mode-sqlite-test-cases.js @@ -10,13 +10,14 @@ const { } = require('bfx-report/test/helpers/helpers.tests') const { - delay, getParamsArrToTestTimeframeGrouping } = require('../helpers/helpers.core') const { testCsvPathHasCommonFolder } = require('../helpers/helpers.tests') +const getSyncProgressTestCase = require('./get-sync-progress-test-case') + module.exports = ( agent, params = {} @@ -123,35 +124,7 @@ module.exports = ( ) }) - it('it should be successfully performed by the getSyncProgress method', async function () { - this.timeout(60000) - - while (true) { - const res = await agent - .post(`${basePath}/json-rpc`) - .type('json') - .send({ - auth, - method: 'getSyncProgress', - id: 5 - }) - .expect('Content-Type', /json/) - .expect(200) - - assert.isObject(res.body) - assert.propertyVal(res.body, 'id', 5) - assert.isNumber(res.body.result) - - if ( - typeof res.body.result !== 'number' || - res.body.result === 100 - ) { - break - } - - await delay() - } - }) + getSyncProgressTestCase(agent, { basePath, auth }) it('it should be successfully performed by the getBalanceHistory method', async function () { this.timeout(5000) diff --git a/test/test-cases/api-sync-mode-sqlite-test-cases.js b/test/test-cases/api-sync-mode-sqlite-test-cases.js index 5c561f4b2..4e08bf703 100644 --- a/test/test-cases/api-sync-mode-sqlite-test-cases.js +++ b/test/test-cases/api-sync-mode-sqlite-test-cases.js @@ -11,7 +11,7 @@ const { testProcQueue } = require('bfx-report/test/helpers/helpers.tests') -const { delay } = require('../helpers/helpers.core') +const getSyncProgressTestCase = require('./get-sync-progress-test-case') const { getMockData } = require('../helpers/helpers.mock-rest-v2') module.exports = ( @@ -414,35 +414,7 @@ module.exports = ( assert.isOk(res.body.result) }) - it('it should be successfully performed by the getSyncProgress method', async function () { - this.timeout(60000) - - while (true) { - const res = await agent - .post(`${basePath}/json-rpc`) - .type('json') - .send({ - auth, - method: 'getSyncProgress', - id: 5 - }) - .expect('Content-Type', /json/) - .expect(200) - - assert.isObject(res.body) - assert.propertyVal(res.body, 'id', 5) - assert.isNumber(res.body.result) - - if ( - typeof res.body.result !== 'number' || - res.body.result === 100 - ) { - break - } - - await delay() - } - }) + getSyncProgressTestCase(agent, { basePath, auth }) it('it should be successfully performed by the haveCollsBeenSyncedAtLeastOnce method, returns true', async function () { this.timeout(60000) @@ -488,35 +460,7 @@ module.exports = ( assert.isOk(res.body.result) }) - it('it should be successfully performed by the getSyncProgress method', async function () { - this.timeout(60000) - - while (true) { - const res = await agent - .post(`${basePath}/json-rpc`) - .type('json') - .send({ - auth, - method: 'getSyncProgress', - id: 5 - }) - .expect('Content-Type', /json/) - .expect(200) - - assert.isObject(res.body) - assert.propertyVal(res.body, 'id', 5) - assert.isNumber(res.body.result) - - if ( - typeof res.body.result !== 'number' || - res.body.result === 100 - ) { - break - } - - await delay() - } - }) + getSyncProgressTestCase(agent, { basePath, auth }) it('it should be successfully performed by the editPublicTradesConf method', async function () { this.timeout(5000) @@ -548,35 +492,7 @@ module.exports = ( assert.isOk(res.body.result) }) - it('it should be successfully performed by the getSyncProgress method', async function () { - this.timeout(60000) - - while (true) { - const res = await agent - .post(`${basePath}/json-rpc`) - .type('json') - .send({ - auth, - method: 'getSyncProgress', - id: 5 - }) - .expect('Content-Type', /json/) - .expect(200) - - assert.isObject(res.body) - assert.propertyVal(res.body, 'id', 5) - assert.isNumber(res.body.result) - - if ( - typeof res.body.result !== 'number' || - res.body.result === 100 - ) { - break - } - - await delay() - } - }) + getSyncProgressTestCase(agent, { basePath, auth }) it('it should be successfully performed by the getPublicTradesConf method', async function () { this.timeout(5000) @@ -630,35 +546,7 @@ module.exports = ( assert.isOk(res.body.result) }) - it('it should be successfully performed by the getSyncProgress method', async function () { - this.timeout(60000) - - while (true) { - const res = await agent - .post(`${basePath}/json-rpc`) - .type('json') - .send({ - auth, - method: 'getSyncProgress', - id: 5 - }) - .expect('Content-Type', /json/) - .expect(200) - - assert.isObject(res.body) - assert.propertyVal(res.body, 'id', 5) - assert.isNumber(res.body.result) - - if ( - typeof res.body.result !== 'number' || - res.body.result === 100 - ) { - break - } - - await delay() - } - }) + getSyncProgressTestCase(agent, { basePath, auth }) it('it should be successfully performed by the editTickersHistoryConf method', async function () { this.timeout(5000) @@ -690,35 +578,7 @@ module.exports = ( assert.isOk(res.body.result) }) - it('it should be successfully performed by the getSyncProgress method', async function () { - this.timeout(60000) - - while (true) { - const res = await agent - .post(`${basePath}/json-rpc`) - .type('json') - .send({ - auth, - method: 'getSyncProgress', - id: 5 - }) - .expect('Content-Type', /json/) - .expect(200) - - assert.isObject(res.body) - assert.propertyVal(res.body, 'id', 5) - assert.isNumber(res.body.result) - - if ( - typeof res.body.result !== 'number' || - res.body.result === 100 - ) { - break - } - - await delay() - } - }) + getSyncProgressTestCase(agent, { basePath, auth }) it('it should be successfully performed by the getTickersHistoryConf method', async function () { this.timeout(5000) @@ -774,35 +634,7 @@ module.exports = ( assert.isOk(res.body.result) }) - it('it should be successfully performed by the getSyncProgress method', async function () { - this.timeout(60000) - - while (true) { - const res = await agent - .post(`${basePath}/json-rpc`) - .type('json') - .send({ - auth, - method: 'getSyncProgress', - id: 5 - }) - .expect('Content-Type', /json/) - .expect(200) - - assert.isObject(res.body) - assert.propertyVal(res.body, 'id', 5) - assert.isNumber(res.body.result) - - if ( - typeof res.body.result !== 'number' || - res.body.result === 100 - ) { - break - } - - await delay() - } - }) + getSyncProgressTestCase(agent, { basePath, auth }) it('it should be successfully performed by the getStatusMessagesConf method', async function () { this.timeout(5000) @@ -855,35 +687,7 @@ module.exports = ( assert.isOk(res.body.result) }) - it('it should be successfully performed by the getSyncProgress method', async function () { - this.timeout(60000) - - while (true) { - const res = await agent - .post(`${basePath}/json-rpc`) - .type('json') - .send({ - auth, - method: 'getSyncProgress', - id: 5 - }) - .expect('Content-Type', /json/) - .expect(200) - - assert.isObject(res.body) - assert.propertyVal(res.body, 'id', 5) - assert.isNumber(res.body.result) - - if ( - typeof res.body.result !== 'number' || - res.body.result === 100 - ) { - break - } - - await delay() - } - }) + getSyncProgressTestCase(agent, { basePath, auth }) it('it should be successfully performed by the getCandlesConf method', async function () { this.timeout(5000) @@ -965,35 +769,7 @@ module.exports = ( assert.isOk(res.body.result) }) - it('it should be successfully performed by the getSyncProgress method', async function () { - this.timeout(60000) - - while (true) { - const res = await agent - .post(`${basePath}/json-rpc`) - .type('json') - .send({ - auth, - method: 'getSyncProgress', - id: 5 - }) - .expect('Content-Type', /json/) - .expect(200) - - assert.isObject(res.body) - assert.propertyVal(res.body, 'id', 5) - assert.isNumber(res.body.result) - - if ( - typeof res.body.result !== 'number' || - res.body.result === 100 - ) { - break - } - - await delay() - } - }) + getSyncProgressTestCase(agent, { basePath, auth }) it('it should be successfully performed by the getAllPublicСollsСonfs method', async function () { this.timeout(5000) @@ -1116,35 +892,7 @@ module.exports = ( ) }) - it('it should be successfully performed by the getSyncProgress method', async function () { - this.timeout(60000) - - while (true) { - const res = await agent - .post(`${basePath}/json-rpc`) - .type('json') - .send({ - auth, - method: 'getSyncProgress', - id: 5 - }) - .expect('Content-Type', /json/) - .expect(200) - - assert.isObject(res.body) - assert.propertyVal(res.body, 'id', 5) - assert.isNumber(res.body.result) - - if ( - typeof res.body.result !== 'number' || - res.body.result === 100 - ) { - break - } - - await delay() - } - }) + getSyncProgressTestCase(agent, { basePath, auth }) it('it should be successfully performed by the isSyncModeWithDbData method', async function () { this.timeout(5000) @@ -3561,7 +3309,11 @@ module.exports = ( assert.isObject(res.body) assert.propertyVal(res.body, 'id', 5) - assert.isNotOk(res.body.result) + assert.isObject(res.body.result) + assert.isNotOk(res.body.result.progress) + assert.isNull(res.body.result.syncStartedAt) + assert.isNull(res.body.result.spentTime) + assert.isNull(res.body.result.leftTime) }) it('it should be successfully performed by the disableSyncMode method', async function () {