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