Skip to content

Commit f32c0c8

Browse files
robertnishiharapcmoritz
authored andcommitted
Move calls to ray.worker.cleanup into tearDown part of tests for isolation. (ray-project#1433)
1 parent 4b1c8be commit f32c0c8

File tree

5 files changed

+37
-91
lines changed

5 files changed

+37
-91
lines changed

test/array_test.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717

1818
class RemoteArrayTest(unittest.TestCase):
19+
def tearDown(self):
20+
ray.worker.cleanup()
1921

2022
def testMethods(self):
2123
for module in [ra.core, ra.random, ra.linalg, da.core, da.random,
@@ -48,10 +50,10 @@ def testMethods(self):
4850
r_val = ray.get(r_id)
4951
assert_almost_equal(np.dot(q_val, r_val), a_val)
5052

51-
ray.worker.cleanup()
52-
5353

5454
class DistributedArrayTest(unittest.TestCase):
55+
def tearDown(self):
56+
ray.worker.cleanup()
5557

5658
def testAssemble(self):
5759
for module in [ra.core, ra.random, ra.linalg, da.core, da.random,
@@ -67,8 +69,6 @@ def testAssemble(self):
6769
np.vstack([np.ones([da.BLOCK_SIZE, da.BLOCK_SIZE]),
6870
np.zeros([da.BLOCK_SIZE, da.BLOCK_SIZE])]))
6971

70-
ray.worker.cleanup()
71-
7272
def testMethods(self):
7373
for module in [ra.core, ra.random, ra.linalg, da.core, da.random,
7474
da.linalg]:
@@ -230,8 +230,6 @@ def test_dist_qr(d1, d2):
230230
d2 = np.random.randint(1, 35)
231231
test_dist_qr(d1, d2)
232232

233-
ray.worker.cleanup()
234-
235233

236234
if __name__ == "__main__":
237235
unittest.main(verbosity=2)

test/failure_test.py

+11-23
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def wait_for_errors(error_type, num_errors, timeout=10):
3030

3131

3232
class TaskStatusTest(unittest.TestCase):
33+
def tearDown(self):
34+
ray.worker.cleanup()
35+
3336
def testFailedTask(self):
3437
reload(test_functions)
3538
ray.init(num_workers=3, driver_mode=ray.SILENT_MODE)
@@ -61,8 +64,6 @@ def testFailedTask(self):
6164
# ray.get should throw an exception.
6265
self.assertTrue(False)
6366

64-
ray.worker.cleanup()
65-
6667
def testFailImportingRemoteFunction(self):
6768
ray.init(num_workers=2, driver_mode=ray.SILENT_MODE)
6869

@@ -100,7 +101,6 @@ def g():
100101

101102
# Clean up the junk we added to sys.path.
102103
sys.path.pop(-1)
103-
ray.worker.cleanup()
104104

105105
def testFailedFunctionToRun(self):
106106
ray.init(num_workers=2, driver_mode=ray.SILENT_MODE)
@@ -117,8 +117,6 @@ def f(worker):
117117
self.assertIn(b"Function to run failed.",
118118
ray.error_info()[1][b"message"])
119119

120-
ray.worker.cleanup()
121-
122120
def testFailImportingActor(self):
123121
ray.init(num_workers=2, driver_mode=ray.SILENT_MODE)
124122

@@ -178,10 +176,11 @@ def get_val(self):
178176

179177
# Clean up the junk we added to sys.path.
180178
sys.path.pop(-1)
181-
ray.worker.cleanup()
182179

183180

184181
class ActorTest(unittest.TestCase):
182+
def tearDown(self):
183+
ray.worker.cleanup()
185184

186185
def testFailedActorInit(self):
187186
ray.init(num_workers=0, driver_mode=ray.SILENT_MODE)
@@ -215,8 +214,6 @@ def fail_method(self):
215214
self.assertIn(error_message2,
216215
ray.error_info()[1][b"message"].decode("ascii"))
217216

218-
ray.worker.cleanup()
219-
220217
def testIncorrectMethodCalls(self):
221218
ray.init(num_workers=0, driver_mode=ray.SILENT_MODE)
222219

@@ -254,10 +251,10 @@ def get_val(self, x):
254251
with self.assertRaises(AttributeError):
255252
a.nonexistent_method.remote()
256253

257-
ray.worker.cleanup()
258-
259254

260255
class WorkerDeath(unittest.TestCase):
256+
def tearDown(self):
257+
ray.worker.cleanup()
261258

262259
def testWorkerRaisingException(self):
263260
ray.init(num_workers=1, driver_mode=ray.SILENT_MODE)
@@ -290,8 +287,6 @@ def f():
290287
self.assertIn("A worker died or was killed while executing a task.",
291288
ray.error_info()[0][b"message"].decode("ascii"))
292289

293-
ray.worker.cleanup()
294-
295290
def testActorWorkerDying(self):
296291
ray.init(num_workers=0, driver_mode=ray.SILENT_MODE)
297292

@@ -310,8 +305,6 @@ def consume(x):
310305
self.assertRaises(Exception, lambda: ray.get(consume.remote(obj)))
311306
wait_for_errors(b"worker_died", 1)
312307

313-
ray.worker.cleanup()
314-
315308
def testActorWorkerDyingFutureTasks(self):
316309
ray.init(num_workers=0, driver_mode=ray.SILENT_MODE)
317310

@@ -334,8 +327,6 @@ def sleep(self):
334327

335328
wait_for_errors(b"worker_died", 1)
336329

337-
ray.worker.cleanup()
338-
339330
def testActorWorkerDyingNothingInProgress(self):
340331
ray.init(num_workers=0, driver_mode=ray.SILENT_MODE)
341332

@@ -351,10 +342,10 @@ def getpid(self):
351342
task2 = a.getpid.remote()
352343
self.assertRaises(Exception, lambda: ray.get(task2))
353344

354-
ray.worker.cleanup()
355-
356345

357346
class PutErrorTest(unittest.TestCase):
347+
def tearDown(self):
348+
ray.worker.cleanup()
358349

359350
def testPutError1(self):
360351
store_size = 10 ** 6
@@ -400,8 +391,6 @@ def put_arg_task():
400391
# Make sure we receive the correct error message.
401392
wait_for_errors(b"put_reconstruction", 1)
402393

403-
ray.worker.cleanup()
404-
405394
def testPutError2(self):
406395
# This is the same as the previous test, but it calls ray.put directly.
407396
store_size = 10 ** 6
@@ -446,10 +435,10 @@ def put_task():
446435
# Make sure we receive the correct error message.
447436
wait_for_errors(b"put_reconstruction", 1)
448437

449-
ray.worker.cleanup()
450-
451438

452439
class ConfigurationTest(unittest.TestCase):
440+
def tearDown(self):
441+
ray.worker.cleanup()
453442

454443
def testVersionMismatch(self):
455444
import cloudpickle
@@ -461,7 +450,6 @@ def testVersionMismatch(self):
461450
wait_for_errors(b"version_mismatch", 1)
462451

463452
cloudpickle.__version__ = cloudpickle_version
464-
ray.worker.cleanup()
465453

466454

467455
if __name__ == "__main__":

test/microbenchmarks.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717

1818
class MicroBenchmarkTest(unittest.TestCase):
19+
def tearDown(self):
20+
ray.worker.cleanup()
1921

2022
def testTiming(self):
2123
reload(test_functions)
@@ -89,8 +91,6 @@ def testTiming(self):
8991
print(" worst: {}".format(elapsed_times[999]))
9092
# average_elapsed_time should be about 0.00087.
9193

92-
ray.worker.cleanup()
93-
9494
def testCache(self):
9595
ray.init(num_workers=1)
9696

@@ -115,8 +115,6 @@ def testCache(self):
115115
print("WARNING: The caching test was too slow. "
116116
"d = {}, b = {}".format(d, b))
117117

118-
ray.worker.cleanup()
119-
120118

121119
if __name__ == "__main__":
122120
unittest.main(verbosity=2)

0 commit comments

Comments
 (0)