Skip to content

Commit

Permalink
Make tests more informative (ray-project#372)
Browse files Browse the repository at this point in the history
* Make tests more informative

* Change grpc status checks to warning instead of fatal
  • Loading branch information
robertnishihara authored and pcmoritz committed Aug 11, 2016
1 parent b0ecff6 commit fd35325
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 193 deletions.
6 changes: 5 additions & 1 deletion include/ray/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
if (!(condition)) {\
RAY_LOG(RAY_FATAL, "Check failed at line " << __LINE__ << " in " << __FILE__ << ": " << #condition << " with message " << message) \
}
#define RAY_WARN(condition, message) \
if (!(condition)) {\
RAY_LOG(RAY_INFO, "Check failed at line " << __LINE__ << " in " << __FILE__ << ": " << #condition << " with message " << message) \
}

#define RAY_CHECK_EQ(var1, var2, message) RAY_CHECK((var1) == (var2), message)
#define RAY_CHECK_NEQ(var1, var2, message) RAY_CHECK((var1) != (var2), message)
Expand All @@ -60,5 +64,5 @@ extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
#define RAY_CHECK_GRPC(expr) \
do { \
grpc::Status _s = (expr); \
RAY_CHECK(_s.ok(), "grpc call failed with message " << _s.error_message()); \
RAY_WARN(_s.ok(), "grpc call failed with message " << _s.error_message()); \
} while (0);
46 changes: 21 additions & 25 deletions test/array_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
import ray.array.remote as ra
import ray.array.distributed as da

class RemoteArrayTest(unittest.TestCase):
class TestRemoteArrays(unittest.TestCase):

def testMethods(self):
@classmethod
def setUpClass(cls):
for module in [ra.core, ra.random, ra.linalg, da.core, da.random, da.linalg]:
reload(module)
ray.init(start_ray_local=True)
ray.init(start_ray_local=True, num_workers=1)

@classmethod
def tearDownClass(cls):
ray.worker.cleanup()

def test_methods(self):
# test eye
object_id = ra.eye.remote(3)
val = ray.get(object_id)
Expand All @@ -41,40 +47,32 @@ def testMethods(self):
r_val = ray.get(r_id)
assert_almost_equal(np.dot(q_val, r_val), a_val)

ray.worker.cleanup()

class DistributedArrayTest(unittest.TestCase):
class TestDistributedArrays(unittest.TestCase):

def testSerialization(self):
@classmethod
def setUpClass(cls):
for module in [ra.core, ra.random, ra.linalg, da.core, da.random, da.linalg]:
reload(module)
ray.init(start_ray_local=True, num_workers=0)
ray.init(start_ray_local=True, num_workers=10, num_objstores=2)

@classmethod
def tearDownClass(cls):
ray.worker.cleanup()

def test_serialization(self):
x = da.DistArray([2, 3, 4], np.array([[[ray.put(0)]]]))
capsule, _ = ray.serialization.serialize(ray.worker.global_worker.handle, x)
y = ray.serialization.deserialize(ray.worker.global_worker.handle, capsule)
self.assertEqual(x.shape, y.shape)
self.assertEqual(x.objectids[0, 0, 0].id, y.objectids[0, 0, 0].id)

ray.worker.cleanup()

def testAssemble(self):
for module in [ra.core, ra.random, ra.linalg, da.core, da.random, da.linalg]:
reload(module)
ray.init(start_ray_local=True, num_workers=1)

def test_assemble(self):
a = ra.ones.remote([da.BLOCK_SIZE, da.BLOCK_SIZE])
b = ra.zeros.remote([da.BLOCK_SIZE, da.BLOCK_SIZE])
x = da.DistArray([2 * da.BLOCK_SIZE, da.BLOCK_SIZE], np.array([[a], [b]]))
assert_equal(x.assemble(), np.vstack([np.ones([da.BLOCK_SIZE, da.BLOCK_SIZE]), np.zeros([da.BLOCK_SIZE, da.BLOCK_SIZE])]))

ray.worker.cleanup()

def testMethods(self):
for module in [ra.core, ra.random, ra.linalg, da.core, da.random, da.linalg]:
reload(module)
ray.init(start_ray_local=True, num_objstores=2, num_workers=10)

def test_methods(self):
x = da.zeros.remote([9, 25, 51], "float")
assert_equal(ray.get(da.assemble.remote(x)), np.zeros([9, 25, 51]))

Expand Down Expand Up @@ -207,7 +205,5 @@ def test_dist_qr(d1, d2):
d2 = np.random.randint(1, 35)
test_dist_qr(d1, d2)

ray.worker.cleanup()

if __name__ == "__main__":
unittest.main()
unittest.main(verbosity=2)
14 changes: 9 additions & 5 deletions test/microbenchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@

import test_functions

class MicroBenchmarkTest(unittest.TestCase):
class TestMicroBenchmarks(unittest.TestCase):

def testTiming(self):
@classmethod
def setUpClass(cls):
reload(test_functions)
ray.init(start_ray_local=True, num_workers=3)

@classmethod
def tearDownClass(cls):
ray.worker.cleanup()

def test_timing(self):
# measure the time required to submit a remote task to the scheduler
elapsed_times = []
for _ in range(1000):
Expand Down Expand Up @@ -77,7 +83,5 @@ def testTiming(self):
print " worst: {}".format(elapsed_times[999])
# average_elapsed_time should be about 0.00087

ray.worker.cleanup()

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

0 comments on commit fd35325

Please sign in to comment.