##// END OF EJS Templates
Merge pull request #3649 from minrk/get_dict_single...
Min RK -
r11410:ccbe1c2b merge
parent child Browse files
Show More
@@ -191,14 +191,21 b' class AsyncResult(object):'
191 """
191 """
192
192
193 results = self.get(timeout)
193 results = self.get(timeout)
194 if self._single_result:
195 results = [results]
194 engine_ids = [ md['engine_id'] for md in self._metadata ]
196 engine_ids = [ md['engine_id'] for md in self._metadata ]
195 bycount = sorted(engine_ids, key=lambda k: engine_ids.count(k))
197
196 maxcount = bycount.count(bycount[-1])
198
197 if maxcount > 1:
199 rdict = {}
200 for engine_id, result in zip(engine_ids, results):
201 if engine_id in rdict:
198 raise ValueError("Cannot build dict, %i jobs ran on engine #%i"%(
202 raise ValueError("Cannot build dict, %i jobs ran on engine #%i" % (
199 maxcount, bycount[-1]))
203 engine_ids.count(engine_id), engine_id)
204 )
205 else:
206 rdict[engine_id] = result
200
207
201 return dict(zip(engine_ids,results))
208 return rdict
202
209
203 @property
210 @property
204 def result(self):
211 def result(self):
@@ -35,6 +35,9 b' def wait(n):'
35 time.sleep(n)
35 time.sleep(n)
36 return n
36 return n
37
37
38 def echo(x):
39 return x
40
38 class AsyncResultTest(ClusterTestCase):
41 class AsyncResultTest(ClusterTestCase):
39
42
40 def test_single_result_view(self):
43 def test_single_result_view(self):
@@ -77,6 +80,20 b' class AsyncResultTest(ClusterTestCase):'
77 for eid,r in d.iteritems():
80 for eid,r in d.iteritems():
78 self.assertEqual(r, 5)
81 self.assertEqual(r, 5)
79
82
83 def test_get_dict_single(self):
84 view = self.client[-1]
85 for v in (range(5), 5, ('abc', 'def'), 'string'):
86 ar = view.apply_async(echo, v)
87 self.assertEqual(ar.get(), v)
88 d = ar.get_dict()
89 self.assertEqual(d, {view.targets : v})
90
91 def test_get_dict_bad(self):
92 ar = self.client[:].apply_async(lambda : 5)
93 ar2 = self.client[:].apply_async(lambda : 5)
94 ar = self.client.get_result(ar.msg_ids + ar2.msg_ids)
95 self.assertRaises(ValueError, ar.get_dict)
96
80 def test_list_amr(self):
97 def test_list_amr(self):
81 ar = self.client.load_balanced_view().map_async(wait, [0.1]*5)
98 ar = self.client.load_balanced_view().map_async(wait, [0.1]*5)
82 rlist = list(ar)
99 rlist = list(ar)
General Comments 0
You need to be logged in to leave comments. Login now