Skip to content

Commit c794bde

Browse files
committed
OI-1098 Unable to stop test while on a breakpoint
1 parent 716ce0b commit c794bde

File tree

6 files changed

+140
-34
lines changed

6 files changed

+140
-34
lines changed

src/core/OxygenCore.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,14 +592,19 @@ export default class Oxygen extends OxygenEvents {
592592
this._waitStepResultList.push(waitId);
593593

594594
stepResult = this._getStepResult(module, moduleName, cmdName, cmdArgs, cmdLocation, startTime, endTime, retval, error);
595+
// this.emitAfterCommand(cmdName, moduleName, cmdFn, cmdArgs, this.ctx, cmdLocation, endTime, stepResult);
595596

596597
const index = this._waitStepResultList.indexOf(waitId);
597598
this._waitStepResultList.splice(index, 1);
598599

599600
//stepResult.location = cmdLocation;
600601

601602
this.resultStore.steps.push(stepResult);
602-
this.emitAfterCommand(cmdName, moduleName, cmdFn, cmdArgs, this.ctx, cmdLocation, endTime, stepResult);
603+
604+
// console.log('~~before sleep');
605+
// deasync.sleep(1000*10);
606+
// console.log('~~after sleep');
607+
603608
done = true;
604609
}
605610

src/lib/util.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ var self = module.exports = {
247247
},
248248

