Skip to content

Commit

Permalink
fix: user cancelation stops execution hook #98
Browse files Browse the repository at this point in the history
  • Loading branch information
AnWeber committed Nov 6, 2021
1 parent dcc5c0a commit fd720bd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/parser/cancelExecutionInterceptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { log } from '../io';
import * as models from '../models';

export function registerCancelExecutionIntercepter(parserContext: models.ParserContext) {

parserContext.httpRegion.hooks.execute.addInterceptor({
beforeLoop: async function checkUserCancelation(context: models.HookTriggerContext<models.ProcessorContext, boolean>) {
if (context.arg.progress?.isCanceled?.()) {
log.trace('processs canceled by user');
return false;
}
return true;
}
});


}
4 changes: 3 additions & 1 deletion src/parser/initHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { parseMQTTLine } from './mqtttHttpRegionParser';

import { injectOnEveryRequestJavascript } from './javascriptHttpRegionParser';
import { injectNote } from './noteMetaHttpRegionParser';
import { registerCancelExecutionIntercepter } from './cancelExecutionInterceptor';


export enum ParserId {
Expand Down Expand Up @@ -67,8 +68,9 @@ export function initParseHook(): models.ParseHook {
export function initParseEndHook(): models.ParseEndRegionHook {
const hook = new models.ParseEndRegionHook();

hook.addHook(ParserId.javascript, injectOnEveryRequestJavascript);
hook.addHook('registerCancelExecutionIntercepter', registerCancelExecutionIntercepter);
hook.addHook(ParserId.note, injectNote);
hook.addHook(ParserId.javascript, injectOnEveryRequestJavascript);
hook.addHook(ParserId.response, closeResponseBody);
hook.addHook(ParserId.requestBody, closeRequestBody);

Expand Down
5 changes: 5 additions & 0 deletions src/utils/variableUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { toAbsoluteFilename } from './fsUtils';
import { isString } from './stringUtils';
import * as io from '../io';
import { toEnvironmentKey } from './environmentUtils';
import { log } from '../io';

export function expandVariables(variables: models.Variables) : models.Variables {
for (const [key, value] of Object.entries(variables)) {
Expand Down Expand Up @@ -33,6 +34,10 @@ export async function replaceVariables(
type: models.VariableType | string,
context: models.ProcessorContext
): Promise<typeof models.HookCancel | unknown> {
if (context.progress?.isCanceled?.()) {
log.trace('processs canceled by user');
return models.HookCancel;
}
let start;
let result = text;
while (start !== result) {
Expand Down

0 comments on commit fd720bd

Please sign in to comment.