mirror of
https://github.com/wassname/ray.git
synced 2026-07-10 11:00:56 +08:00
API for task log and scheduled task (#25)
* API revision * update * make status a bitmap * update api * tests working * new task log APIs * update APIs * write binary structures to redis * update tests * fix clang-format * Fix formatting.
This commit is contained in:
committed by
Robert Nishihara
parent
084220b0e7
commit
e21e9f68df
@@ -6,11 +6,8 @@ SUITE(common_tests);
|
||||
|
||||
TEST sha1_test(void) {
|
||||
static char hex[2 * UNIQUE_ID_SIZE + 1];
|
||||
static unsigned char id[UNIQUE_ID_SIZE];
|
||||
unique_id uid = globally_unique_id();
|
||||
sha1_to_hex(&uid.id[0], &hex[0]);
|
||||
hex_to_sha1(&hex[0], &id[0]);
|
||||
ASSERT(memcmp(&uid.id[0], &id[0], 20) == 0);
|
||||
PASS();
|
||||
}
|
||||
|
||||
|
||||
+49
-6
@@ -6,7 +6,7 @@
|
||||
#include "test/example_task.h"
|
||||
#include "state/db.h"
|
||||
#include "state/object_table.h"
|
||||
#include "state/task_queue.h"
|
||||
#include "state/task_log.h"
|
||||
#include "state/redis.h"
|
||||
#include "task.h"
|
||||
|
||||
@@ -72,27 +72,70 @@ TEST object_table_lookup_test(void) {
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST task_queue_test(void) {
|
||||
void task_log_test_callback(task_instance *instance, void *userdata) {
|
||||
task_instance *other = userdata;
|
||||
CHECK(*task_instance_state(instance) == TASK_SCHEDULED);
|
||||
CHECK(task_instance_size(instance) == task_instance_size(other));
|
||||
CHECK(memcmp(instance, other, task_instance_size(instance)) == 0);
|
||||
}
|
||||
|
||||
TEST task_log_test(void) {
|
||||
event_loop *loop = event_loop_create();
|
||||
db_handle *db = db_connect("127.0.0.1", 6379, "local_scheduler", "", -1);
|
||||
db_attach(db, loop);
|
||||
|
||||
node_id node = globally_unique_id();
|
||||
task_spec *task = example_task();
|
||||
task_queue_submit_task(db, globally_unique_id(), task);
|
||||
task_instance *instance =
|
||||
make_task_instance(globally_unique_id(), task, TASK_SCHEDULED, node);
|
||||
task_log_register_callback(db, task_log_test_callback, node, TASK_SCHEDULED,
|
||||
instance);
|
||||
task_log_add_task(db, instance);
|
||||
event_loop_add_timer(loop, 100, timeout_handler, NULL);
|
||||
event_loop_run(loop);
|
||||
|
||||
task_instance_free(instance);
|
||||
free_task_spec(task);
|
||||
db_disconnect(db);
|
||||
event_loop_destroy(loop);
|
||||
PASS();
|
||||
}
|
||||
|
||||
int num_test_callback_called = 0;
|
||||
|
||||
void task_log_all_test_callback(task_instance *instance, void *userdata) {
|
||||
num_test_callback_called += 1;
|
||||
}
|
||||
|
||||
TEST task_log_all_test(void) {
|
||||
event_loop *loop = event_loop_create();
|
||||
db_handle *db = db_connect("127.0.0.1", 6379, "local_scheduler", "", -1);
|
||||
db_attach(db, loop);
|
||||
task_spec *task = example_task();
|
||||
/* Schedule two tasks on different nodes. */
|
||||
task_instance *instance1 = make_task_instance(
|
||||
globally_unique_id(), task, TASK_SCHEDULED, globally_unique_id());
|
||||
task_instance *instance2 = make_task_instance(
|
||||
globally_unique_id(), task, TASK_SCHEDULED, globally_unique_id());
|
||||
task_log_register_callback(db, task_log_all_test_callback, NIL_ID,
|
||||
TASK_SCHEDULED, NULL);
|
||||
task_log_add_task(db, instance1);
|
||||
task_log_add_task(db, instance2);
|
||||
event_loop_add_timer(loop, 100, timeout_handler, NULL);
|
||||
event_loop_run(loop);
|
||||
task_instance_free(instance2);
|
||||
task_instance_free(instance1);
|
||||
free_task_spec(task);
|
||||
db_disconnect(db);
|
||||
event_loop_destroy(loop);
|
||||
ASSERT(num_test_callback_called == 2);
|
||||
PASS();
|
||||
}
|
||||
|
||||
SUITE(db_tests) {
|
||||
redisContext *context = redisConnect("127.0.0.1", 6379);
|
||||
freeReplyObject(redisCommand(context, "FLUSHALL"));
|
||||
RUN_REDIS_TEST(context, object_table_lookup_test);
|
||||
RUN_REDIS_TEST(context, task_queue_test);
|
||||
RUN_REDIS_TEST(context, task_log_test);
|
||||
RUN_REDIS_TEST(context, task_log_all_test);
|
||||
redisFree(context);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,28 +63,9 @@ TEST send_task(void) {
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST print_and_parse_task(void) {
|
||||
task_spec *task = example_task();
|
||||
|
||||
UT_string *output;
|
||||
utstring_new(output);
|
||||
print_task(task, output);
|
||||
task_spec *result = parse_task(utstring_body(output), utstring_len(output));
|
||||
utstring_free(output);
|
||||
|
||||
ASSERT_EQ(task_size(task), task_size(result));
|
||||
ASSERT(memcmp(task, result, task_size(task)) == 0);
|
||||
|
||||
free_task_spec(task);
|
||||
free_task_spec(result);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
SUITE(task_tests) {
|
||||
RUN_TEST(task_test);
|
||||
RUN_TEST(send_task);
|
||||
RUN_TEST(print_and_parse_task);
|
||||
}
|
||||
|
||||
GREATEST_MAIN_DEFS();
|
||||
|
||||
Reference in New Issue
Block a user