Show More
@@ -46,7 +46,7 b' We support a subset of mongodb operators:' | |||
|
46 | 46 | # the file COPYING, distributed as part of this software. |
|
47 | 47 | #----------------------------------------------------------------------------- |
|
48 | 48 | |
|
49 | from copy import copy | |
|
49 | from copy import deepcopy as copy | |
|
50 | 50 | from datetime import datetime |
|
51 | 51 | |
|
52 | 52 | from IPython.config.configurable import LoggingConfigurable |
@@ -129,7 +129,7 b' class DictDB(BaseDB):' | |||
|
129 | 129 | d['msg_id'] = rec['msg_id'] |
|
130 | 130 | for key in keys: |
|
131 | 131 | d[key] = rec[key] |
|
132 | return d | |
|
132 | return copy(d) | |
|
133 | 133 | |
|
134 | 134 | def add_record(self, msg_id, rec): |
|
135 | 135 | """Add a new Task Record, by msg_id.""" |
@@ -1166,7 +1166,11 b' class Hub(SessionFactory):' | |||
|
1166 | 1166 | msg = self.session.msg(header['msg_type']) |
|
1167 | 1167 | msg_id = msg['msg_id'] |
|
1168 | 1168 | msg['content'] = rec['content'] |
|
1169 | header.update(msg['header']) | |
|
1169 | ||
|
1170 | # use the old header, but update msg_id and timestamp | |
|
1171 | fresh = msg['header'] | |
|
1172 | header['msg_id'] = fresh['msg_id'] | |
|
1173 | header['date'] = fresh['date'] | |
|
1170 | 1174 | msg['header'] = header |
|
1171 | 1175 | |
|
1172 | 1176 | self.session.send(self.resubmit, msg, buffers=rec['buffers']) |
@@ -312,6 +312,28 b' class TestClient(ClusterTestCase):' | |||
|
312 | 312 | r2 = ahr.get(1) |
|
313 | 313 | self.assertFalse(r1 == r2) |
|
314 | 314 | |
|
315 | def test_resubmit_header(self): | |
|
316 | """resubmit shouldn't clobber the whole header""" | |
|
317 | def f(): | |
|
318 | import random | |
|
319 | return random.random() | |
|
320 | v = self.client.load_balanced_view() | |
|
321 | v.retries = 1 | |
|
322 | ar = v.apply_async(f) | |
|
323 | r1 = ar.get(1) | |
|
324 | # give the Hub a chance to notice: | |
|
325 | self._wait_for_idle() | |
|
326 | ahr = self.client.resubmit(ar.msg_ids) | |
|
327 | ahr.get(1) | |
|
328 | time.sleep(0.5) | |
|
329 | records = self.client.db_query({'msg_id': {'$in': ar.msg_ids + ahr.msg_ids}}, keys='header') | |
|
330 | h1,h2 = [ r['header'] for r in records ] | |
|
331 | for key in set(h1.keys()).union(set(h2.keys())): | |
|
332 | if key in ('msg_id', 'date'): | |
|
333 | self.assertNotEquals(h1[key], h2[key]) | |
|
334 | else: | |
|
335 | self.assertEquals(h1[key], h2[key]) | |
|
336 | ||
|
315 | 337 | def test_resubmit_aborted(self): |
|
316 | 338 | def f(): |
|
317 | 339 | import random |
@@ -384,4 +406,3 b' class TestClient(ClusterTestCase):' | |||
|
384 | 406 | "Shouldn't be spinning, but got wall_time=%f" % ar.wall_time |
|
385 | 407 | ) |
|
386 | 408 | |
|
387 |
@@ -197,9 +197,11 b' class TestDictBackend(TestCase):' | |||
|
197 | 197 | rec = self.db.get_record(msg_id) |
|
198 | 198 | rec.pop('buffers') |
|
199 | 199 | rec['garbage'] = 'hello' |
|
200 | rec['header']['msg_id'] = 'fubar' | |
|
200 | 201 | rec2 = self.db.get_record(msg_id) |
|
201 | 202 | self.assertTrue('buffers' in rec2) |
|
202 | 203 | self.assertFalse('garbage' in rec2) |
|
204 | self.assertEquals(rec2['header']['msg_id'], msg_id) | |
|
203 | 205 | |
|
204 | 206 | def test_pop_safe_find(self): |
|
205 | 207 | """editing query results shouldn't affect record [find]""" |
@@ -207,19 +209,23 b' class TestDictBackend(TestCase):' | |||
|
207 | 209 | rec = self.db.find_records({'msg_id' : msg_id})[0] |
|
208 | 210 | rec.pop('buffers') |
|
209 | 211 | rec['garbage'] = 'hello' |
|
212 | rec['header']['msg_id'] = 'fubar' | |
|
210 | 213 | rec2 = self.db.find_records({'msg_id' : msg_id})[0] |
|
211 | 214 | self.assertTrue('buffers' in rec2) |
|
212 | 215 | self.assertFalse('garbage' in rec2) |
|
216 | self.assertEquals(rec2['header']['msg_id'], msg_id) | |
|
213 | 217 | |
|
214 | 218 | def test_pop_safe_find_keys(self): |
|
215 | 219 | """editing query results shouldn't affect record [find+keys]""" |
|
216 | 220 | msg_id = self.db.get_history()[-1] |
|
217 | rec = self.db.find_records({'msg_id' : msg_id}, keys=['buffers'])[0] | |
|
221 | rec = self.db.find_records({'msg_id' : msg_id}, keys=['buffers', 'header'])[0] | |
|
218 | 222 | rec.pop('buffers') |
|
219 | 223 | rec['garbage'] = 'hello' |
|
224 | rec['header']['msg_id'] = 'fubar' | |
|
220 | 225 | rec2 = self.db.find_records({'msg_id' : msg_id})[0] |
|
221 | 226 | self.assertTrue('buffers' in rec2) |
|
222 | 227 | self.assertFalse('garbage' in rec2) |
|
228 | self.assertEquals(rec2['header']['msg_id'], msg_id) | |
|
223 | 229 | |
|
224 | 230 | |
|
225 | 231 | class TestSQLiteBackend(TestDictBackend): |
General Comments 0
You need to be logged in to leave comments.
Login now