nope/test/testAmqpClient.ts

60 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-09-30 06:25:03 +00:00
import 'reflect-metadata';
import { AmqpLayer, } from "../lib/communication/amqpLayer";
import { nopeDispatcher } from "../lib/dispatcher/nopeDispatcher";
import { promisify } from 'util'
import { getLogger } from "../lib/logger/getLogger";
import { nopeObservable } from "../lib/observables/nopeObservable";
const client = new AmqpLayer('localhost');
const sleep = promisify(setTimeout)
const logger = getLogger('info','DISPATCHER')
const main = async () => {
let max = 10000;
await sleep(1000);
const dispatcher = new nopeDispatcher({ communicator: client, logger }, () => new nopeObservable());
await sleep(500);
let c = 0
// Call Tasks Parallel!
while (c < 10) {
dispatcher.performCall('func', [c++]).catch(e => console.error(e));
}
// Benchmark:
c = 0
// Call Tasks Parallel!
while (c < max) {
await dispatcher.performCall('benchmark', [], {
paramsHasNoCallback: true,
});
c++;
}
await sleep(500);
const obs01 = new nopeObservable<number>();
dispatcher.registerObservable(obs01, {
mode: 'publish',
topic: 'test.var'
});
obs01.setContent(1200);
await sleep(500);
c = 0;
while (c < max) {
obs01.setContent(c++);
}
c = 0;
while(c < max){
await client.emit('publish','benchmark', c++);
}
}
main();