Skip to content

Commit

Permalink
fix: Fix multiple iterations timeout bug
Browse files Browse the repository at this point in the history
  • Loading branch information
virgs committed Apr 2, 2019
1 parent 8cff56b commit 039f7c1
Show file tree
Hide file tree
Showing 15 changed files with 1,357 additions and 1,334 deletions.
1,300 changes: 650 additions & 650 deletions output/examples.json

Large diffs are not rendered by default.

1,296 changes: 648 additions & 648 deletions output/examples.yml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"commander": "^2.19.0",
"express": "^4.16.4",
"glob": "^7.1.3",
"json-placeholder-replacer": "^1.0.31",
"json-placeholder-replacer": "^1.0.32",
"log4js": "^4.0.2",
"prettyjson": "^1.2.1",
"request": "^2.88.0",
Expand Down
7 changes: 5 additions & 2 deletions src/code-generators/assertion-code-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {AssertionCodeGenerator} from './assertion-code-generator';
describe('AssertionCodeGenerator', () => {

it('Should pass tests instance name', () => {
const assertionCodeGenerator: AssertionCodeGenerator = new AssertionCodeGenerator('tests', 'asserter', 'assertion');
const assertionCodeGenerator: AssertionCodeGenerator =
new AssertionCodeGenerator('tests', 'asserter', 'assertion');
const code: string = assertionCodeGenerator.generate();

expect(code).toBe('try {\n' +
Expand All @@ -13,8 +14,10 @@ describe('AssertionCodeGenerator', () => {
' .forEach(key => evaluated[key] = eval(assertion[key]) );\n' +
' tests.push(asserter.assert(evaluated, assertion));\n' +
' } catch (err) {\n' +
" const msg = `Error executing assertion: '${err}'`;\n" +
' Logger.error(msg);\n' +
' tests.push({\n' +
" description: `Error executing assertion: '${err}'`,\n" +
' description: msg,\n' +
' valid: false,\n' +
" label: 'Assertion code valid'\n" +
' });\n' +
Expand Down
5 changes: 3 additions & 2 deletions src/code-generators/assertion-code-generator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export class AssertionCodeGenerator {
private readonly testsName: string;
private readonly assertionName: string;
Expand All @@ -18,8 +17,10 @@ export class AssertionCodeGenerator {
.forEach(key => evaluated[key] = eval(${this.assertionName}[key]) );
${this.testsName}.push(${this.asserterInstanceName}.assert(evaluated, ${this.assertionName}));
} catch (err) {
const msg = \`Error executing assertion: '\${err}'\`;
Logger.error(msg);
${this.testsName}.push({
description: \`Error executing assertion: '\${err}'\`,
description: msg,
valid: false,
label: 'Assertion code valid'
});
Expand Down
6 changes: 5 additions & 1 deletion src/code-generators/event-code-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class EventCodeGenerator {

dynamicFunction.addArgument(this.storeInstanceName, Store.getData());
dynamicFunction.addArgument(this.testsInstanceName, this.tests);
dynamicFunction.addArgument('Logger', Logger);

functionArguments.forEach(argument => {
dynamicFunction.addArgument(argument.name, argument.value);
Expand All @@ -55,8 +56,10 @@ export class EventCodeGenerator {
return `try {
${this.script}
} catch (err) {
const msg = \`Error executing '${this.name}.script' code: '\${err}'\`;
Logger.error(msg);
${this.testsInstanceName}.push({
description: \`Error executing '${this.name}.script' code: '\${err}'\`,
description: msg,
valid: false,
label: "Valid 'script snippet' code"
});
Expand All @@ -79,6 +82,7 @@ export class EventCodeGenerator {
dynamicFunction.addArgument(this.storeInstanceName, Store.getData());
dynamicFunction.addArgument(this.testsInstanceName, this.tests);
dynamicFunction.addArgument('assertion', assertion);
dynamicFunction.addArgument('Logger', Logger);

functionArguments.forEach(argument => {
dynamicFunction.addArgument(argument.name, argument.value);
Expand Down
12 changes: 8 additions & 4 deletions src/code-generators/store-code-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@ describe('StoreCodeGenerator', () => {
expect(code).toBe('try {\n' +
' storeName[\'first\'] = firstValue;\n' +
' } catch (err) {\n' +
' const msg = `Error executing store \'first\' code: \'${err}\'`;\n' +
' Logger.error(msg);\n' +
' tests.push({\n' +
' description: `Error executing store \'first\' code: \'${err}\'`,\n' +
' description: msg,\n' +
' valid: false,\n' +
' label: \"Valid \'store\' in event auto-generated code\"\n' +
' label: \"Valid \'store\' in event code\"\n' +
' });\n' +
' }\n' +
'try {\n' +
' storeName[\'second\'] = secondValue;\n' +
' } catch (err) {\n' +
' const msg = `Error executing store \'second\' code: \'${err}\'`;\n' +
' Logger.error(msg);\n' +
' tests.push({\n' +
' description: `Error executing store \'second\' code: \'${err}\'`,\n' +
' description: msg,\n' +
' valid: false,\n' +
' label: \"Valid \'store\' in event auto-generated code\"\n' +
' label: \"Valid \'store\' in event code\"\n' +
' });\n' +
' }\n');
});
Expand Down
6 changes: 4 additions & 2 deletions src/code-generators/store-code-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ export class StoreCodeGenerator {
code += `try {
${this.storeInstanceName}['${key}'] = ${store[key]};
} catch (err) {
const msg = \`Error executing store '${key}' code: '\${err}'\`;
Logger.error(msg);
${this.testsName}.push({
description: \`Error executing store '${key}' code: '\${err}'\`,
description: msg,
valid: false,
label: "Valid 'store' in event auto-generated code"
label: "Valid 'store' in event code"
});
}\n`;

Expand Down
8 changes: 8 additions & 0 deletions src/configurations/file-content-map-creator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ describe('FileContentMapCreator', () => {
expect(readFileSyncMock).toHaveBeenCalledWith(filename);
});

it('Handle exceptions undefined field', () => {
const requisition = {value: undefined};

// @ts-ignore
expect(() => new FileContentMapCreator(requisition)).not.toThrow();

});

it('Parse from file with right parser', () => {
const fileContent = 'fileContent';
const readFileSyncMock = jest.fn(() => fileContent);
Expand Down
4 changes: 2 additions & 2 deletions src/configurations/file-content-map-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class FileContentMapCreator {
const attribute = node[key];
if (typeof attribute === 'object') {
this.checkChildren(attribute);
} else {
} else if (attribute !== undefined) {
this.findTags(JSON.stringify(attribute));
}
}
Expand Down Expand Up @@ -76,7 +76,7 @@ export class FileContentMapCreator {
for (let i = 0; i < pairs.length; i++) {
const pair = pairs[i].split('=');
let value: any = pair[1];
if (value === undefined) {
if (value === undefined) {
value = true;
}
query[pair[0]] = value;
Expand Down
1 change: 1 addition & 0 deletions src/enqueuer-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class EnqueuerRunner {
}

public async execute(): Promise<boolean> {
Logger.info('Let\'s rock');
const configuration = Configuration.getInstance();
const requisitionFileParser = new RequisitionFilePatternParser(configuration.getFiles());
const requisitions = requisitionFileParser.parse();
Expand Down
19 changes: 10 additions & 9 deletions src/reporters/publishers/multi-publishers-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ export class MultiPublishersReporter {
let errorsCounter = 0;
if (this.publishers.length > 0) {
Logger.info(`Publishers are publishing messages`);

await Promise.all(this.publishers.map(async publisher => {
try {
await publisher.publish();
} catch (err) {
++errorsCounter;
Logger.error(err);
}
}));
Logger.info(`Publishers have published their messages`);
}
await Promise.all(this.publishers.map(async publisher => {
try {
await publisher.publish();
} catch (err) {
++errorsCounter;
Logger.error(err);
}
}));
Logger.info(`Publishers have published their messages`);
return errorsCounter;
}

Expand Down
7 changes: 3 additions & 4 deletions src/reporters/requisition-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ export class RequisitionReporter {
this.requisitionAttributes = requisitionAttributes;
const onInitFunctionTests = this.executeOnInitFunction();
if (this.requisitionAttributes.timeout === undefined) {
this.requisitionAttributes.timeout = RequisitionReporter.DEFAULT_TIMEOUT;
} else if (this.requisitionAttributes.timeout <= 0) {
delete this.requisitionAttributes.timeout;
this.timeout = RequisitionReporter.DEFAULT_TIMEOUT;
} else if (this.requisitionAttributes.timeout > 0) {
this.timeout = this.requisitionAttributes.timeout;
}
this.startTime = new Date();
this.timeout = this.requisitionAttributes.timeout;
this.reportGenerator = new RequisitionReportGenerator(this.requisitionAttributes, this.timeout);
this.reportGenerator.addTests(onInitFunctionTests);
this.multiSubscriptionsReporter = new MultiSubscriptionsReporter(this.requisitionAttributes.subscriptions);
Expand Down
12 changes: 6 additions & 6 deletions src/reporters/subscription/subscription-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ export class SubscriptionReporter {
};

this.executeOnInitFunction(subscriptionAttributes);
if (subscriptionAttributes.timeout === undefined) {
subscriptionAttributes.timeout = SubscriptionReporter.DEFAULT_TIMEOUT;
} else if (subscriptionAttributes.timeout <= 0) {
delete subscriptionAttributes.timeout;
}

Logger.debug(`Instantiating subscription ${subscriptionAttributes.type}`);
this.subscription = DynamicModulesManager.getInstance().getProtocolManager().createSubscription(subscriptionAttributes);
if (subscriptionAttributes.timeout === undefined) {
this.subscription.timeout = SubscriptionReporter.DEFAULT_TIMEOUT;
} else if (subscriptionAttributes.timeout <= 0) {
delete this.subscription.timeout;
}
this.killListener = (signal: Signals) => this.handleKillSignal(signal, this.subscription.type || 'undefined');
}

Expand All @@ -57,7 +57,7 @@ export class SubscriptionReporter {

public startTimeout(onTimeOutCallback: Function) {
if (this.subscription.timeout) {
Logger.info(`Starting subscription '${this.subscription.name}'`);
Logger.info(`Starting subscription '${this.subscription.name}' timeout`);
new Timeout(() => {
if (!this.subscription.messageReceived) {
this.totalTime = new DateController();
Expand Down

0 comments on commit 039f7c1

Please sign in to comment.