mirror of
https://github.com/wassname/ray.git
synced 2026-07-17 11:32:33 +08:00
add valgrind check
This commit is contained in:
+25
-3
@@ -1,6 +1,7 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
@@ -9,6 +10,8 @@ import time
|
||||
|
||||
import photon
|
||||
|
||||
USE_VALGRIND = False
|
||||
|
||||
class TestPhotonClient(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
@@ -18,8 +21,15 @@ class TestPhotonClient(unittest.TestCase):
|
||||
time.sleep(0.1)
|
||||
scheduler_executable = os.path.join(os.path.abspath(os.path.dirname(__file__)), "../build/photon_scheduler")
|
||||
scheduler_name = "/tmp/scheduler{}".format(random.randint(0, 10000))
|
||||
self.p2 = subprocess.Popen([scheduler_executable, "-s", scheduler_name, "-r", "127.0.0.1:6379"])
|
||||
time.sleep(0.1)
|
||||
command = [scheduler_executable, "-s", scheduler_name, "-r", "127.0.0.1:6379"]
|
||||
if USE_VALGRIND:
|
||||
self.p2 = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--show-leak-kinds=all"] + command)
|
||||
else:
|
||||
self.p2 = subprocess.Popen(command)
|
||||
if USE_VALGRIND:
|
||||
time.sleep(1.0)
|
||||
else:
|
||||
time.sleep(0.1)
|
||||
# Connect to the scheduler.
|
||||
self.photon_client = photon.PhotonClient(scheduler_name)
|
||||
|
||||
@@ -27,7 +37,13 @@ class TestPhotonClient(unittest.TestCase):
|
||||
# Kill the Redis server.
|
||||
self.p1.kill()
|
||||
# Kill the local scheduler.
|
||||
self.p2.kill()
|
||||
if USE_VALGRIND:
|
||||
self.p2.send_signal(signal.SIGTERM)
|
||||
self.p2.wait()
|
||||
os._exit(self.p2.returncode)
|
||||
else:
|
||||
self.p2.kill()
|
||||
|
||||
|
||||
def test_create(self):
|
||||
l = [20 * "a", 20 * "b", 20 * "c"]
|
||||
@@ -38,4 +54,10 @@ class TestPhotonClient(unittest.TestCase):
|
||||
task = self.photon_client.get_task()
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
# pop the argument so we don't mess with unittest's own argument parser
|
||||
arg = sys.argv.pop()
|
||||
if arg == "valgrind":
|
||||
USE_VALGRIND = True
|
||||
print("Using valgrind for tests")
|
||||
unittest.main(verbosity=2)
|
||||
|
||||
Reference in New Issue
Block a user