##// END OF EJS Templates
yet another JS race condition fix...
Paul Ivanov -
Show More
@@ -1,39 +1,49 b''
1 //
1 //
2 // Test kernel interrupt
2 // Test kernel interrupt
3 //
3 //
4 casper.notebook_test(function () {
4 casper.notebook_test(function () {
5 this.evaluate(function () {
5 this.evaluate(function () {
6 var cell = IPython.notebook.get_cell(0);
6 var cell = IPython.notebook.get_cell(0);
7 cell.set_text('import time\nfor x in range(3):\n time.sleep(1)');
7 cell.set_text(
8 'import time'+
9 '\nfor x in range(3):'+
10 '\n time.sleep(1)'
11 );
8 cell.execute();
12 cell.execute();
9 });
13 });
10
14
15 this.waitFor(function(){
16 return this.evaluate(function() {
17 return $("#notification_kernel")[0].textContent.indexOf('busy') !== -1;
18 });
19 });
20
11
21
12 // interrupt using menu item (Kernel -> Interrupt)
22 // interrupt using menu item (Kernel -> Interrupt)
13 this.thenClick('li#int_kernel');
23 this.thenClick('li#int_kernel');
14
24
15 this.wait_for_output(0);
25 this.wait_for_output(0);
16
26
17 this.then(function () {
27 this.then(function () {
18 var result = this.get_output_cell(0);
28 var result = this.get_output_cell(0);
19 this.test.assertEquals(result.ename, 'KeyboardInterrupt', 'keyboard interrupt (mouseclick)');
29 this.test.assertEquals(result.ename, 'KeyboardInterrupt', 'keyboard interrupt (mouseclick)');
20 });
30 });
21
31
22 // run cell 0 again, now interrupting using keyboard shortcut
32 // run cell 0 again, now interrupting using keyboard shortcut
23 this.thenEvaluate(function () {
33 this.thenEvaluate(function () {
24 cell.clear_output();
34 cell.clear_output();
25 cell.execute();
35 cell.execute();
26 });
36 });
27
37
28 // interrupt using Ctrl-M I keyboard shortcut
38 // interrupt using Ctrl-M I keyboard shortcut
29 this.thenEvaluate( function() {
39 this.thenEvaluate( function() {
30 IPython.utils.press_ghetto(IPython.utils.keycodes.I)
40 IPython.utils.press_ghetto(IPython.utils.keycodes.I)
31 });
41 });
32
42
33 this.wait_for_output(0);
43 this.wait_for_output(0);
34
44
35 this.then(function () {
45 this.then(function () {
36 var result = this.get_output_cell(0);
46 var result = this.get_output_cell(0);
37 this.test.assertEquals(result.ename, 'KeyboardInterrupt', 'keyboard interrupt (shortcut)');
47 this.test.assertEquals(result.ename, 'KeyboardInterrupt', 'keyboard interrupt (shortcut)');
38 });
48 });
39 });
49 });
@@ -1,123 +1,127 b''
1 //
1 //
2 // Utility functions for the HTML notebook's CasperJS tests.
2 // Utility functions for the HTML notebook's CasperJS tests.
3 //
3 //
4
4
5 // Get the URL of a notebook server on which to run tests.
5 // Get the URL of a notebook server on which to run tests.
6 casper.get_notebook_server = function () {
6 casper.get_notebook_server = function () {
7 port = casper.cli.get("port")
7 port = casper.cli.get("port")
8 port = (typeof port === 'undefined') ? '8888' : port;
8 port = (typeof port === 'undefined') ? '8888' : port;
9 return 'http://127.0.0.1:' + port
9 return 'http://127.0.0.1:' + port
10 };
10 };
11
11
12 // Create and open a new notebook.
12 // Create and open a new notebook.
13 casper.open_new_notebook = function () {
13 casper.open_new_notebook = function () {
14 var baseUrl = this.get_notebook_server();
14 var baseUrl = this.get_notebook_server();
15 this.start(baseUrl);
15 this.start(baseUrl);
16 this.thenClick('button#new_notebook');
16 this.thenClick('button#new_notebook');
17 this.waitForPopup('');
17 this.waitForPopup('');
18
18
19 this.withPopup('', function () {this.waitForSelector('.CodeMirror-code');});
19 this.withPopup('', function () {this.waitForSelector('.CodeMirror-code');});
20 this.then(function () {
20 this.then(function () {
21 // XXX: Kind of odd, the next line works for one test, but not when
21 // XXX: Kind of odd, the next line works for one test, but not when
22 // running multiple tests back-to-back, so we will just point the main
22 // running multiple tests back-to-back, so we will just point the main
23 // casper browser to the same URL as the popup we just grabbed.
23 // casper browser to the same URL as the popup we just grabbed.
24
24
25 //this.page = this.popups[0];
25 //this.page = this.popups[0];
26 this.open(this.popups[0].url);
26 this.open(this.popups[0].url);
27 });
27 });
28
28
29 // initially, the cells aren't created, so wait for them to appear
29 // initially, the cells aren't created, so wait for them to appear
30 this.waitForSelector('.CodeMirror-code');
30 this.waitForSelector('.CodeMirror-code');
31 // and make sure the kernel has started
31 // and make sure the kernel has started
32 this.waitFor( this.kernel_running );
32 this.waitFor( this.kernel_running );
33 };
33 };
34
34
35 // return whether or not the kernel is running
35 // return whether or not the kernel is running
36 casper.kernel_running = function kernel_running() {
36 casper.kernel_running = function kernel_running() {
37 return this.evaluate(function kernel_running() {
37 return this.evaluate(function kernel_running() {
38 return IPython.notebook.kernel.running;
38 return IPython.notebook.kernel.running;
39 });
39 });
40 };
40 };
41
41
42 // Shut down the current notebook's kernel.
42 // Shut down the current notebook's kernel.
43 casper.shutdown_current_kernel = function () {
43 casper.shutdown_current_kernel = function () {
44 this.thenEvaluate(function() {
44 this.thenEvaluate(function() {
45 IPython.notebook.kernel.kill();
45 IPython.notebook.kernel.kill();
46 });
46 });
47 };
47 };
48
48
49 // Delete created notebook.
49 // Delete created notebook.
50 casper.delete_current_notebook = function () {
50 casper.delete_current_notebook = function () {
51 this.thenEvaluate(function() {
51 this.thenEvaluate(function() {
52 var nbData = $('body').data();
52 var nbData = $('body').data();
53 var url = nbData.baseProjectUrl + 'notebooks/' + nbData.notebookId;
53 var url = nbData.baseProjectUrl + 'notebooks/' + nbData.notebookId;
54 $.ajax(url, {
54 $.ajax(url, {
55 type: 'DELETE',
55 type: 'DELETE',
56 });
56 });
57 });
57 });
58 };
58 };
59
59
60 // wait for output in a given cell
60 // wait for output in a given cell
61 casper.wait_for_output = function (cell_num) {
61 casper.wait_for_output = function (cell_num) {
62 this.then(function() {
62 this.then(function() {
63 this.waitFor(function (c) {
63 this.waitFor(function (c) {
64 return this.evaluate(function get_output(c) {
64 return this.evaluate(function get_output(c) {
65 var cell = IPython.notebook.get_cell(c);
65 var cell = IPython.notebook.get_cell(c);
66 return cell.output_area.outputs.length != 0;
66 return cell.output_area.outputs.length != 0;
67 },
67 },
68 // pass parameter from the test suite js to the browser code js
68 // pass parameter from the test suite js to the browser code js
69 {c : cell_num});
69 {c : cell_num});
70 },
71 function then() { },
72 function timeout() {
73 this.echo("wait_for_output timedout!");
70 });
74 });
71 });
75 });
72 };
76 };
73
77
74 // return the output of a given cell
78 // return the output of a given cell
75 casper.get_output_cell = function (cell_num) {
79 casper.get_output_cell = function (cell_num) {
76 var result = casper.evaluate(function (c) {
80 var result = casper.evaluate(function (c) {
77 var cell = IPython.notebook.get_cell(c);
81 var cell = IPython.notebook.get_cell(c);
78 return cell.output_area.outputs[0];
82 return cell.output_area.outputs[0];
79 },
83 },
80 {c : cell_num});
84 {c : cell_num});
81 return result;
85 return result;
82 };
86 };
83
87
84 // return the number of cells in the notebook
88 // return the number of cells in the notebook
85 casper.get_cells_length = function () {
89 casper.get_cells_length = function () {
86 var result = casper.evaluate(function () {
90 var result = casper.evaluate(function () {
87 return IPython.notebook.get_cells().length;
91 return IPython.notebook.get_cells().length;
88 })
92 })
89 return result;
93 return result;
90 };
94 };
91
95
92 // Wrap a notebook test to reduce boilerplate.
96 // Wrap a notebook test to reduce boilerplate.
93 casper.notebook_test = function(test) {
97 casper.notebook_test = function(test) {
94 this.open_new_notebook();
98 this.open_new_notebook();
95 this.then(test);
99 this.then(test);
96 //XXX: we get sporadic error messages when shutting down some of the tests.
100 //XXX: we get sporadic error messages when shutting down some of the tests.
97 // Since the entire server will go down at the end of running the test
101 // Since the entire server will go down at the end of running the test
98 // suite, it's ok for now to not try to shut anything down.
102 // suite, it's ok for now to not try to shut anything down.
99 this.shutdown_current_kernel();
103 this.shutdown_current_kernel();
100
104
101 //XXX: the implementation of delete_current_notebook is currently broken
105 //XXX: the implementation of delete_current_notebook is currently broken
102 // it's not a big deal, since the notebook directory will be deleted on
106 // it's not a big deal, since the notebook directory will be deleted on
103 // cleanup, but we should add tests for deleting the notebook separately
107 // cleanup, but we should add tests for deleting the notebook separately
104 //this.delete_current_notebook();
108 //this.delete_current_notebook();
105
109
106 // Run the browser automation.
110 // Run the browser automation.
107 this.run(function() {
111 this.run(function() {
108 this.test.done();
112 this.test.done();
109 });
113 });
110 };
114 };
111
115
112 casper.options.waitTimeout=10000
116 casper.options.waitTimeout=10000
113 casper.on('waitFor.timeout', function onWaitForTimeout(timeout) {
117 casper.on('waitFor.timeout', function onWaitForTimeout(timeout) {
114 this.echo("Timeout for " + casper.get_notebook_server());
118 this.echo("Timeout for " + casper.get_notebook_server());
115 this.echo("Is the notebook server running?");
119 this.echo("Is the notebook server running?");
116 });
120 });
117
121
118 // Pass `console.log` calls from page JS to casper.
122 // Pass `console.log` calls from page JS to casper.
119 casper.printLog = function () {
123 casper.printLog = function () {
120 this.on('remote.message', function(msg) {
124 this.on('remote.message', function(msg) {
121 this.echo('Remote message caught: ' + msg);
125 this.echo('Remote message caught: ' + msg);
122 });
126 });
123 };
127 };
General Comments 0
You need to be logged in to leave comments. Login now