Show More
@@ -46,7 +46,7 b' We support a subset of mongodb operators:' | |||||
46 | # the file COPYING, distributed as part of this software. |
|
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 | from datetime import datetime |
|
50 | from datetime import datetime | |
51 |
|
51 | |||
52 | from IPython.config.configurable import LoggingConfigurable |
|
52 | from IPython.config.configurable import LoggingConfigurable | |
@@ -129,7 +129,7 b' class DictDB(BaseDB):' | |||||
129 | d['msg_id'] = rec['msg_id'] |
|
129 | d['msg_id'] = rec['msg_id'] | |
130 | for key in keys: |
|
130 | for key in keys: | |
131 | d[key] = rec[key] |
|
131 | d[key] = rec[key] | |
132 | return d |
|
132 | return copy(d) | |
133 |
|
133 | |||
134 | def add_record(self, msg_id, rec): |
|
134 | def add_record(self, msg_id, rec): | |
135 | """Add a new Task Record, by msg_id.""" |
|
135 | """Add a new Task Record, by msg_id.""" |
@@ -1166,7 +1166,11 b' class Hub(SessionFactory):' | |||||
1166 | msg = self.session.msg(header['msg_type']) |
|
1166 | msg = self.session.msg(header['msg_type']) | |
1167 | msg_id = msg['msg_id'] |
|
1167 | msg_id = msg['msg_id'] | |
1168 | msg['content'] = rec['content'] |
|
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 | msg['header'] = header |
|
1174 | msg['header'] = header | |
1171 |
|
1175 | |||
1172 | self.session.send(self.resubmit, msg, buffers=rec['buffers']) |
|
1176 | self.session.send(self.resubmit, msg, buffers=rec['buffers']) |
@@ -312,6 +312,28 b' class TestClient(ClusterTestCase):' | |||||
312 | r2 = ahr.get(1) |
|
312 | r2 = ahr.get(1) | |
313 | self.assertFalse(r1 == r2) |
|
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 | def test_resubmit_aborted(self): |
|
337 | def test_resubmit_aborted(self): | |
316 | def f(): |
|
338 | def f(): | |
317 | import random |
|
339 | import random | |
@@ -384,4 +406,3 b' class TestClient(ClusterTestCase):' | |||||
384 | "Shouldn't be spinning, but got wall_time=%f" % ar.wall_time |
|
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 | rec = self.db.get_record(msg_id) |
|
197 | rec = self.db.get_record(msg_id) | |
198 | rec.pop('buffers') |
|
198 | rec.pop('buffers') | |
199 | rec['garbage'] = 'hello' |
|
199 | rec['garbage'] = 'hello' | |
|
200 | rec['header']['msg_id'] = 'fubar' | |||
200 | rec2 = self.db.get_record(msg_id) |
|
201 | rec2 = self.db.get_record(msg_id) | |
201 | self.assertTrue('buffers' in rec2) |
|
202 | self.assertTrue('buffers' in rec2) | |
202 | self.assertFalse('garbage' in rec2) |
|
203 | self.assertFalse('garbage' in rec2) | |
|
204 | self.assertEquals(rec2['header']['msg_id'], msg_id) | |||
203 |
|
205 | |||
204 | def test_pop_safe_find(self): |
|
206 | def test_pop_safe_find(self): | |
205 | """editing query results shouldn't affect record [find]""" |
|
207 | """editing query results shouldn't affect record [find]""" | |
@@ -207,19 +209,23 b' class TestDictBackend(TestCase):' | |||||
207 | rec = self.db.find_records({'msg_id' : msg_id})[0] |
|
209 | rec = self.db.find_records({'msg_id' : msg_id})[0] | |
208 | rec.pop('buffers') |
|
210 | rec.pop('buffers') | |
209 | rec['garbage'] = 'hello' |
|
211 | rec['garbage'] = 'hello' | |
|
212 | rec['header']['msg_id'] = 'fubar' | |||
210 | rec2 = self.db.find_records({'msg_id' : msg_id})[0] |
|
213 | rec2 = self.db.find_records({'msg_id' : msg_id})[0] | |
211 | self.assertTrue('buffers' in rec2) |
|
214 | self.assertTrue('buffers' in rec2) | |
212 | self.assertFalse('garbage' in rec2) |
|
215 | self.assertFalse('garbage' in rec2) | |
|
216 | self.assertEquals(rec2['header']['msg_id'], msg_id) | |||
213 |
|
217 | |||
214 | def test_pop_safe_find_keys(self): |
|
218 | def test_pop_safe_find_keys(self): | |
215 | """editing query results shouldn't affect record [find+keys]""" |
|
219 | """editing query results shouldn't affect record [find+keys]""" | |
216 | msg_id = self.db.get_history()[-1] |
|
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 | rec.pop('buffers') |
|
222 | rec.pop('buffers') | |
219 | rec['garbage'] = 'hello' |
|
223 | rec['garbage'] = 'hello' | |
|
224 | rec['header']['msg_id'] = 'fubar' | |||
220 | rec2 = self.db.find_records({'msg_id' : msg_id})[0] |
|
225 | rec2 = self.db.find_records({'msg_id' : msg_id})[0] | |
221 | self.assertTrue('buffers' in rec2) |
|
226 | self.assertTrue('buffers' in rec2) | |
222 | self.assertFalse('garbage' in rec2) |
|
227 | self.assertFalse('garbage' in rec2) | |
|
228 | self.assertEquals(rec2['header']['msg_id'], msg_id) | |||
223 |
|
229 | |||
224 |
|
230 | |||
225 | class TestSQLiteBackend(TestDictBackend): |
|
231 | class TestSQLiteBackend(TestDictBackend): |
General Comments 0
You need to be logged in to leave comments.
Login now