Skip to content

Commit

Permalink
Rebase to master (update jasmine runners)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryAstafyev committed Sep 18, 2024
1 parent 6f6f78e commit 94d7357
Showing 1 changed file with 50 additions and 66 deletions.
116 changes: 50 additions & 66 deletions application/apps/rustcore/ts-bindings/spec/session.protocol.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
import { initLogger } from './logger';
initLogger();

import { finish, runner } from './common';
import { finish } from './common';
import { readConfigurationFile } from './config';
import { Session } from '../src/api/session';

import * as proto from 'protocol';
import * as $ from 'platform/types/observe';
import * as Types from '../src/protocol';
import * as runners from './runners';

const config = readConfigurationFile().get().tests.protocol;

describe('Protocol', function () {
it(config.regular.list[1], function () {
return runner(config.regular, 1, async (logger, done, collector) => {
return runners.noSession(config.regular, 1, async (logger, done) => {
{
let origin = Types.toObserveOptions({
origin: { File: ['somefile', $.Types.File.FileType.Text, 'path_to_file'] },
Expand Down Expand Up @@ -54,69 +54,53 @@ describe('Protocol', function () {
});
});
it(config.regular.list[2], function () {
return runner(config.regular, 2, async (logger, done, collector) => {
Session.create()
.then((session: Session) => {
// Set provider into debug mode
session.debug(true);
const MESSAGES_COUNT = 1000;
{
const meausere: { json: number; proto: number } = { json: 0, proto: 0 };
meausere.json = Date.now();
for (let i = MESSAGES_COUNT; i >= 0; i -= 1) {
const msg = session.getNativeSession().testGrabElsAsJson(false);
expect(msg instanceof Array).toBe(true);
}
meausere.json = Date.now() - meausere.json;
meausere.proto = Date.now();
for (let i = MESSAGES_COUNT; i >= 0; i -= 1) {
const msg = session.getNativeSession().testGrabElsAsProto(false);
expect(msg instanceof Array).toBe(true);
}
meausere.proto = Date.now() - meausere.proto;
console.log(
`Receiving messages (no decoding) count: ${MESSAGES_COUNT}\nJSON: ${
meausere.json
}ms (per msg ${(meausere.json / MESSAGES_COUNT).toFixed(2)});\nPROTO: ${
meausere.proto
}ms (per msg ${(meausere.proto / MESSAGES_COUNT).toFixed(2)})`,
);
}
{
const meausere: { json: number; proto: number } = { json: 0, proto: 0 };
meausere.json = Date.now();
for (let i = MESSAGES_COUNT; i >= 0; i -= 1) {
const msg = session.getNativeSession().testGrabElsAsJson();
expect(msg instanceof Array).toBe(true);
}
meausere.json = Date.now() - meausere.json;
meausere.proto = Date.now();
for (let i = MESSAGES_COUNT; i >= 0; i -= 1) {
const msg = session.getNativeSession().testGrabElsAsProto();
expect(msg instanceof Array).toBe(true);
}
meausere.proto = Date.now() - meausere.proto;
console.log(
`Grabbing messages (with decoding) count: ${MESSAGES_COUNT}\nJSON: ${
meausere.json
}ms (per msg ${(meausere.json / MESSAGES_COUNT).toFixed(2)});\nPROTO: ${
meausere.proto
}ms (per msg ${(meausere.proto / MESSAGES_COUNT).toFixed(2)})`,
);
}
finish(session, done);
})
.catch((err: Error) => {
finish(
undefined,
done,
new Error(
`Fail to create session due error: ${
err instanceof Error ? err.message : err
}`,
),
);
});
return runners.withSession(config.regular, 2, async (logger, done, comps) => {
const MESSAGES_COUNT = 1000;
{
const meausere: { json: number; proto: number } = { json: 0, proto: 0 };
meausere.json = Date.now();
for (let i = MESSAGES_COUNT; i >= 0; i -= 1) {
const msg = comps.session.getNativeSession().testGrabElsAsJson(false);
expect(msg instanceof Array).toBe(true);
}
meausere.json = Date.now() - meausere.json;
meausere.proto = Date.now();
for (let i = MESSAGES_COUNT; i >= 0; i -= 1) {
const msg = comps.session.getNativeSession().testGrabElsAsProto(false);
expect(msg instanceof Array).toBe(true);
}
meausere.proto = Date.now() - meausere.proto;
console.log(
`Receiving messages (no decoding) count: ${MESSAGES_COUNT}\nJSON: ${
meausere.json
}ms (per msg ${(meausere.json / MESSAGES_COUNT).toFixed(2)});\nPROTO: ${
meausere.proto
}ms (per msg ${(meausere.proto / MESSAGES_COUNT).toFixed(2)})`,
);
}
{
const meausere: { json: number; proto: number } = { json: 0, proto: 0 };
meausere.json = Date.now();
for (let i = MESSAGES_COUNT; i >= 0; i -= 1) {
const msg = comps.session.getNativeSession().testGrabElsAsJson();
expect(msg instanceof Array).toBe(true);
}
meausere.json = Date.now() - meausere.json;
meausere.proto = Date.now();
for (let i = MESSAGES_COUNT; i >= 0; i -= 1) {
const msg = comps.session.getNativeSession().testGrabElsAsProto();
expect(msg instanceof Array).toBe(true);
}
meausere.proto = Date.now() - meausere.proto;
console.log(
`Grabbing messages (with decoding) count: ${MESSAGES_COUNT}\nJSON: ${
meausere.json
}ms (per msg ${(meausere.json / MESSAGES_COUNT).toFixed(2)});\nPROTO: ${
meausere.proto
}ms (per msg ${(meausere.proto / MESSAGES_COUNT).toFixed(2)})`,
);
}
finish(comps.session, done);
});
});
});

0 comments on commit 94d7357

Please sign in to comment.