##// END OF EJS Templates
test new AsyncResult properties
MinRK -
Show More
@@ -16,10 +16,11 b' Authors:'
16 # Imports
16 # Imports
17 #-------------------------------------------------------------------------------
17 #-------------------------------------------------------------------------------
18
18
19 import time
19
20
20 from IPython.parallel.error import TimeoutError
21 from IPython.parallel.error import TimeoutError
21
22
22 from IPython.parallel import error
23 from IPython.parallel import error, Client
23 from IPython.parallel.tests import add_engines
24 from IPython.parallel.tests import add_engines
24 from .clienttest import ClusterTestCase
25 from .clienttest import ClusterTestCase
25
26
@@ -122,4 +123,83 b' class AsyncResultTest(ClusterTestCase):'
122 self.assertRaises(error.TaskAborted, ar2.get)
123 self.assertRaises(error.TaskAborted, ar2.get)
123 ar.get()
124 ar.get()
124
125
126 def test_len(self):
127 v = self.client.load_balanced_view()
128 ar = v.map_async(lambda x: x, range(10))
129 self.assertEquals(len(ar), 10)
130 ar = v.apply_async(lambda x: x, range(10))
131 self.assertEquals(len(ar), 1)
132 ar = self.client[:].apply_async(lambda x: x, range(10))
133 self.assertEquals(len(ar), len(self.client.ids))
134
135 def test_wall_time_single(self):
136 v = self.client.load_balanced_view()
137 ar = v.apply_async(time.sleep, 0.25)
138 self.assertRaises(TimeoutError, getattr, ar, 'wall_time')
139 ar.get(2)
140 self.assertTrue(ar.wall_time < 1.)
141 self.assertTrue(ar.wall_time > 0.2)
142
143 def test_wall_time_multi(self):
144 self.minimum_engines(4)
145 v = self.client[:]
146 ar = v.apply_async(time.sleep, 0.25)
147 self.assertRaises(TimeoutError, getattr, ar, 'wall_time')
148 ar.get(2)
149 self.assertTrue(ar.wall_time < 1.)
150 self.assertTrue(ar.wall_time > 0.2)
151
152 def test_serial_time_single(self):
153 v = self.client.load_balanced_view()
154 ar = v.apply_async(time.sleep, 0.25)
155 self.assertRaises(TimeoutError, getattr, ar, 'serial_time')
156 ar.get(2)
157 self.assertTrue(ar.serial_time < 0.5)
158 self.assertTrue(ar.serial_time > 0.2)
159
160 def test_serial_time_multi(self):
161 self.minimum_engines(4)
162 v = self.client[:]
163 ar = v.apply_async(time.sleep, 0.25)
164 self.assertRaises(TimeoutError, getattr, ar, 'serial_time')
165 ar.get(2)
166 self.assertTrue(ar.serial_time < 2.)
167 self.assertTrue(ar.serial_time > 0.8)
168
169 def test_elapsed_single(self):
170 v = self.client.load_balanced_view()
171 ar = v.apply_async(time.sleep, 0.25)
172 while not ar.ready():
173 time.sleep(0.01)
174 self.assertTrue(ar.elapsed < 0.3)
175 self.assertTrue(ar.elapsed < 0.3)
176 ar.get(2)
177
178 def test_elapsed_multi(self):
179 v = self.client[:]
180 ar = v.apply_async(time.sleep, 0.25)
181 while not ar.ready():
182 time.sleep(0.01)
183 self.assertTrue(ar.elapsed < 0.3)
184 self.assertTrue(ar.elapsed < 0.3)
185 ar.get(2)
186
187 def test_hubresult_timestamps(self):
188 self.minimum_engines(4)
189 v = self.client[:]
190 ar = v.apply_async(time.sleep, 0.25)
191 ar.get(2)
192 rc2 = Client(profile='iptest')
193 # must have try/finally to close second Client, otherwise
194 # will have dangling sockets causing problems
195 try:
196 time.sleep(0.25)
197 hr = rc2.get_result(ar.msg_ids)
198 self.assertTrue(hr.elapsed > 0., "got bad elapsed: %s" % hr.elapsed)
199 hr.get(1)
200 self.assertTrue(hr.wall_time < ar.wall_time + 0.2, "got bad wall_time: %s > %s" % (hr.wall_time, ar.wall_time))
201 self.assertEquals(hr.serial_time, ar.serial_time)
202 finally:
203 rc2.close()
204
125
205
General Comments 0
You need to be logged in to leave comments. Login now