mirror of
https://github.com/wassname/ray.git
synced 2026-07-23 13:10:11 +08:00
Merge task table and task log into a single table (#30)
* Merge task table and task log * Fix test in db tests * Address Robert's comments and some better error checking * Add a LOG_FATAL that exits the program
This commit is contained in:
committed by
Philipp Moritz
parent
194bdb1d96
commit
9d1e750e8f
@@ -12,6 +12,132 @@ SUITE(object_table_tests);
|
||||
|
||||
static event_loop *g_loop;
|
||||
|
||||
/* ==== Test adding and looking up metadata ==== */
|
||||
|
||||
int new_object_failed = 0;
|
||||
int new_object_succeeded = 0;
|
||||
object_id new_object_id;
|
||||
task *new_object_task;
|
||||
task_spec *new_object_task_spec;
|
||||
task_id new_object_task_id;
|
||||
|
||||
void new_object_fail_callback(unique_id id,
|
||||
void *user_context,
|
||||
void *user_data) {
|
||||
new_object_failed = 1;
|
||||
event_loop_stop(g_loop);
|
||||
}
|
||||
|
||||
/* === Test adding an object with an associated task === */
|
||||
|
||||
void new_object_done_callback(object_id object_id,
|
||||
task *task,
|
||||
void *user_context) {
|
||||
new_object_succeeded = 1;
|
||||
CHECK(object_ids_equal(object_id, new_object_id));
|
||||
CHECK(task);
|
||||
CHECK(memcmp(task, new_object_task, task_size(task)) == 0);
|
||||
event_loop_stop(g_loop);
|
||||
}
|
||||
|
||||
void new_object_lookup_callback(object_id object_id, void *user_context) {
|
||||
CHECK(object_ids_equal(object_id, new_object_id));
|
||||
retry_info retry = {
|
||||
.num_retries = 5,
|
||||
.timeout = 100,
|
||||
.fail_callback = new_object_fail_callback,
|
||||
};
|
||||
db_handle *db = user_context;
|
||||
result_table_lookup(db, new_object_id, &retry, new_object_done_callback,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void new_object_task_callback(task_id task_id, void *user_context) {
|
||||
retry_info retry = {
|
||||
.num_retries = 5,
|
||||
.timeout = 100,
|
||||
.fail_callback = new_object_fail_callback,
|
||||
};
|
||||
db_handle *db = user_context;
|
||||
result_table_add(db, new_object_id, new_object_task_id, &retry,
|
||||
new_object_lookup_callback, (void *) db);
|
||||
}
|
||||
|
||||
TEST new_object_test(void) {
|
||||
new_object_failed = 0;
|
||||
new_object_succeeded = 0;
|
||||
new_object_id = globally_unique_id();
|
||||
new_object_task = example_task();
|
||||
new_object_task_spec = task_task_spec(new_object_task);
|
||||
new_object_task_id = task_spec_id(new_object_task_spec);
|
||||
g_loop = event_loop_create();
|
||||
db_handle *db =
|
||||
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 1234);
|
||||
db_attach(db, g_loop);
|
||||
retry_info retry = {
|
||||
.num_retries = 5,
|
||||
.timeout = 100,
|
||||
.fail_callback = new_object_fail_callback,
|
||||
};
|
||||
task_table_add_task(db, new_object_task, &retry, new_object_task_callback,
|
||||
db);
|
||||
event_loop_run(g_loop);
|
||||
db_disconnect(db);
|
||||
destroy_outstanding_callbacks(g_loop);
|
||||
event_loop_destroy(g_loop);
|
||||
free_task(new_object_task);
|
||||
ASSERT(new_object_succeeded);
|
||||
ASSERT(!new_object_failed);
|
||||
PASS();
|
||||
}
|
||||
|
||||
/* === Test adding an object without an associated task === */
|
||||
|
||||
void new_object_no_task_lookup_callback(object_id object_id,
|
||||
task *task,
|
||||
void *user_context) {
|
||||
new_object_succeeded = 1;
|
||||
CHECK(task == NULL);
|
||||
event_loop_stop(g_loop);
|
||||
}
|
||||
|
||||
void new_object_no_task_callback(object_id object_id, void *user_context) {
|
||||
CHECK(node_ids_equal(object_id, new_object_id));
|
||||
retry_info retry = {
|
||||
.num_retries = 5,
|
||||
.timeout = 100,
|
||||
.fail_callback = new_object_fail_callback,
|
||||
};
|
||||
db_handle *db = user_context;
|
||||
result_table_lookup(db, object_id, &retry, new_object_no_task_lookup_callback,
|
||||
NULL);
|
||||
}
|
||||
|
||||
TEST new_object_no_task_test(void) {
|
||||
new_object_failed = 0;
|
||||
new_object_succeeded = 0;
|
||||
new_object_id = globally_unique_id();
|
||||
new_object_task_id = globally_unique_id();
|
||||
g_loop = event_loop_create();
|
||||
db_handle *db =
|
||||
db_connect("127.0.0.1", 6379, "plasma_manager", "127.0.0.1", 1234);
|
||||
db_attach(db, g_loop);
|
||||
retry_info retry = {
|
||||
.num_retries = 5,
|
||||
.timeout = 100,
|
||||
.fail_callback = new_object_fail_callback,
|
||||
};
|
||||
result_table_add(db, new_object_id, new_object_task_id, &retry,
|
||||
new_object_no_task_callback, db);
|
||||
event_loop_run(g_loop);
|
||||
db_disconnect(db);
|
||||
destroy_outstanding_callbacks(g_loop);
|
||||
event_loop_destroy(g_loop);
|
||||
ASSERT(new_object_succeeded);
|
||||
ASSERT(!new_object_failed);
|
||||
PASS();
|
||||
}
|
||||
|
||||
/* ==== Test if operations time out correctly ==== */
|
||||
|
||||
/* === Test lookup timeout === */
|
||||
@@ -27,9 +153,9 @@ void lookup_done_callback(object_id object_id,
|
||||
CHECK(0);
|
||||
}
|
||||
|
||||
void lookup_fail_callback(unique_id id, void *user_data) {
|
||||
void lookup_fail_callback(unique_id id, void *user_context, void *user_data) {
|
||||
lookup_failed = 1;
|
||||
CHECK(user_data == (void *) lookup_timeout_context);
|
||||
CHECK(user_context == (void *) lookup_timeout_context);
|
||||
event_loop_stop(g_loop);
|
||||
}
|
||||
|
||||
@@ -63,9 +189,9 @@ void add_done_callback(object_id object_id, void *user_context) {
|
||||
CHECK(0);
|
||||
}
|
||||
|
||||
void add_fail_callback(unique_id id, void *user_data) {
|
||||
void add_fail_callback(unique_id id, void *user_context, void *user_data) {
|
||||
add_failed = 1;
|
||||
CHECK(user_data == (void *) add_timeout_context);
|
||||
CHECK(user_context == (void *) add_timeout_context);
|
||||
event_loop_stop(g_loop);
|
||||
}
|
||||
|
||||
@@ -99,9 +225,11 @@ void subscribe_done_callback(object_id object_id, void *user_context) {
|
||||
CHECK(0);
|
||||
}
|
||||
|
||||
void subscribe_fail_callback(unique_id id, void *user_data) {
|
||||
void subscribe_fail_callback(unique_id id,
|
||||
void *user_context,
|
||||
void *user_data) {
|
||||
subscribe_failed = 1;
|
||||
CHECK(user_data == (void *) subscribe_timeout_context);
|
||||
CHECK(user_context == (void *) subscribe_timeout_context);
|
||||
event_loop_stop(g_loop);
|
||||
}
|
||||
|
||||
@@ -166,7 +294,9 @@ void lookup_retry_done_callback(object_id object_id,
|
||||
free(manager_vector);
|
||||
}
|
||||
|
||||
void lookup_retry_fail_callback(unique_id id, void *user_data) {
|
||||
void lookup_retry_fail_callback(unique_id id,
|
||||
void *user_context,
|
||||
void *user_data) {
|
||||
/* The fail callback should not be called. */
|
||||
CHECK(0);
|
||||
}
|
||||
@@ -210,7 +340,9 @@ void add_retry_done_callback(object_id object_id, void *user_context) {
|
||||
add_retry_succeeded = 1;
|
||||
}
|
||||
|
||||
void add_retry_fail_callback(unique_id id, void *user_data) {
|
||||
void add_retry_fail_callback(unique_id id,
|
||||
void *user_context,
|
||||
void *user_data) {
|
||||
/* The fail callback should not be called. */
|
||||
CHECK(0);
|
||||
}
|
||||
@@ -269,7 +401,9 @@ void subscribe_retry_done_callback(object_id object_id, void *user_context) {
|
||||
subscribe_retry_succeeded = 1;
|
||||
}
|
||||
|
||||
void subscribe_retry_fail_callback(unique_id id, void *user_data) {
|
||||
void subscribe_retry_fail_callback(unique_id id,
|
||||
void *user_context,
|
||||
void *user_data) {
|
||||
/* The fail callback should not be called. */
|
||||
CHECK(0);
|
||||
}
|
||||
@@ -312,7 +446,9 @@ TEST subscribe_retry_test(void) {
|
||||
const char *lookup_late_context = "lookup_late";
|
||||
int lookup_late_failed = 0;
|
||||
|
||||
void lookup_late_fail_callback(unique_id id, void *user_context) {
|
||||
void lookup_late_fail_callback(unique_id id,
|
||||
void *user_context,
|
||||
void *user_data) {
|
||||
CHECK(user_context == (void *) lookup_late_context);
|
||||
lookup_late_failed = 1;
|
||||
}
|
||||
@@ -357,7 +493,7 @@ TEST lookup_late_test(void) {
|
||||
const char *add_late_context = "add_late";
|
||||
int add_late_failed = 0;
|
||||
|
||||
void add_late_fail_callback(unique_id id, void *user_context) {
|
||||
void add_late_fail_callback(unique_id id, void *user_context, void *user_data) {
|
||||
CHECK(user_context == (void *) add_late_context);
|
||||
add_late_failed = 1;
|
||||
}
|
||||
@@ -397,7 +533,9 @@ TEST add_late_test(void) {
|
||||
const char *subscribe_late_context = "subscribe_late";
|
||||
int subscribe_late_failed = 0;
|
||||
|
||||
void subscribe_late_fail_callback(unique_id id, void *user_context) {
|
||||
void subscribe_late_fail_callback(unique_id id,
|
||||
void *user_context,
|
||||
void *user_data) {
|
||||
CHECK(user_context == (void *) subscribe_late_context);
|
||||
subscribe_late_failed = 1;
|
||||
}
|
||||
@@ -441,7 +579,9 @@ const char *subscribe_success_context = "subscribe_success";
|
||||
int subscribe_success_done = 0;
|
||||
int subscribe_success_succeeded = 0;
|
||||
|
||||
void subscribe_success_fail_callback(unique_id id, void *user_context) {
|
||||
void subscribe_success_fail_callback(unique_id id,
|
||||
void *user_context,
|
||||
void *user_data) {
|
||||
/* This function should never be called. */
|
||||
CHECK(0);
|
||||
}
|
||||
@@ -492,16 +632,18 @@ TEST subscribe_success_test(void) {
|
||||
}
|
||||
|
||||
SUITE(object_table_tests) {
|
||||
RUN_TEST(lookup_timeout_test);
|
||||
RUN_TEST(add_timeout_test);
|
||||
RUN_TEST(subscribe_timeout_test);
|
||||
RUN_TEST(lookup_retry_test);
|
||||
RUN_TEST(add_retry_test);
|
||||
RUN_TEST(subscribe_retry_test);
|
||||
RUN_TEST(lookup_late_test);
|
||||
RUN_TEST(add_late_test);
|
||||
RUN_TEST(subscribe_late_test);
|
||||
RUN_TEST(subscribe_success_test);
|
||||
RUN_REDIS_TEST(new_object_test);
|
||||
RUN_REDIS_TEST(new_object_no_task_test);
|
||||
RUN_REDIS_TEST(lookup_timeout_test);
|
||||
RUN_REDIS_TEST(add_timeout_test);
|
||||
RUN_REDIS_TEST(subscribe_timeout_test);
|
||||
RUN_REDIS_TEST(lookup_retry_test);
|
||||
RUN_REDIS_TEST(add_retry_test);
|
||||
RUN_REDIS_TEST(subscribe_retry_test);
|
||||
RUN_REDIS_TEST(lookup_late_test);
|
||||
RUN_REDIS_TEST(add_late_test);
|
||||
RUN_REDIS_TEST(subscribe_late_test);
|
||||
RUN_REDIS_TEST(subscribe_success_test);
|
||||
}
|
||||
|
||||
GREATEST_MAIN_DEFS();
|
||||
|
||||
Reference in New Issue
Block a user