JS: close WebSockets when killing kernels

by calling Kernel.stop_channels() in Session.delete and Kernel.kill
This commit is contained in:
MinRK 2014-08-13 14:21:14 -07:00
parent 865fb20c00
commit e3696996be
4 changed files with 84 additions and 3 deletions

View File

@ -394,6 +394,7 @@ define([
error : utils.log_ajax_error,
};
$.ajax(utils.url_join_encode(this.kernel_url), settings);
this.stop_channels();
}
};

View File

@ -80,6 +80,7 @@ define([
error : utils.log_ajax_error,
};
this.kernel.running = false;
this.kernel.stop_channels();
var url = utils.url_join_encode(this.base_url, 'api/sessions', this.id);
$.ajax(url, settings);
};

View File

@ -1,12 +1,12 @@
//
// Miscellaneous javascript tests
// Kernel tests
//
casper.notebook_test(function () {
this.evaluate(function () {
IPython.notebook.kernel.kernel_info(
function(msg){
IPython._kernel_info_response = msg;
IPython._kernel_info_response = msg;
})
});
@ -24,5 +24,41 @@ casper.notebook_test(function () {
this.test.assertTrue( kernel_info_response.msg_type === 'kernel_info_reply', 'Kernel info request return kernel_info_reply');
this.test.assertTrue( kernel_info_response.content !== undefined, 'Kernel_info_reply is not undefined');
});
this.thenEvaluate(function () {
var kernel = IPython.notebook.session.kernel;
IPython._channels = [
kernel.shell_channel,
kernel.iopub_channel,
kernel.stdin_channel
];
kernel.kill();
});
this.waitFor(function () {
return this.evaluate(function(){
for (var i=0; i < IPython._channels.length; i++) {
var ws = IPython._channels[i];
if (ws.readyState !== ws.CLOSED) {
return false;
}
}
return true;
});
});
this.then(function () {
var states = this.evaluate(function() {
var states = [];
for (var i = 0; i < IPython._channels.length; i++) {
states.push(IPython._channels[i].readyState);
}
return states;
});
for (var i = 0; i < states.length; i++) {
this.test.assertEquals(states[i], WebSocket.CLOSED,
"Kernel.kill closes websockets[" + i + "]");
}
});
});

View File

@ -0,0 +1,43 @@
//
// Tests for the Session object
//
casper.notebook_test(function () {
this.evaluate(function () {
var kernel = IPython.notebook.session.kernel;
IPython._channels = [
kernel.shell_channel,
kernel.iopub_channel,
kernel.stdin_channel
];
IPython.notebook.session.delete();
});
this.waitFor(function () {
return this.evaluate(function(){
for (var i=0; i < IPython._channels.length; i++) {
var ws = IPython._channels[i];
if (ws.readyState !== ws.CLOSED) {
return false;
}
}
return true;
});
});
this.then(function () {
var states = this.evaluate(function() {
var states = [];
for (var i = 0; i < IPython._channels.length; i++) {
states.push(IPython._channels[i].readyState);
}
return states;
});
for (var i = 0; i < states.length; i++) {
this.test.assertEquals(states[i], WebSocket.CLOSED,
"Session.delete closes websockets[" + i + "]");
}
});
});