mirror of
https://github.com/wassname/ray.git
synced 2026-08-11 11:24:51 +08:00
[WIP] Fix valgrind tests. (#5)
* Make tests fail when valgrind finds a memory leak. * Properly clean up scheduler state. * Remove unnecessary malloc.
This commit is contained in:
committed by
Philipp Moritz
parent
f83a98d71a
commit
6f75c738b5
@@ -37,6 +37,11 @@ scheduler_state *make_scheduler_state(void) {
|
||||
}
|
||||
|
||||
void free_scheduler_state(scheduler_state *s) {
|
||||
for (int i = 0; i < utarray_len(s->task_queue); ++i) {
|
||||
task_instance **instance =
|
||||
(task_instance **) utarray_eltptr(s->task_queue, i);
|
||||
free(*instance);
|
||||
}
|
||||
utarray_free(s->task_queue);
|
||||
utarray_free(s->available_workers);
|
||||
free(s);
|
||||
|
||||
@@ -73,6 +73,13 @@ local_scheduler_state *init_local_scheduler(event_loop *loop,
|
||||
|
||||
void free_local_scheduler(local_scheduler_state *s) {
|
||||
db_disconnect(s->scheduler_info->db);
|
||||
free(s->plasma_conn);
|
||||
worker_index *current_worker_index, *temp_worker_index;
|
||||
HASH_ITER(hh, s->worker_index, current_worker_index, temp_worker_index) {
|
||||
HASH_DEL(s->worker_index, current_worker_index);
|
||||
free(current_worker_index);
|
||||
}
|
||||
utarray_free(s->scheduler_info->workers);
|
||||
free(s->scheduler_info);
|
||||
free_scheduler_state(s->scheduler_state);
|
||||
event_loop_destroy(s->loop);
|
||||
@@ -93,10 +100,9 @@ void process_plasma_notification(event_loop *loop,
|
||||
int events) {
|
||||
local_scheduler_state *s = context;
|
||||
/* Read the notification from Plasma. */
|
||||
uint8_t *message = (uint8_t *) malloc(sizeof(object_id));
|
||||
recv(client_sock, message, sizeof(object_id), 0);
|
||||
object_id *obj_id = (object_id *) message;
|
||||
handle_object_available(s->scheduler_info, s->scheduler_state, *obj_id);
|
||||
object_id obj_id;
|
||||
recv(client_sock, &obj_id, sizeof(object_id), 0);
|
||||
handle_object_available(s->scheduler_info, s->scheduler_state, obj_id);
|
||||
}
|
||||
|
||||
void process_message(event_loop *loop, int client_sock, void *context,
|
||||
|
||||
@@ -30,7 +30,7 @@ class TestPhotonClient(unittest.TestCase):
|
||||
scheduler_name = "/tmp/scheduler{}".format(random.randint(0, 10000))
|
||||
command = [scheduler_executable, "-s", scheduler_name, "-r", "127.0.0.1:6379", "-p", plasma_socket]
|
||||
if USE_VALGRIND:
|
||||
self.p3 = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--show-leak-kinds=all"] + command)
|
||||
self.p3 = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--show-leak-kinds=all", "--error-exitcode=1"] + command)
|
||||
else:
|
||||
self.p3 = subprocess.Popen(command)
|
||||
if USE_VALGRIND:
|
||||
|
||||
@@ -60,7 +60,7 @@ class TestPlasmaClient(unittest.TestCase):
|
||||
store_name = "/tmp/store{}".format(random.randint(0, 10000))
|
||||
command = [plasma_store_executable, "-s", store_name]
|
||||
if USE_VALGRIND:
|
||||
self.p = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full"] + command)
|
||||
self.p = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--show-leak-kinds=all", "--error-exitcode=1"] + command)
|
||||
time.sleep(2.0)
|
||||
else:
|
||||
self.p = subprocess.Popen(command)
|
||||
@@ -216,8 +216,8 @@ class TestPlasmaManager(unittest.TestCase):
|
||||
plasma_store_command2 = [plasma_store_executable, "-s", store_name2]
|
||||
|
||||
if USE_VALGRIND:
|
||||
self.p2 = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--error-exitcode=1"] + plasma_store_command1)
|
||||
self.p3 = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--error-exitcode=1"] + plasma_store_command2)
|
||||
self.p2 = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--show-leak-kinds=all", "--error-exitcode=1"] + plasma_store_command1)
|
||||
self.p3 = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--show-leak-kinds=all", "--error-exitcode=1"] + plasma_store_command2)
|
||||
else:
|
||||
self.p2 = subprocess.Popen(plasma_store_command1)
|
||||
self.p3 = subprocess.Popen(plasma_store_command2)
|
||||
@@ -250,8 +250,8 @@ class TestPlasmaManager(unittest.TestCase):
|
||||
"-p", str(self.port2)] + manager_redis_args
|
||||
|
||||
if USE_VALGRIND:
|
||||
self.p4 = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--error-exitcode=1"] + plasma_manager_command1)
|
||||
self.p5 = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--error-exitcode=1"] + plasma_manager_command2)
|
||||
self.p4 = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--show-leak-kinds=all", "--error-exitcode=1"] + plasma_manager_command1)
|
||||
self.p5 = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--show-leak-kinds=all", "--error-exitcode=1"] + plasma_manager_command2)
|
||||
time.sleep(2.0)
|
||||
else:
|
||||
self.p4 = subprocess.Popen(plasma_manager_command1)
|
||||
|
||||
Reference in New Issue
Block a user