Browse Source

Update log & scheduler.test.js

develop
Jerome Wu 5 years ago
parent
commit
d1c4a33c9e
  1. 2
      package.json
  2. 6
      src/createScheduler.js
  3. 4
      src/createWorker.js
  4. 3
      tests/constants.js
  5. 12
      tests/scheduler.test.js

2
package.json

@ -14,7 +14,7 @@ @@ -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",

6
src/createScheduler.js

@ -42,7 +42,7 @@ module.exports = () => { @@ -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 = () => { @@ -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;
};

4
src/createWorker.js

@ -40,7 +40,7 @@ module.exports = (_options = {}) => { @@ -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 = {}) => { @@ -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);

3
tests/constants.js

@ -2,9 +2,10 @@ const TIMEOUT = 10000; @@ -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';

12
tests/scheduler.test.js

@ -4,7 +4,7 @@ let workers = []; @@ -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() { @@ -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) => (

Loading…
Cancel
Save