Better way to wait inbetween tests

Jessica B. Hamrick 12 years ago
parent fe2402f99d
commit f2ad4fc176

@ -76,16 +76,8 @@ casper.notebook_test(function () {
this.thenEvaluate(function () {
IPython.notebook.kernel.restart();
});
this.waitFor(function () {
return this.evaluate(function () {
return IPython.notebook.kernel.is_fully_disconnected();
});
});
this.waitFor(function () {
return this.evaluate(function () {
return IPython.notebook.kernel.is_connected();
});
});
this.waitFor(this.kernel_disconnected);
this.wait_for_kernel_ready();
this.then(function () {
this.test.assert(this.kernel_running(), 'kernel restarted');
});
@ -94,19 +86,11 @@ casper.notebook_test(function () {
this.thenEvaluate(function () {
IPython.notebook.kernel.stop_channels();
});
this.waitFor(function () {
return this.evaluate(function () {
return IPython.notebook.kernel.is_fully_disconnected();
});
});
this.waitFor(this.kernel_disconnected);
this.thenEvaluate(function () {
IPython.notebook.kernel.reconnect();
});
this.waitFor(function () {
return this.evaluate(function () {
return IPython.notebook.kernel.is_connected();
});
});
this.wait_for_kernel_ready();
this.then(function () {
this.test.assert(this.kernel_running(), 'kernel reconnected');
});
@ -136,11 +120,7 @@ casper.notebook_test(function () {
this.thenEvaluate(function () {
IPython.notebook.kernel.kill();
});
this.waitFor(function () {
return this.evaluate(function () {
return IPython.notebook.kernel.is_fully_disconnected();
});
});
this.waitFor(this.kernel_disconnected);
this.then(function () {
this.test.assert(!this.kernel_running(), 'kernel is not running');
});
@ -155,11 +135,7 @@ casper.notebook_test(function () {
this.then(function () {
this.test.assertEquals(url, "/api/kernels", "start url is correct");
});
this.waitFor(function () {
return this.evaluate(function () {
return IPython.notebook.kernel.is_connected();
});
});
this.wait_for_kernel_ready();
this.then(function () {
this.test.assert(this.kernel_running(), 'kernel is running');
});
@ -168,11 +144,7 @@ casper.notebook_test(function () {
this.thenEvaluate(function () {
IPython.notebook.kernel.kill();
});
this.waitFor(function () {
return this.evaluate(function () {
return IPython.notebook.kernel.is_fully_disconnected();
});
});
this.waitFor(this.kernel_disconnected);
this.then(function () {
url = this.evaluate(function () {
return IPython.notebook.kernel.start({foo: "bar"});
@ -181,16 +153,10 @@ casper.notebook_test(function () {
this.then(function () {
this.test.assertEquals(url, "/api/kernels?foo=bar", "start url with params is correct");
});
this.waitFor(function () {
return this.evaluate(function () {
return IPython.notebook.kernel.is_connected();
});
});
this.wait_for_kernel_ready();
this.then(function () {
this.test.assert(this.kernel_running(), 'kernel is running');
});
// wait for any last idle/busy messages to be handled
this.wait(1000);
// check for events in kill/start cycle
this.event_test(
@ -213,7 +179,7 @@ casper.notebook_test(function () {
}
);
// wait for any last idle/busy messages to be handled
this.wait(500);
this.wait_for_kernel_ready();
// check for events in disconnect/connect cycle
this.event_test(
@ -221,8 +187,6 @@ casper.notebook_test(function () {
[
'status_reconnecting.Kernel',
'status_connected.Kernel',
'status_busy.Kernel',
'status_idle.Kernel'
],
function () {
this.thenEvaluate(function () {
@ -232,7 +196,7 @@ casper.notebook_test(function () {
}
);
// wait for any last idle/busy messages to be handled
this.wait(500);
this.wait_for_kernel_ready();
// check for events in the restart cycle
this.event_test(
@ -251,7 +215,7 @@ casper.notebook_test(function () {
}
);
// wait for any last idle/busy messages to be handled
this.wait(500);
this.wait_for_kernel_ready();
// TODO: test for failed restart, that it triggers
// kernel_dead.Kernel? How to do this?
@ -273,6 +237,7 @@ casper.notebook_test(function () {
});
}
);
this.wait_for_kernel_ready();
// check for events after ws close
this.event_test(
@ -291,7 +256,7 @@ casper.notebook_test(function () {
}
);
// wait for any last idle/busy messages to be handled
this.wait(500);
this.wait_for_kernel_ready();
// check for events after ws close (error)
this.event_test(
@ -306,6 +271,4 @@ casper.notebook_test(function () {
});
}
);
// wait for any last idle/busy messages to be handled
this.wait(500);
});

@ -89,11 +89,7 @@ casper.notebook_test(function () {
this.thenEvaluate(function () {
IPython.notebook.session.delete();
});
this.waitFor(function () {
return this.evaluate(function () {
return IPython.notebook.kernel.is_fully_disconnected();
});
});
this.waitFor(this.kernel_disconnected);
this.then(function () {
this.test.assert(!this.kernel_running(), 'session deletes kernel');
});
@ -113,7 +109,7 @@ casper.notebook_test(function () {
});
}
);
this.wait(500);
this.wait_for_kernel_ready();
// check for events when killing the session
this.event_test(
@ -125,7 +121,6 @@ casper.notebook_test(function () {
});
}
);
this.wait(500);
// check for events when restarting the session
this.event_test(
@ -143,7 +138,7 @@ casper.notebook_test(function () {
});
}
);
this.wait(500);
this.wait_for_kernel_ready();
// check for events when starting a nonexistant kernel
this.event_test(

@ -68,6 +68,22 @@ casper.kernel_disconnected = function() {
});
};
casper.wait_for_kernel_ready = function () {
this.waitFor(this.kernel_running);
this.thenEvaluate(function () {
IPython._kernel_ready = false;
IPython.notebook.kernel.kernel_info(
function () {
IPython._kernel_ready = true;
});
});
this.waitFor(function () {
return this.evaluate(function () {
return IPython._kernel_ready;
});
});
};
casper.shutdown_current_kernel = function () {
// Shut down the current notebook's kernel.
this.thenEvaluate(function() {

Loading…
Cancel
Save