Modified stuff for easyer testing, logging questiondb count in daily stats

This commit is contained in:
mrfry 2021-08-01 11:31:09 +02:00
parent d7b5ad8160
commit cc19b5424b
8 changed files with 11 additions and 40 deletions

View file

@ -48,7 +48,6 @@ export interface RecievedData {
subj: string
id: string
version: string
scriptVersion: string
location: string
}

View file

@ -1,25 +0,0 @@
import { compareString } from './classes'
const testCases: Array<{ s1: string; s2: string; res: number }> = [
{ s1: 'hello', s2: 'hello', res: 100 },
{ s1: 'aaaaa', s2: 'bbbbb', res: 0 },
{
s1: 'Mely állítás nem igaz a tőzsdékre?',
s2: 'Mely állítás nem igaz a tőzsdékre?',
res: 100,
},
{
s1: 'Mely állítás nem igaz a tőzsdékre?',
s2: 'Ez egy teljesen más mondat',
res: 0,
},
{ s1: 'cHar caSe tESt', s2: 'ChaR cAse TEst', res: 0 },
]
testCases.forEach((currCase) => {
const { s1, s2, res } = currCase
test(`String compare tests: "${s1}" & "${s2}" should be: ${res}%`, () => {
expect(compareString(s1, s1.split(' '), s2, s2.split(' '))).toBe(res)
})
})

View file

@ -87,20 +87,12 @@ export function doALongTask(
})
}
export function initWorkerPool(initData: any): void {
export function initWorkerPool(initData: any): Array<WorkerObj> {
if (workers) {
logger.Log('WORKERS ALREADY EXISTS', logger.GetColor('redbg'))
return
}
workers = []
const factory = {
create: function(index) {
return getAWorker(index, initData)
},
destroy: function(client) {
client.worker.terminate()
},
}
const threadCount = process.env.NS_THREAD_COUNT || os.cpus().length
if (process.env.NS_THREAD_COUNT) {
@ -112,11 +104,13 @@ export function initWorkerPool(initData: any): void {
for (let i = 0; i < threadCount; i++) {
workers.push({
worker: factory.create(i),
worker: getAWorker(i, initData),
index: i,
free: true,
})
}
return workers
}
// ---------------------------------------------------------------------------
@ -169,7 +163,7 @@ function processJob() {
freeWorker.free = true
job.doneEvent.emit('done', res)
})
.catch(function(err) {
.catch(function (err) {
handleWorkerError(freeWorker, err)
})
}