249249
executeTestHook: async function(hooks, method, args) {
250+
console.log('~~hooks', hooks);
250251
// if hook is not defined, just quietly ignore it
251252
if (!hooks || !method || !hooks[method] || typeof hooks[method] !== 'function') {
252253
return null;

src/runners/WorkerProcess.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,40 @@ export default class WorkerProcess extends EventEmitter {
114114
}
115115

116116
async stop(status = null) {
117+
console.log('~~ this._worker.stop start');
117118
if (this._isInitialized && this._childProc) {
119+
console.log('~~ if');
118120
if (this._debugger && this._debugger._paused) {
121+
console.log('~~ if this._debugger._paused resumeTerminate before');
119122
await this._debugger.resumeTerminate();
123+
console.log('~~ if this._debugger._paused resumeTerminate after');
120124
}
125+
console.log('~~ if invoke dispose before');
121126
await this.invoke('dispose', status);
127+
console.log('~~ if invoke dispose after');
128+
console.log('~~ if snooze before');
122129
await snooze(100);
130+
console.log('~~ if snooze after');
123131
} else if (this._childProc) {
132+
console.log('~~ else if');
124133
await snooze(100);
125134
}
126135
if (this._debugger) {
136+
console.log('~~ after if');
127137
await this._debugger.close();
128138
}
129139

140+
console.log('~~ before send');
130141
this._send({
131142
type: 'exit',
132143
status: status,
133144
});
145+
console.log('~~ before kill');
146+
console.log('~~ after send');
134147
this._childProc.kill('SIGINT');
148+
console.log('~~ after kill');
135149
this._reset();
150+
console.log('~~ this._worker.stop end');
136151
}
137152

138153
kill() {
@@ -222,19 +237,42 @@ export default class WorkerProcess extends EventEmitter {
222237
}
223238
if (this._childProc) {
224239
const callId = oxutil.generateUniqueId();
240+
241+
console.log('~~callId', callId);
242+
console.log('~~method', method);
243+
console.log('~~args', args);
244+
245+
if (method === 'dispose' && args[0] === 'CANCELED' && this.runDefer && this.runDeferCallId) {
246+
this.runDefer.resolve(null);
247+
delete this._calls[this.runDeferCallId];
248+
}
249+
225250
this._send({
226251
type: 'invoke',
227252
method: method,
228253
callId: callId,
229254
args: args
230255
});
231256
this._calls[callId] = defer();
257+
258+
if (method === 'run') {
259+
this.runDefer = this._calls[callId];
260+
this.runDeferCallId = callId;
261+
}
262+
263+
console.log('~~this._calls', this._calls);
264+
232265
return this._calls[callId].promise;
233266
}
234267
}
235268

236269
async invokeTestHook(hookName, hookArgs) {
237270
const callId = oxutil.generateUniqueId();
271+
272+
console.log('~~callId', callId);
273+
console.log('~~hookName', hookName);
274+
console.log('~~hookArgs', hookArgs);
275+
238276
this._send({
239277
type: 'invoke:hook',
240278
method: hookName,
@@ -281,15 +319,21 @@ export default class WorkerProcess extends EventEmitter {
281319
if (msg.event) {
282320
switch (msg.event) {
283321
case 'invoke:result':
322+
console.log('invoke:result msg', msg);
284323
if (msg.callId && Object.prototype.hasOwnProperty.call(this._calls, msg.callId)) {
285324
const promise = this._calls[msg.callId];
325+
console.log('~~promise', promise);
286326
if (msg.error) {
287327
promise.reject(msg.error);
288328
}
289329
else {
290-
promise.resolve(msg.retval);
330+
console.log('~~promise resolve msg.retval', msg.retval);
331+
console.log('~~promise resolve msg.retval || null', msg.retval || null);
332+
promise.resolve(msg.retval || null);
291333
}
334+
console.log('~~this._calls before', this._calls);
292335
delete this._calls[msg.callId];
336+
console.log('~~this._calls after', this._calls);
293337
}
294338
break;
295339
case 'reporter':

src/runners/oxygen/OxygenWorker.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,17 @@ export default class OxygenWorker extends EventEmitter {
159159
}
160160

161161
async callTestHook(hookName, hookArgs) {
162+
console.log('~~callTestHook start');
162163
if (!this._testHooks || !this._testHooks[hookName] || typeof this._testHooks[hookName] !== 'function') {
163164
throw new Error(`Hook does not exist: ${hookName}`);
164165
}
166+
console.log('~~oxutil.executeTestHook start');
167+
console.log('~~oxutil.executeTestHook this._testHooks', this._testHooks);
168+
console.log('~~oxutil.executeTestHook hookName', hookName);
169+
console.log('~~oxutil.executeTestHook hookArgs', hookArgs);
165170
await oxutil.executeTestHook(this._testHooks, hookName, hookArgs);
171+
console.log('~~oxutil.executeTestHook end');
172+
console.log('~~callTestHook end');
166173
}
167174

168175
async _runFnInFiberContext (fn) {

src/runners/oxygen/index.js

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,14 @@ export default class OxygenRunner extends EventEmitter {
184184
}
185185

186186
async dispose(status = null) {
187+
console.log('~~ runner dispose status', status);
187188
this._isDisposing = true;
188189
try {
189190
if (this._worker && this._worker.isRunning) {
191+
console.log('~~this._worker.isRunning', this._worker.isRunning);
192+
console.log('~~ this._worker.stop before');
190193
await this._worker.stop(status);
194+
console.log('~~ this._worker.stop after');
191195
}
192196
} catch (e) {
193197
console.log('runner dispose e', e);
@@ -224,8 +228,12 @@ export default class OxygenRunner extends EventEmitter {
224228
error = result.failure;
225229
}
226230

227-
this._reporter.onRunnerEnd(this._id, result, error);
228-
this._isRunning = false;
231+
if (this._worker._stoppedByUser) {
232+
// ignore, not need this
233+
} else {
234+
this._reporter.onRunnerEnd(this._id, result, error);
235+
this._isRunning = false;
236+
}
229237
if (error) {
230238
throw error;
231239
}
@@ -362,7 +370,11 @@ export default class OxygenRunner extends EventEmitter {
362370
result.failure = errorHelper.getFailureFromError(error);
363371
result.status = Status.FAILED;
364372
}
365-
await this._worker_callAfterTestHook(result);
373+
if (this._worker._stoppedByUser) {
374+
// ignore, not need this
375+
} else {
376+
await this._worker_callAfterTestHook(result);
377+
}
366378
return result;
367379
}
368380

@@ -452,12 +464,18 @@ export default class OxygenRunner extends EventEmitter {
452464
suiteResult.endTime = oxutil.getTimeStamp();
453465
suiteResult.duration = suiteResult.endTime - suiteResult.startTime;
454466

455-
if (showSuiteIterationsMessages) {
456-
this._reporter.onIterationEnd(this._id, suiteResult, 'Suite');
457-
}
467+
console.log('~~this._worker.stoppedByUser', this._worker._stoppedByUser);
458468

459-
await this._worker_callAfterSuiteHook(suite, suiteResult);
460-
this._reporter.onSuiteEnd(this._id, suite.uri, suiteResult);
469+
if (this._worker._stoppedByUser) {
470+
// ignore, not need this
471+
} else {
472+
if (showSuiteIterationsMessages) {
473+
this._reporter.onIterationEnd(this._id, suiteResult, 'Suite');
474+
}
475+
476+
await this._worker_callAfterSuiteHook(suite, suiteResult);
477+
this._reporter.onSuiteEnd(this._id, suite.uri, suiteResult);
478+
}
461479
}
462480
return suiteIterations;
463481
}
@@ -517,21 +535,27 @@ export default class OxygenRunner extends EventEmitter {
517535
try {
518536
caseResult.startTime = oxutil.getTimeStamp();
519537
if (this._worker) {
520-
const { resultStore, context, moduleCaps, error } = await this._worker_Run(suite, caze, suiteIteration, caseIteration, params);
521-
this._processTestResults({ resultStore, context, error, moduleCaps });
522-
caseResult.endTime = oxutil.getTimeStamp();
523-
caseResult.duration = caseResult.endTime - caseResult.startTime;
524-
caseResult.context = context;
525-
caseResult.steps = resultStore && resultStore.steps ? resultStore.steps : [];
526-
caseResult.logs = resultStore && resultStore.logs ? resultStore.logs : [];
527-
caseResult.har = resultStore && resultStore.har ? resultStore.har : null;
528-
529-
// determine test case iteration status - mark it as failed if any step has failed
530-
var failedSteps = _.find(caseResult.steps, {status: Status.FAILED});
531-
caseResult.status = _.isEmpty(failedSteps) && !error ? Status.PASSED : Status.FAILED;
532-
if (error) {
533-
caseResult.failure = error;
534-
caseResult.status = Status.FAILED;
538+
const workerRunResult = await this._worker_Run(suite, caze, suiteIteration, caseIteration, params);
539+
console.log('~~workerRunResult', workerRunResult);
540+
if (workerRunResult) {
541+
const { resultStore, context, moduleCaps, error } = workerRunResult;
542+
this._processTestResults({ resultStore, context, error, moduleCaps });
543+
caseResult.endTime = oxutil.getTimeStamp();
544+
caseResult.duration = caseResult.endTime - caseResult.startTime;
545+
caseResult.context = context;
546+
caseResult.steps = resultStore && resultStore.steps ? resultStore.steps : [];
547+
caseResult.logs = resultStore && resultStore.logs ? resultStore.logs : [];
548+
caseResult.har = resultStore && resultStore.har ? resultStore.har : null;
549+
// determine test case iteration status - mark it as failed if any step has failed
550+
var failedSteps = _.find(caseResult.steps, {status: Status.FAILED});
551+
caseResult.status = _.isEmpty(failedSteps) && !error ? Status.PASSED : Status.FAILED;
552+
if (error) {
553+
caseResult.failure = error;
554+
caseResult.status = Status.FAILED;
555+
}
556+
} else {
557+
// test canceled
558+
return;
535559
}
536560
} else {
537561
return;
@@ -655,6 +679,7 @@ export default class OxygenRunner extends EventEmitter {
655679

656680
async _startWorkerProcess() {
657681
const workerPath = path.join(__dirname, 'worker.js');
682+
console.log('~~workerPath', workerPath);
658683
this._worker = new WorkerProcess(this._id, workerPath, this._debugMode, this._debugPort, 'Oxygen', this._npmGRootExecution);
659684
await this._worker.start();
660685
this._hookWorkerEvents();
@@ -767,7 +792,11 @@ export default class OxygenRunner extends EventEmitter {
767792
if (e && e.module && e.module === 'log') {
768793
// ignore
769794
} else {
770-
await (this._worker && this._worker.invokeTestHook('afterCommand', [e.result]));
795+
console.log('~~afterCommand before', e.result);
796+
if (this._worker) {
797+
await this._worker.invokeTestHook('afterCommand', [e.result]);
798+
}
799+
console.log('~~afterCommand after');
771800
}
772801
}
773802
catch (e) {

src/runners/oxygen/worker.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,33 @@ process.on('SIGINT', async function() {
9696
await dispose('CANCELED');
9797
});
9898

99-
process.on('message', async function (msg) {
99+
process.on('message', function (msg) {
100+
101+
console.log('~~msg', msg);
102+
100103
if (!msg.type) {
101104
return;
102105
}
103106
if ((msg.type === 'invoke' || msg.type === 'invoke:hook') && msg.method) {
104107
const { callId, method, args } = msg;
105108
const invokeFunc = msg.type === 'invoke:hook' ? invokeTestHook : invoke;
106-
const { retval, error } = await invokeFunc(method, args);
107-
processSend({
108-
event: 'invoke:result',
109-
method: method,
110-
callId: callId,
111-
error: error,
112-
retval: retval
109+
110+
console.log('~~method', method);
111+
console.log('~~args', args);
112+
113+
invokeFunc(method, args).then((rv) => {
114+
console.log('~~invokeFunc rv', rv);
115+
const { retval, error } = rv;
116+
console.log('~~invokeFunc retval', retval);
117+
console.log('~~invokeFunc error', error);
118+
119+
processSend({
120+
event: 'invoke:result',
121+
method: method,
122+
callId: callId,
123+
error: error,
124+
retval: retval
125+
});
113126
});
114127
}
115128
else if (msg.type === 'subscribe') {
@@ -118,12 +131,19 @@ process.on('message', async function (msg) {
118131
});
119132

120133
async function dispose(status= null) {
134+
135+
console.log('~~ worker dispose', status);
136+
console.log('~~ worker dispose !!_worker', !!_worker);
137+
121138
if (_worker) {
122139
try {
140+
console.log('~~ _worker.dispose before');
123141
await _worker.dispose(status);
142+
console.log('~~ _worker.dispose after');
124143
}
125144
catch (e) {
126145
// ignore
146+
console.log('~~ worker dispose e', e);
127147
}
128148
}
129149
}

0 commit comments

Comments
 (0)