Show More
@@ -1,317 +1,321 b'' | |||||
1 |
|
1 | |||
2 | // |
|
2 | // | |
3 | // Kernel tests |
|
3 | // Kernel tests | |
4 | // |
|
4 | // | |
5 | casper.notebook_test(function () { |
|
5 | casper.notebook_test(function () { | |
6 | // test that the kernel is running |
|
6 | // test that the kernel is running | |
7 | this.then(function () { |
|
7 | this.then(function () { | |
8 | this.test.assert(this.kernel_running(), 'kernel is running'); |
|
8 | this.test.assert(this.kernel_running(), 'kernel is running'); | |
9 | }); |
|
9 | }); | |
10 |
|
10 | |||
11 | // test list |
|
11 | // test list | |
12 | this.thenEvaluate(function () { |
|
12 | this.thenEvaluate(function () { | |
13 | IPython._kernels = null; |
|
13 | IPython._kernels = null; | |
14 | IPython.notebook.kernel.list(function (data) { |
|
14 | IPython.notebook.kernel.list(function (data) { | |
15 | IPython._kernels = data; |
|
15 | IPython._kernels = data; | |
16 | }); |
|
16 | }); | |
17 | }); |
|
17 | }); | |
18 | this.waitFor(function () { |
|
18 | this.waitFor(function () { | |
19 | return this.evaluate(function () { |
|
19 | return this.evaluate(function () { | |
20 | return IPython._kernels !== null; |
|
20 | return IPython._kernels !== null; | |
21 | }); |
|
21 | }); | |
22 | }); |
|
22 | }); | |
23 | this.then(function () { |
|
23 | this.then(function () { | |
24 | var num_kernels = this.evaluate(function () { |
|
24 | var num_kernels = this.evaluate(function () { | |
25 | return IPython._kernels.length; |
|
25 | return IPython._kernels.length; | |
26 | }); |
|
26 | }); | |
27 | this.test.assertEquals(num_kernels, 1, 'one kernel running'); |
|
27 | this.test.assertEquals(num_kernels, 1, 'one kernel running'); | |
28 | }); |
|
28 | }); | |
29 |
|
29 | |||
30 | // test get_info |
|
30 | // test get_info | |
31 | var kernel_info = this.evaluate(function () { |
|
31 | var kernel_info = this.evaluate(function () { | |
32 | return { |
|
32 | return { | |
33 | name: IPython.notebook.kernel.name, |
|
33 | name: IPython.notebook.kernel.name, | |
34 | id: IPython.notebook.kernel.id |
|
34 | id: IPython.notebook.kernel.id | |
35 | }; |
|
35 | }; | |
36 | }); |
|
36 | }); | |
37 | this.thenEvaluate(function () { |
|
37 | this.thenEvaluate(function () { | |
38 | IPython._kernel_info = null; |
|
38 | IPython._kernel_info = null; | |
39 | IPython.notebook.kernel.get_info(function (data) { |
|
39 | IPython.notebook.kernel.get_info(function (data) { | |
40 | IPython._kernel_info = data; |
|
40 | IPython._kernel_info = data; | |
41 | }); |
|
41 | }); | |
42 | }); |
|
42 | }); | |
43 | this.waitFor(function () { |
|
43 | this.waitFor(function () { | |
44 | return this.evaluate(function () { |
|
44 | return this.evaluate(function () { | |
45 | return IPython._kernel_info !== null; |
|
45 | return IPython._kernel_info !== null; | |
46 | }); |
|
46 | }); | |
47 | }); |
|
47 | }); | |
48 | this.then(function () { |
|
48 | this.then(function () { | |
49 | var new_kernel_info = this.evaluate(function () { |
|
49 | var new_kernel_info = this.evaluate(function () { | |
50 | return IPython._kernel_info; |
|
50 | return IPython._kernel_info; | |
51 | }); |
|
51 | }); | |
52 | this.test.assertEquals(kernel_info.name, new_kernel_info.name, 'kernel: name correct'); |
|
52 | this.test.assertEquals(kernel_info.name, new_kernel_info.name, 'kernel: name correct'); | |
53 | this.test.assertEquals(kernel_info.id, new_kernel_info.id, 'kernel: id correct'); |
|
53 | this.test.assertEquals(kernel_info.id, new_kernel_info.id, 'kernel: id correct'); | |
54 | }); |
|
54 | }); | |
55 |
|
55 | |||
56 | // test interrupt |
|
56 | // test interrupt | |
57 | this.thenEvaluate(function () { |
|
57 | this.thenEvaluate(function () { | |
58 | IPython._interrupted = false; |
|
58 | IPython._interrupted = false; | |
59 | IPython.notebook.kernel.interrupt(function () { |
|
59 | IPython.notebook.kernel.interrupt(function () { | |
60 | IPython._interrupted = true; |
|
60 | IPython._interrupted = true; | |
61 | }); |
|
61 | }); | |
62 | }); |
|
62 | }); | |
63 | this.waitFor(function () { |
|
63 | this.waitFor(function () { | |
64 | return this.evaluate(function () { |
|
64 | return this.evaluate(function () { | |
65 | return IPython._interrupted; |
|
65 | return IPython._interrupted; | |
66 | }); |
|
66 | }); | |
67 | }); |
|
67 | }); | |
68 | this.then(function () { |
|
68 | this.then(function () { | |
69 | var interrupted = this.evaluate(function () { |
|
69 | var interrupted = this.evaluate(function () { | |
70 | return IPython._interrupted; |
|
70 | return IPython._interrupted; | |
71 | }); |
|
71 | }); | |
72 | this.test.assert(interrupted, 'kernel was interrupted'); |
|
72 | this.test.assert(interrupted, 'kernel was interrupted'); | |
73 | }); |
|
73 | }); | |
74 |
|
74 | |||
75 | // test restart |
|
75 | // test restart | |
76 | this.thenEvaluate(function () { |
|
76 | this.thenEvaluate(function () { | |
77 | IPython.notebook.kernel.restart(); |
|
77 | IPython.notebook.kernel.restart(); | |
78 | }); |
|
78 | }); | |
79 | this.waitFor(this.kernel_disconnected); |
|
79 | this.waitFor(this.kernel_disconnected); | |
80 | this.wait_for_kernel_ready(); |
|
80 | this.wait_for_kernel_ready(); | |
81 | this.then(function () { |
|
81 | this.then(function () { | |
82 | this.test.assert(this.kernel_running(), 'kernel restarted'); |
|
82 | this.test.assert(this.kernel_running(), 'kernel restarted'); | |
83 | }); |
|
83 | }); | |
84 |
|
84 | |||
85 | // test reconnect |
|
85 | // test reconnect | |
86 | this.thenEvaluate(function () { |
|
86 | this.thenEvaluate(function () { | |
87 | IPython.notebook.kernel.stop_channels(); |
|
87 | IPython.notebook.kernel.stop_channels(); | |
88 | }); |
|
88 | }); | |
89 | this.waitFor(this.kernel_disconnected); |
|
89 | this.waitFor(this.kernel_disconnected); | |
90 | this.thenEvaluate(function () { |
|
90 | this.thenEvaluate(function () { | |
91 | IPython.notebook.kernel.reconnect(); |
|
91 | IPython.notebook.kernel.reconnect(); | |
92 | }); |
|
92 | }); | |
93 | this.wait_for_kernel_ready(); |
|
93 | this.wait_for_kernel_ready(); | |
94 | this.then(function () { |
|
94 | this.then(function () { | |
95 | this.test.assert(this.kernel_running(), 'kernel reconnected'); |
|
95 | this.test.assert(this.kernel_running(), 'kernel reconnected'); | |
96 | }); |
|
96 | }); | |
97 |
|
97 | |||
98 | // test kernel_info_request |
|
98 | // test kernel_info_request | |
99 | this.evaluate(function () { |
|
99 | this.evaluate(function () { | |
100 | IPython.notebook.kernel.kernel_info( |
|
100 | IPython.notebook.kernel.kernel_info( | |
101 | function(msg){ |
|
101 | function(msg){ | |
102 | IPython._kernel_info_response = msg; |
|
102 | IPython._kernel_info_response = msg; | |
103 | }); |
|
103 | }); | |
104 | }); |
|
104 | }); | |
105 | this.waitFor( |
|
105 | this.waitFor( | |
106 | function () { |
|
106 | function () { | |
107 | return this.evaluate(function(){ |
|
107 | return this.evaluate(function(){ | |
108 | return IPython._kernel_info_response; |
|
108 | return IPython._kernel_info_response; | |
109 | }); |
|
109 | }); | |
110 | }); |
|
110 | }); | |
111 | this.then(function () { |
|
111 | this.then(function () { | |
112 | var kernel_info_response = this.evaluate(function(){ |
|
112 | var kernel_info_response = this.evaluate(function(){ | |
113 | return IPython._kernel_info_response; |
|
113 | return IPython._kernel_info_response; | |
114 | }); |
|
114 | }); | |
115 | this.test.assertTrue( kernel_info_response.msg_type === 'kernel_info_reply', 'Kernel info request return kernel_info_reply'); |
|
115 | this.test.assertTrue( kernel_info_response.msg_type === 'kernel_info_reply', 'Kernel info request return kernel_info_reply'); | |
116 | this.test.assertTrue( kernel_info_response.content !== undefined, 'Kernel_info_reply is not undefined'); |
|
116 | this.test.assertTrue( kernel_info_response.content !== undefined, 'Kernel_info_reply is not undefined'); | |
117 | }); |
|
117 | }); | |
118 |
|
118 | |||
119 | // test kill |
|
119 | // test kill | |
120 | this.thenEvaluate(function () { |
|
120 | this.thenEvaluate(function () { | |
121 | IPython.notebook.kernel.kill(); |
|
121 | IPython.notebook.kernel.kill(); | |
122 | }); |
|
122 | }); | |
123 | this.waitFor(this.kernel_disconnected); |
|
123 | this.waitFor(this.kernel_disconnected); | |
124 | this.then(function () { |
|
124 | this.then(function () { | |
125 | this.test.assert(!this.kernel_running(), 'kernel is not running'); |
|
125 | this.test.assert(!this.kernel_running(), 'kernel is not running'); | |
126 | }); |
|
126 | }); | |
127 |
|
127 | |||
128 | // test start |
|
128 | // test start | |
129 | var url; |
|
129 | var url; | |
130 | this.then(function () { |
|
130 | this.then(function () { | |
131 | url = this.evaluate(function () { |
|
131 | url = this.evaluate(function () { | |
132 | return IPython.notebook.kernel.start(); |
|
132 | return IPython.notebook.kernel.start(); | |
133 | }); |
|
133 | }); | |
134 | }); |
|
134 | }); | |
135 | this.then(function () { |
|
135 | this.then(function () { | |
136 | this.test.assertEquals(url, "/api/kernels", "start url is correct"); |
|
136 | this.test.assertEquals(url, "/api/kernels", "start url is correct"); | |
137 | }); |
|
137 | }); | |
138 | this.wait_for_kernel_ready(); |
|
138 | this.wait_for_kernel_ready(); | |
139 | this.then(function () { |
|
139 | this.then(function () { | |
140 | this.test.assert(this.kernel_running(), 'kernel is running'); |
|
140 | this.test.assert(this.kernel_running(), 'kernel is running'); | |
141 | }); |
|
141 | }); | |
142 |
|
142 | |||
143 | // test start with parameters |
|
143 | // test start with parameters | |
144 | this.thenEvaluate(function () { |
|
144 | this.thenEvaluate(function () { | |
145 | IPython.notebook.kernel.kill(); |
|
145 | IPython.notebook.kernel.kill(); | |
146 | }); |
|
146 | }); | |
147 | this.waitFor(this.kernel_disconnected); |
|
147 | this.waitFor(this.kernel_disconnected); | |
148 | this.then(function () { |
|
148 | this.then(function () { | |
149 | url = this.evaluate(function () { |
|
149 | url = this.evaluate(function () { | |
150 | return IPython.notebook.kernel.start({foo: "bar"}); |
|
150 | return IPython.notebook.kernel.start({foo: "bar"}); | |
151 | }); |
|
151 | }); | |
152 | }); |
|
152 | }); | |
153 | this.then(function () { |
|
153 | this.then(function () { | |
154 | this.test.assertEquals(url, "/api/kernels?foo=bar", "start url with params is correct"); |
|
154 | this.test.assertEquals(url, "/api/kernels?foo=bar", "start url with params is correct"); | |
155 | }); |
|
155 | }); | |
156 | this.wait_for_kernel_ready(); |
|
156 | this.wait_for_kernel_ready(); | |
157 | this.then(function () { |
|
157 | this.then(function () { | |
158 | this.test.assert(this.kernel_running(), 'kernel is running'); |
|
158 | this.test.assert(this.kernel_running(), 'kernel is running'); | |
159 | }); |
|
159 | }); | |
160 |
|
160 | |||
161 | // check for events in kill/start cycle |
|
161 | // check for events in kill/start cycle | |
162 | this.event_test( |
|
162 | this.event_test( | |
163 | 'kill/start', |
|
163 | 'kill/start', | |
164 | [ |
|
164 | [ | |
165 | 'kernel_killed.Kernel', |
|
165 | 'kernel_killed.Kernel', | |
166 | 'kernel_created.Kernel', |
|
166 | 'kernel_created.Kernel', | |
167 | 'kernel_connected.Kernel', |
|
167 | 'kernel_connected.Kernel', | |
168 | 'kernel_starting.Kernel', |
|
168 | 'kernel_starting.Kernel', | |
169 | 'kernel_ready.Kernel' |
|
169 | 'kernel_ready.Kernel' | |
170 | ], |
|
170 | ], | |
171 | function () { |
|
171 | function () { | |
172 | this.thenEvaluate(function () { |
|
172 | this.thenEvaluate(function () { | |
173 | IPython.notebook.kernel.kill(); |
|
173 | IPython.notebook.kernel.kill(); | |
174 | }); |
|
174 | }); | |
175 | this.waitFor(this.kernel_disconnected); |
|
175 | this.waitFor(this.kernel_disconnected); | |
176 | this.thenEvaluate(function () { |
|
176 | this.thenEvaluate(function () { | |
177 | IPython.notebook.kernel.start(); |
|
177 | IPython.notebook.kernel.start(); | |
178 | }); |
|
178 | }); | |
179 | } |
|
179 | } | |
180 | ); |
|
180 | ); | |
181 | // wait for any last idle/busy messages to be handled |
|
181 | // wait for any last idle/busy messages to be handled | |
182 | this.wait_for_kernel_ready(); |
|
182 | this.wait_for_kernel_ready(); | |
183 |
|
183 | |||
184 | // check for events in disconnect/connect cycle |
|
184 | // check for events in disconnect/connect cycle | |
185 | this.event_test( |
|
185 | this.event_test( | |
186 | 'reconnect', |
|
186 | 'reconnect', | |
187 | [ |
|
187 | [ | |
188 | 'kernel_reconnecting.Kernel', |
|
188 | 'kernel_reconnecting.Kernel', | |
189 | 'kernel_connected.Kernel', |
|
189 | 'kernel_connected.Kernel', | |
190 | ], |
|
190 | ], | |
191 | function () { |
|
191 | function () { | |
192 | this.thenEvaluate(function () { |
|
192 | this.thenEvaluate(function () { | |
193 | IPython.notebook.kernel.stop_channels(); |
|
193 | IPython.notebook.kernel.stop_channels(); | |
194 | IPython.notebook.kernel.reconnect(1); |
|
194 | IPython.notebook.kernel.reconnect(1); | |
195 | }); |
|
195 | }); | |
196 | } |
|
196 | } | |
197 | ); |
|
197 | ); | |
198 | // wait for any last idle/busy messages to be handled |
|
198 | // wait for any last idle/busy messages to be handled | |
199 | this.wait_for_kernel_ready(); |
|
199 | this.wait_for_kernel_ready(); | |
200 |
|
200 | |||
201 | // check for events in the restart cycle |
|
201 | // check for events in the restart cycle | |
202 | this.event_test( |
|
202 | this.event_test( | |
203 | 'restart', |
|
203 | 'restart', | |
204 | [ |
|
204 | [ | |
205 | 'kernel_restarting.Kernel', |
|
205 | 'kernel_restarting.Kernel', | |
206 | 'kernel_created.Kernel', |
|
206 | 'kernel_created.Kernel', | |
207 | 'kernel_connected.Kernel', |
|
207 | 'kernel_connected.Kernel', | |
208 | 'kernel_starting.Kernel', |
|
208 | 'kernel_starting.Kernel', | |
209 | 'kernel_ready.Kernel' |
|
209 | 'kernel_ready.Kernel' | |
210 | ], |
|
210 | ], | |
211 | function () { |
|
211 | function () { | |
212 | this.thenEvaluate(function () { |
|
212 | this.thenEvaluate(function () { | |
213 | IPython.notebook.kernel.restart(); |
|
213 | IPython.notebook.kernel.restart(); | |
214 | }); |
|
214 | }); | |
215 | } |
|
215 | } | |
216 | ); |
|
216 | ); | |
217 | // wait for any last idle/busy messages to be handled |
|
217 | // wait for any last idle/busy messages to be handled | |
218 | this.wait_for_kernel_ready(); |
|
218 | this.wait_for_kernel_ready(); | |
219 |
|
219 | |||
220 | // check for events in the interrupt cycle |
|
220 | // check for events in the interrupt cycle | |
221 | this.event_test( |
|
221 | this.event_test( | |
222 | 'interrupt', |
|
222 | 'interrupt', | |
223 | [ |
|
223 | [ | |
224 | 'kernel_interrupting.Kernel', |
|
224 | 'kernel_interrupting.Kernel', | |
225 | 'kernel_busy.Kernel', |
|
225 | 'kernel_busy.Kernel', | |
226 | 'kernel_idle.Kernel' |
|
226 | 'kernel_idle.Kernel' | |
227 | ], |
|
227 | ], | |
228 | function () { |
|
228 | function () { | |
229 | this.thenEvaluate(function () { |
|
229 | this.thenEvaluate(function () { | |
230 | IPython.notebook.kernel.interrupt(); |
|
230 | IPython.notebook.kernel.interrupt(); | |
231 | }); |
|
231 | }); | |
232 | } |
|
232 | } | |
233 | ); |
|
233 | ); | |
234 | this.wait_for_kernel_ready(); |
|
234 | this.wait_for_kernel_ready(); | |
235 |
|
235 | |||
236 | // check for events after ws close |
|
236 | // check for events after ws close | |
237 | this.event_test( |
|
237 | this.event_test( | |
238 | 'ws_closed_ok', |
|
238 | 'ws_closed_ok', | |
239 | [ |
|
239 | [ | |
240 | 'kernel_disconnected.Kernel', |
|
240 | 'kernel_disconnected.Kernel', | |
241 | 'kernel_reconnecting.Kernel', |
|
241 | 'kernel_reconnecting.Kernel', | |
242 | 'kernel_connected.Kernel', |
|
242 | 'kernel_connected.Kernel', | |
243 | 'kernel_busy.Kernel', |
|
243 | 'kernel_busy.Kernel', | |
244 | 'kernel_idle.Kernel' |
|
244 | 'kernel_idle.Kernel' | |
245 | ], |
|
245 | ], | |
246 | function () { |
|
246 | function () { | |
247 | this.thenEvaluate(function () { |
|
247 | this.thenEvaluate(function () { | |
248 | IPython.notebook.kernel._ws_closed("", false); |
|
248 | IPython.notebook.kernel._ws_closed("", false); | |
249 | }); |
|
249 | }); | |
250 | } |
|
250 | } | |
251 | ); |
|
251 | ); | |
252 | // wait for any last idle/busy messages to be handled |
|
252 | // wait for any last idle/busy messages to be handled | |
253 | this.wait_for_kernel_ready(); |
|
253 | this.wait_for_kernel_ready(); | |
254 |
|
254 | |||
255 | // check for events after ws close (error) |
|
255 | // check for events after ws close (error) | |
256 | this.event_test( |
|
256 | this.event_test( | |
257 | 'ws_closed_error', |
|
257 | 'ws_closed_error', | |
258 | [ |
|
258 | [ | |
259 | 'kernel_disconnected.Kernel', |
|
259 | 'kernel_disconnected.Kernel', | |
260 | 'kernel_connection_failed.Kernel' |
|
260 | 'kernel_connection_failed.Kernel', | |
|
261 | 'kernel_reconnecting.Kernel', | |||
|
262 | 'kernel_connected.Kernel', | |||
|
263 | 'kernel_busy.Kernel', | |||
|
264 | 'kernel_idle.Kernel' | |||
261 | ], |
|
265 | ], | |
262 | function () { |
|
266 | function () { | |
263 | this.thenEvaluate(function () { |
|
267 | this.thenEvaluate(function () { | |
264 | IPython.notebook.kernel._ws_closed("", true); |
|
268 | IPython.notebook.kernel._ws_closed("", true); | |
265 | }); |
|
269 | }); | |
266 | } |
|
270 | } | |
267 | ); |
|
271 | ); | |
268 |
|
272 | |||
269 | // start the kernel back up |
|
273 | // start the kernel back up | |
270 | this.thenEvaluate(function () { |
|
274 | this.thenEvaluate(function () { | |
271 | IPython.notebook.kernel.restart(); |
|
275 | IPython.notebook.kernel.restart(); | |
272 | }); |
|
276 | }); | |
273 | this.waitFor(this.kernel_running); |
|
277 | this.waitFor(this.kernel_running); | |
274 | this.wait_for_kernel_ready(); |
|
278 | this.wait_for_kernel_ready(); | |
275 |
|
279 | |||
276 | // test handling of autorestarting messages |
|
280 | // test handling of autorestarting messages | |
277 | this.event_test( |
|
281 | this.event_test( | |
278 | 'autorestarting', |
|
282 | 'autorestarting', | |
279 | [ |
|
283 | [ | |
280 | 'kernel_restarting.Kernel', |
|
284 | 'kernel_restarting.Kernel', | |
281 | 'kernel_autorestarting.Kernel', |
|
285 | 'kernel_autorestarting.Kernel', | |
282 | ], |
|
286 | ], | |
283 | function () { |
|
287 | function () { | |
284 | this.thenEvaluate(function () { |
|
288 | this.thenEvaluate(function () { | |
285 | var cell = IPython.notebook.get_cell(0); |
|
289 | var cell = IPython.notebook.get_cell(0); | |
286 | cell.set_text('import os\n' + 'os._exit(1)'); |
|
290 | cell.set_text('import os\n' + 'os._exit(1)'); | |
287 | cell.execute(); |
|
291 | cell.execute(); | |
288 | }); |
|
292 | }); | |
289 | } |
|
293 | } | |
290 | ); |
|
294 | ); | |
291 | this.wait_for_kernel_ready(); |
|
295 | this.wait_for_kernel_ready(); | |
292 |
|
296 | |||
293 | // test handling of failed restart |
|
297 | // test handling of failed restart | |
294 | this.event_test( |
|
298 | this.event_test( | |
295 | 'failed_restart', |
|
299 | 'failed_restart', | |
296 | [ |
|
300 | [ | |
297 | 'kernel_restarting.Kernel', |
|
301 | 'kernel_restarting.Kernel', | |
298 | 'kernel_autorestarting.Kernel', |
|
302 | 'kernel_autorestarting.Kernel', | |
299 | 'kernel_dead.Kernel' |
|
303 | 'kernel_dead.Kernel' | |
300 | ], |
|
304 | ], | |
301 | function () { |
|
305 | function () { | |
302 | this.thenEvaluate(function () { |
|
306 | this.thenEvaluate(function () { | |
303 | var cell = IPython.notebook.get_cell(0); |
|
307 | var cell = IPython.notebook.get_cell(0); | |
304 | cell.set_text("import os\n" + |
|
308 | cell.set_text("import os\n" + | |
305 | "from IPython.kernel.connect import get_connection_file\n" + |
|
309 | "from IPython.kernel.connect import get_connection_file\n" + | |
306 | "with open(get_connection_file(), 'w') as f:\n" + |
|
310 | "with open(get_connection_file(), 'w') as f:\n" + | |
307 | " f.write('garbage')\n" + |
|
311 | " f.write('garbage')\n" + | |
308 | "os._exit(1)"); |
|
312 | "os._exit(1)"); | |
309 | cell.execute(); |
|
313 | cell.execute(); | |
310 | }); |
|
314 | }); | |
311 | }, |
|
315 | }, | |
312 |
|
316 | |||
313 | // need an extra-long timeout, because it needs to try |
|
317 | // need an extra-long timeout, because it needs to try | |
314 | // restarting the kernel 5 times! |
|
318 | // restarting the kernel 5 times! | |
315 | 20000 |
|
319 | 20000 | |
316 | ); |
|
320 | ); | |
317 | }); |
|
321 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now