##// END OF EJS Templates
Fix bug where traceback wasn't being correctly stored in remote tasks....
Fernando Perez -
Show More
@@ -389,7 +389,7 b' class EngineService(object, service.Service):'
389 389 et,ev,tb = self.shell.formatTraceback(et,ev,tb,msg)
390 390 # Add another attribute
391 391 ev._ipython_engine_info = msg
392 f = failure.Failure(ev,et,None)
392 f = failure.Failure(ev,et,tb)
393 393 d.errback(f)
394 394 else:
395 395 d.callback(result)
@@ -186,6 +186,22 b' class ITaskControllerTestCase(TaskTestBase):'
186 186 d.addErrback(lambda f: self.assertRaises(IndexError, f.raiseException))
187 187 return d
188 188
189 def get_traceback_frames(self, result):
190 """Execute a failing string as a task and return stack frame strings.
191
192 This lets us check that the returned exceptions contain as many stack
193 frames as the user expects from his code.
194
195 Parameters
196 ----------
197 d : deferred
198
199 src : string
200 Code to be executed, should fail."""
201 # This gets Twisted's short-format traceback and picks the info for
202 # frames that actually belong to user code.
203 return result.failure.getBriefTraceback().split('\n<string>:')[1:]
204
189 205 def test_traceback(self):
190 206 """Ensure that we have a traceback object in task failures."""
191 207
@@ -196,14 +212,35 b' def fail():'
196 212
197 213 result = fail()
198 214 """
199 t1 = task.StringTask(cmd, pull = 'result')
215 t1 = task.StringTask(cmd)
200 216 d = self.tc.run(t1)
201 217 d.addCallback(self.tc.get_task_result, block=True)
202 218 # Sanity check, that the right exception is raised
203 219 d.addCallback(lambda tr: self.assertRaises(IOError, tr.raise_exception))
204 # Rerun the same task, this time we check for the traceback
220 # Rerun the same task, this time we check for the traceback to have two
221 # frames
222 d.addCallback(lambda r: self.tc.run(t1))
223 d.addCallback(self.tc.get_task_result, block=True)
224 d.addCallback(self.get_traceback_frames)
225 d.addCallback(lambda frames: self.assertEquals(len(frames), 2))
226
227 # And repeat with a deeper stack, just to be safe
228 cmd = """
229 def boom():
230 raise IOError('failure test')
231
232 def crash():
233 boom()
234
235 def fail():
236 crash()
237
238 result = fail()
239 """
240 t1 = task.StringTask(cmd)
205 241 d.addCallback(lambda r: self.tc.run(t1))
206 242 d.addCallback(self.tc.get_task_result, block=True)
207 d.addCallback(lambda tr: self.assertNotEquals(tr.failure.getTraceback(),
208 None))
243 d.addCallback(self.get_traceback_frames)
244 d.addCallback(lambda frames: self.assertEquals(len(frames), 4))
245
209 246 return d
General Comments 0
You need to be logged in to leave comments. Login now