Skip to content

Commit 9a11ad1

Browse files
authored
Make it functional (#85)
* fix: actually awaiting result fixes idrinth-api-bench/issues#1127 * fix: actually fixing includes fixes idrinth-api-bench/issues#1127 * fix: actually fixing includes fixes idrinth-api-bench/issues#1127 * fix: actually fixing includes fixes idrinth-api-bench/issues#1127 * fix: actually fixing includes fixes idrinth-api-bench/issues#1127
1 parent edde78e commit 9a11ad1

15 files changed

Lines changed: 62 additions & 153 deletions

index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ import {
5858
import {
5959
run as r,
6060
} from './src/main.js';
61-
import rS from './src/store/result-store.js';
62-
import iR from './src/reporter/internal-reporter.js';
6361

6462
export type Reporter = R;
6563
export const CliReporter = CliR;
@@ -80,7 +78,5 @@ export const MssqlStorage = MSSQLS;
8078
export const PostgresStorage = PGSQL;
8179
export type Job = J;
8280
export type Task = T;
83-
export const internalReporter = iR;
84-
export const resultStore = rS;
8581
export const run = r;
8682
export default r;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@idrinth-api-bench/framework",
33
"description": "A library to benchmark apis, no matter if rest or soap",
44
"license": "MIT",
5-
"version": "1.0.8",
5+
"version": "1.0.12",
66
"type": "module",
77
"main": "index.js",
88
"homepage": "https://idrinth-api-ben.ch",

src/cli/cli.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
ONE,
66
FRAMEWORK_ROOT,
77
} from '../constants.js';
8-
import resultStore from '../store/result-store.js';
98
import run from '../main.js';
109
import configFactory from '../config/config-factory.js';
1110
import storageFactory from '../storage/storage-factory.js';
@@ -15,37 +14,32 @@ import {readFileSync} from "fs";
1514
// eslint-disable-next-line complexity
1615
export default async(args: string[], cwd: string,): Promise<number> => {
1716
const config = configFactory(cwd, args, process.env,);
18-
resultStore.set(false,);
1917
const storage = storageFactory(config,);
2018
switch (config.task) {
2119
case 'bench':
22-
await run({
20+
return await run({
2321
mode: 'benchmarking',
2422
taskId: config.taskId,
2523
language: config.language,
2624
cwd: config.cwd,
2725
resultStorage: storage,
28-
}, config.threads, config.repetitions,);
29-
break;
26+
}, config.threads, config.repetitions,) ? STATUSCODE_SUCCESS : STATUSCODE_FAILURE;
3027
case 'content':
31-
await run({
28+
return await run({
3229
mode: 'content-testing',
3330
taskId: config.taskId,
3431
language: config.language,
3532
cwd: config.cwd,
36-
}, ONE, ONE,);
37-
break;
33+
}, ONE, ONE,) ? STATUSCODE_SUCCESS : STATUSCODE_FAILURE;
3834
case 'load':
39-
await loader(config,);
40-
break;
35+
return await loader(config,) ? STATUSCODE_SUCCESS : STATUSCODE_FAILURE;
4136
case 'verify':
42-
await run({
37+
return await run({
4338
mode: 'verify',
4439
taskId: config.taskId,
4540
language: config.language,
4641
cwd: config.cwd,
47-
},);
48-
break;
42+
},) ? STATUSCODE_SUCCESS : STATUSCODE_FAILURE;
4943
case 'stress':
5044
console.error('NOT YET IMPLEMENTED',);
5145
return STATUSCODE_FAILURE;
@@ -73,5 +67,4 @@ export default async(args: string[], cwd: string,): Promise<number> => {
7367
);
7468
return STATUSCODE_SUCCESS;
7569
}
76-
return resultStore.get(false,) ? STATUSCODE_SUCCESS : STATUSCODE_FAILURE;
7770
};

src/constants.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,7 @@ export const STATUSCODE_FAILURE = 1;
5050
// Fixes GitHub Action's broken /tmp
5151
export const TEMP_DIR = process.env.RUNNER_TEMP ?? tmpdir();
5252
// Fixes tests running in typescript
53-
export const INCLUDE_EXTENSION = existsSync('./constants.js',) ? '.js' : '.ts';
54-
53+
export const INCLUDE_EXTENSION = existsSync(
54+
fileURLToPath(new URL('.', import.meta.url)) + '../index.js'
55+
) ? '.js' : '.ts';
56+
export const CLOSE_WAIT_TIMEOUT = 3333;

src/executor.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Task from './routes/task.js';
2424
import buildTaskList from './routes/build-task-list.js';
2525

2626
/* eslint max-params:0 */
27-
const executor = (
27+
const executor = async(
2828
threads: number,
2929
repetitions: number,
3030
job: Job,
@@ -36,10 +36,13 @@ const executor = (
3636
resultOutputDir: string,
3737
progress: Progress,
3838
blacklist: string[],
39-
): void => {
39+
): Promise<boolean> => {
40+
validateTasks(repetitions, threads, job.main,);
41+
const resolver = {
42+
resolve(value: boolean) {}
43+
};
4044
const total = threads*repetitions;
4145
const now = new Date();
42-
validateTasks(repetitions, threads, job.main,);
4346
const results: {[z: string]: ResultSet} = {};
4447
const finished: {[z: string]: FinishedSet} = {};
4548
logger.debug(
@@ -61,6 +64,7 @@ const executor = (
6164
reportModifiers,
6265
resultHandler,
6366
resultOutputDir,
67+
resolver,
6468
),
6569
);
6670
const after = buildWorker(
@@ -114,6 +118,9 @@ const executor = (
114118
before.terminate();
115119
startMain();
116120
}
121+
return new Promise(resolve => {
122+
resolver.resolve = resolve;
123+
});
117124
};
118125

119126
export default executor;

src/load/loader.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@ const loadUp = async(config: Config,) => {
5050
} while (threads <= config.maximum);
5151
}
5252
defaultReporter(runs, config.cwd,);
53+
return true;
5354
};
5455
export default loadUp;

src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const run = async(
4848
repetitions = DEFAULT_REPETITIONS,
4949
job?: Job|Array<Task>|undefined,
5050
// eslint-disable-next-line max-params
51-
): Promise<void> => {
51+
): Promise<boolean> => {
5252
if (! configuration.cwd) {
5353
configuration.cwd = process.cwd();
5454
}
@@ -99,9 +99,9 @@ export const run = async(
9999
}
100100
if (configuration.mode === 'verify') {
101101
validateTasks(repetitions, threads, job.main,);
102-
return;
102+
return true;
103103
}
104-
executor(
104+
return executor(
105105
threads,
106106
repetitions,
107107
job,

src/messaging/calculator.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Thread from '../worker/thread.js';
88
import Counter from '../helper/counter.js';
99
import ReportModifier from '../report-modifier/report-modifier.js';
1010
import Reporter from '../reporter/reporter.js';
11+
import {CLOSE_WAIT_TIMEOUT} from "../constants.js";
1112

1213
const startResults = (
1314
logger: Logger,
@@ -16,6 +17,7 @@ const startResults = (
1617
reportModifiers: ReportModifier[],
1718
resultHandler: Reporter,
1819
resultOutputDir: string,
20+
resolver: {resolve(value: boolean,): void},
1921
// eslint-disable-next-line max-params
2022
): void => {
2123
if (! Counter.isEmpty('active',) || ! Counter.isEmpty('analyzing',)) {
@@ -24,13 +26,16 @@ const startResults = (
2426
calculator.terminate();
2527
logger.info(language('starting_result',),);
2628
logger.debug(language('data',), finished,);
29+
let hasErrors = false;
2730
for (const reportModifier of reportModifiers) {
2831
for (const set of Object.keys(finished,)) {
2932
finished[set] = reportModifier.adjust(finished[set],);
33+
hasErrors = hasErrors || finished[set].errors > 0;
3034
}
3135
}
3236
resultHandler(finished, resultOutputDir,);
3337
logger.info(language('done',),);
38+
setTimeout(() => resolver.resolve(hasErrors), CLOSE_WAIT_TIMEOUT,);
3439
};
3540
const onCalculate = (
3641
data: FinishedSet,
@@ -43,6 +48,7 @@ const onCalculate = (
4348
reportModifiers: ReportModifier[],
4449
reporter: Reporter,
4550
resultOutputDir: string,
51+
resolver: {resolve(value: boolean,): void},
4652
// eslint-disable-next-line max-params
4753
): void => {
4854
finished[data.id] = data;
@@ -57,6 +63,7 @@ const onCalculate = (
5763
reportModifiers,
5864
reporter,
5965
resultOutputDir,
66+
resolver,
6067
);
6168
};
6269
export default onCalculate;

src/reporter/default-reporter.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ import csvReporter from './csv-reporter.js';
33
import consoleReporter from './console-reporter.js';
44
import jsonReporter from './json-reporter.js';
55
import htmlReporter from './html-reporter.js';
6-
import internalReporter from './internal-reporter.js';
76
import xrayCloudReporter from './xray-cloud-reporter.js';
87
import xrayOnpremiseReporter from './xray-onpremise-reporter.js';
98

109
multiReporter.addReporter(csvReporter,);
1110
multiReporter.addReporter(consoleReporter,);
1211
multiReporter.addReporter(jsonReporter,);
1312
multiReporter.addReporter(htmlReporter,);
14-
multiReporter.addReporter(internalReporter,);
1513
multiReporter.addReporter(xrayCloudReporter,);
1614
multiReporter.addReporter(xrayOnpremiseReporter,);
1715

src/reporter/internal-reporter.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)