Skip to content

Commit

Permalink
test: Fail CDP commands on unhandled exceptions
Browse files Browse the repository at this point in the history
Install a Chrome Devtools Protocol handler for unhandled exceptions, and
fail the next CDP command with it.  This got lost with the move from
PhantomJS to Chrome.

Some of our tests rely on failed ph_* function invocations, so we must
not log failures of ph_wait_cond(); these  are also technically
unhandled exceptions. So turn this into a proper `PhWaitCondTimeout`
error class, so that it can be identified reliably.

Handle cases where undefined value is passed to fail/success in
cdp-driver.js.

Adjust the naughty override for the XTerm.js crash (cockpit-project#9641) as this now
shows the actual underlying crash instead of just the followup element
wait timeout.

Closes cockpit-project#9639

Cherry-picked from upstream master commit 9d3c17b, so that the
naughty overrides match correctly.
  • Loading branch information
martinpitt committed Jul 27, 2018
1 parent 8515134 commit 26556ed
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 19 deletions.
3 changes: 1 addition & 2 deletions bots/naughty/debian-stable/9641-xtermjs-dimensions-crash
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Traceback (most recent call last):
File "test/verify/check-machines", line *, in testSerialConsole
b.wait_not_present("div.terminal canvas.xterm-text-layer")
*
Error: timeout
RuntimeError: TypeError: Cannot read property 'dimensions' of undefined
3 changes: 1 addition & 2 deletions bots/naughty/debian-testing/9641-xtermjs-dimensions-crash
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Traceback (most recent call last):
File "test/verify/check-machines", line *, in testSerialConsole
b.wait_not_present("div.terminal canvas.xterm-text-layer")
*
Error: timeout
RuntimeError: TypeError: Cannot read property 'dimensions' of undefined
3 changes: 1 addition & 2 deletions bots/naughty/fedora-27/9641-xtermjs-dimensions-crash
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Traceback (most recent call last):
File "test/verify/check-machines", line *, in testSerialConsole
b.wait_not_present("div.terminal canvas.xterm-text-layer")
*
Error: timeout
RuntimeError: TypeError: Cannot read property 'dimensions' of undefined
3 changes: 1 addition & 2 deletions bots/naughty/fedora-28/9641-xtermjs-dimensions-crash
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Traceback (most recent call last):
File "test/verify/check-machines", line *, in testSerialConsole
b.wait_not_present("div.terminal canvas.xterm-text-layer")
*
Error: timeout
RuntimeError: TypeError: Cannot read property 'dimensions' of undefined
3 changes: 1 addition & 2 deletions bots/naughty/rhel-7/9641-xtermjs-dimensions-crash
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Traceback (most recent call last):
File "test/verify/check-machines", line *, in testSerialConsole
b.wait_not_present("div.terminal canvas.xterm-text-layer")
*
Error: timeout
RuntimeError: TypeError: Cannot read property 'dimensions' of undefined
3 changes: 1 addition & 2 deletions bots/naughty/rhel-x/9641-xtermjs-dimensions-crash
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Traceback (most recent call last):
File "test/verify/check-machines", line *, in testSerialConsole
b.wait_not_present("div.terminal canvas.xterm-text-layer")
*
Error: timeout
RuntimeError: TypeError: Cannot read property 'dimensions' of undefined
3 changes: 1 addition & 2 deletions bots/naughty/ubuntu-1604/9641-xtermjs-dimensions-crash
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Traceback (most recent call last):
File "test/verify/check-machines", line *, in testSerialConsole
b.wait_not_present("div.terminal canvas.xterm-text-layer")
*
Error: timeout
RuntimeError: TypeError: Cannot read property 'dimensions' of undefined
3 changes: 1 addition & 2 deletions bots/naughty/ubuntu-stable/9641-xtermjs-dimensions-crash
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Traceback (most recent call last):
File "test/verify/check-machines", line *, in testSerialConsole
b.wait_not_present("div.terminal canvas.xterm-text-layer")
*
Error: timeout
RuntimeError: TypeError: Cannot read property 'dimensions' of undefined
31 changes: 29 additions & 2 deletions test/common/cdp-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ function fatal() {
}

function fail(err) {
if (typeof err === 'undefined')
err = null;
process.stdout.write(JSON.stringify({"error": err}) + '\n');
}

function success(result) {
process.stdout.write(JSON.stringify({"result": result === undefined ? null : result}) + '\n');
if (typeof result === 'undefined')
result = null;
process.stdout.write(JSON.stringify({"result": result}) + '\n');
}

/**
Expand All @@ -61,6 +65,7 @@ function success(result) {
var messages = [];
var logPromiseResolver;
var nReportedLogMessages = 0;
var unhandledExceptions = [];

function setupLogging(client) {
client.Runtime.enable();
Expand All @@ -72,6 +77,16 @@ function setupLogging(client) {
resolveLogPromise();
});

client.Runtime.exceptionThrown(info => {
let details = info.exceptionDetails;
// don't log test timeouts, they already get handled
if (details.exception && details.exception.className === "PhWaitCondTimeout")
return;

unhandledExceptions.push(details)
process.stderr.write(details.description || JSON.stringify(details) + "\n");
});

client.Log.enable();
client.Log.entryAdded(entry => {
let msg = entry["entry"];
Expand Down Expand Up @@ -288,7 +303,19 @@ CDP.New(options)
pageLoadPromise = new Promise((resolve, reject) => { pageLoadResolve = resolve; pageLoadReject = reject; });

// run the command
eval(command).then(success, fail);
eval(command).then(reply => {
if (unhandledExceptions.length === 0) {
success(reply);
} else {
let details = unhandledExceptions[0];
let message = details.exception.message ||
details.exception.description ||
details.exception.value ||
JSON.stringify(details.exception);
fail(message.split("\n")[0]);
unhandledExceptions.length = 0;
}
}, fail);

input_buf = input_buf.slice(i+1);
}
Expand Down
8 changes: 7 additions & 1 deletion test/common/test-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ function ph_focus(sel)
ph_find(sel).focus();
}

class PhWaitCondTimeout extends Error {
constructor() {
super("condition did not become true");
}
}

function ph_wait_cond(cond, timeout) {
return new Promise((resolve, reject) => {
// poll every 100 ms for now; FIXME: poll less often and re-check on mutations using
Expand All @@ -192,7 +198,7 @@ function ph_wait_cond(cond, timeout) {
let tm = window.setTimeout( () => {
if (stepTimer)
window.clearTimeout(stepTimer);
reject("condition did not become true");
reject(new PhWaitCondTimeout());
}, timeout);
function step() {
try {
Expand Down

0 comments on commit 26556ed

Please sign in to comment.