From d1c4a33c9e45e1dda6c3aba0402316606c0cbd44 Mon Sep 17 00:00:00 2001 From: Jerome Wu Date: Wed, 2 Oct 2019 17:26:36 +0800 Subject: [PATCH] Update log & scheduler.test.js --- package.json | 2 +- src/createScheduler.js | 6 +++--- src/createWorker.js | 4 ++-- tests/constants.js | 3 ++- tests/scheduler.test.js | 12 ++++++------ 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 2a7c124..4cfdae2 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "test": "npm-run-all -p -r start test:all", "test:all": "npm-run-all wait test:browser:* test:node", "test:node": "nyc mocha --exit --bail --require ./scripts/test-helper.js ./tests/*.test.js", - "test:browser-tpl": "mocha-headless-chrome -a incognito -a no-sandbox -a disable-setuid-sandbox -t 300000", + "test:browser-tpl": "mocha-headless-chrome -a incognito -a no-sandbox -a disable-setuid-sandbox -a disable-logging -t 300000", "test:browser:detect": "npm run test:browser-tpl -- -f ./tests/detect.test.html", "test:browser:recognize": "npm run test:browser-tpl -- -f ./tests/recognize.test.html", "test:browser:scheduler": "npm run test:browser-tpl -- -f ./tests/scheduler.test.html", diff --git a/src/createScheduler.js b/src/createScheduler.js index c2003f4..7fee07d 100644 --- a/src/createScheduler.js +++ b/src/createScheduler.js @@ -42,7 +42,7 @@ module.exports = () => { dequeue(); } }); - log(`[${id}]: add ${job.id} to JobQueue`); + log(`[${id}]: Add ${job.id} to JobQueue`); log(`[${id}]: JobQueue length=${jobQueue.length}`); dequeue(); }) @@ -50,8 +50,8 @@ module.exports = () => { const addWorker = (w) => { workers[w.id] = w; - log(`[${id}]: add ${w.id}`); - log(`[${id}]: number of workers=${getNumWorkers()}`); + log(`[${id}]: Add ${w.id}`); + log(`[${id}]: Number of workers=${getNumWorkers()}`); dequeue(); return w.id; }; diff --git a/src/createWorker.js b/src/createWorker.js index 0689757..0788d58 100644 --- a/src/createWorker.js +++ b/src/createWorker.js @@ -40,7 +40,7 @@ module.exports = (_options = {}) => { const startJob = ({ id: jobId, action, payload }) => ( new Promise((resolve, reject) => { - log(`[${id}]: Start ${jobId}, action=${action}, payload=`, payload); + log(`[${id}]: Start ${jobId}, action=${action}`); setResolve(action, resolve); setReject(action, reject); send(worker, { @@ -119,7 +119,7 @@ module.exports = (_options = {}) => { workerId, jobId, status, action, data, }) => { if (status === 'resolve') { - log(`[${workerId}]: Complete ${jobId}, data=`, data); + log(`[${workerId}]: Complete ${jobId}`); let d = data; if (action === 'recognize') { d = circularize(data); diff --git a/tests/constants.js b/tests/constants.js index e65f493..cb3c07b 100644 --- a/tests/constants.js +++ b/tests/constants.js @@ -2,9 +2,10 @@ const TIMEOUT = 10000; const IMAGE_PATH = 'http://localhost:3000/tests/assets/images'; const IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined'; const OPTIONS = { + cacheMethod: 'readOnly', langPath: 'http://localhost:3000/tests/assets/traineddata', cachePath: './tests/assets/traineddata', - ...(IS_BROWSER ? { workerPath: '/dist/worker.dev.js' } : {}), + ...(IS_BROWSER ? { workerPath: '../dist/worker.dev.js' } : {}), }; const SIMPLE_TEXT = 'Tesseract.js\n'; const SIMPLE_TEXT_HALF = 'Tesse\n'; diff --git a/tests/scheduler.test.js b/tests/scheduler.test.js index 1bab4ca..b47cc83 100644 --- a/tests/scheduler.test.js +++ b/tests/scheduler.test.js @@ -4,7 +4,7 @@ let workers = []; before(async function cb() { this.timeout(0); - const NUM_WORKERS = 10; + const NUM_WORKERS = 5; console.log(`Initializing ${NUM_WORKERS} workers`); workers = await Promise.all(Array(NUM_WORKERS).fill(0).map(async () => { const w = createWorker(OPTIONS); @@ -17,12 +17,12 @@ before(async function cb() { }); describe('scheduler', () => { - describe('should speed up with more workers (running 20 jobs)', () => { - Array(10).fill(0).forEach((_, num) => ( - it(`support using ${num + 1} workers`, async () => { - const NUM_JOBS = 30; + describe('should speed up with more workers (running 10 jobs)', () => { + [1, 3, 5].forEach(num => ( + it(`support using ${num} workers`, async () => { + const NUM_JOBS = 10; const scheduler = createScheduler(); - workers.slice(0, num + 1).forEach((w) => { + workers.slice(0, num).forEach((w) => { scheduler.addWorker(w); }); const rets = await Promise.all(Array(NUM_JOBS).fill(0).map((_, idx) => (