Second Part of Internal API Refactor (#1326)

This commit is contained in:
Philipp Moritz
2017-12-26 16:22:04 -08:00
committed by Robert Nishihara
parent 4bb5b6bd5b
commit 3d224c4edf
58 changed files with 537 additions and 677 deletions
-24
View File
@@ -1,24 +0,0 @@
#include "greatest.h"
#include "common.h"
SUITE(common_tests);
TEST sha1_test(void) {
static char hex[ID_STRING_SIZE];
UniqueID uid = globally_unique_id();
ObjectID_to_string((ObjectID) uid, &hex[0], ID_STRING_SIZE);
PASS();
}
SUITE(common_tests) {
RUN_TEST(sha1_test);
}
GREATEST_MAIN_DEFS();
int main(int argc, char **argv) {
GREATEST_MAIN_BEGIN();
RUN_SUITE(common_tests);
GREATEST_MAIN_END();
}
+8 -6
View File
@@ -81,7 +81,7 @@ TEST object_table_lookup_test(void) {
manager_addr, db_connect_args2);
db_attach(db1, loop, false);
db_attach(db2, loop, false);
UniqueID id = globally_unique_id();
UniqueID id = UniqueID::from_random();
RetryInfo retry = {
.num_retries = NUM_RETRIES,
.timeout = TIMEOUT,
@@ -149,7 +149,7 @@ TEST task_table_test(void) {
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "local_scheduler",
"127.0.0.1", std::vector<std::string>());
db_attach(db, loop, false);
DBClientID local_scheduler_id = globally_unique_id();
DBClientID local_scheduler_id = DBClientID::from_random();
TaskExecutionSpec spec = example_task_execution_spec(1, 1);
task_table_test_task =
Task_alloc(spec, TASK_STATUS_SCHEDULED, local_scheduler_id);
@@ -185,12 +185,14 @@ TEST task_table_all_test(void) {
db_attach(db, loop, false);
TaskExecutionSpec spec = example_task_execution_spec(1, 1);
/* Schedule two tasks on different local local schedulers. */
Task *task1 = Task_alloc(spec, TASK_STATUS_SCHEDULED, globally_unique_id());
Task *task2 = Task_alloc(spec, TASK_STATUS_SCHEDULED, globally_unique_id());
Task *task1 =
Task_alloc(spec, TASK_STATUS_SCHEDULED, DBClientID::from_random());
Task *task2 =
Task_alloc(spec, TASK_STATUS_SCHEDULED, DBClientID::from_random());
RetryInfo retry = {
.num_retries = NUM_RETRIES, .timeout = TIMEOUT, .fail_callback = NULL,
};
task_table_subscribe(db, NIL_ID, TASK_STATUS_SCHEDULED,
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_SCHEDULED,
task_table_all_test_callback, NULL, &retry, NULL, NULL);
event_loop_add_timer(loop, 50, (event_loop_timer_handler) timeout_handler,
NULL);
@@ -221,7 +223,7 @@ TEST unique_client_id_test(void) {
}
for (int i = 0; i < num_conns; ++i) {
for (int j = 0; j < i; ++j) {
ASSERT(!DBClientID_equal(ids[i], ids[j]));
ASSERT(!(ids[i] == ids[j]));
}
}
PASS();
+8 -8
View File
@@ -11,15 +11,15 @@ static inline TaskExecutionSpec example_task_execution_spec_with_args(
int64_t num_args,
int64_t num_returns,
ObjectID arg_ids[]) {
TaskID parent_task_id = globally_unique_id();
FunctionID func_id = globally_unique_id();
TaskSpec_start_construct(g_task_builder, NIL_ID, parent_task_id, 0,
NIL_ACTOR_ID, NIL_ACTOR_ID, 0, false, func_id,
TaskID parent_task_id = TaskID::from_random();
FunctionID func_id = FunctionID::from_random();
TaskSpec_start_construct(g_task_builder, UniqueID::nil(), parent_task_id, 0,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
num_returns);
for (int64_t i = 0; i < num_args; ++i) {
ObjectID arg_id;
if (arg_ids == NULL) {
arg_id = globally_unique_id();
arg_id = ObjectID::from_random();
} else {
arg_id = arg_ids[i];
}
@@ -46,7 +46,7 @@ static inline Task *example_task_with_args(int64_t num_args,
ObjectID arg_ids[]) {
TaskExecutionSpec spec =
example_task_execution_spec_with_args(num_args, num_returns, arg_ids);
Task *instance = Task_alloc(spec, task_state, NIL_ID);
Task *instance = Task_alloc(spec, task_state, UniqueID::nil());
return instance;
}
@@ -54,7 +54,7 @@ static inline Task *example_task(int64_t num_args,
int64_t num_returns,
int task_state) {
TaskExecutionSpec spec = example_task_execution_spec(num_args, num_returns);
Task *instance = Task_alloc(spec, task_state, NIL_ID);
Task *instance = Task_alloc(spec, task_state, UniqueID::nil());
return instance;
}
@@ -62,7 +62,7 @@ static inline bool Task_equals(Task *task1, Task *task2) {
if (task1->state != task2->state) {
return false;
}
if (!DBClientID_equal(task1->local_scheduler_id, task2->local_scheduler_id)) {
if (!(task1->local_scheduler_id == task2->local_scheduler_id)) {
return false;
}
auto execution_spec1 = Task_task_execution_spec(task1);
+26 -25
View File
@@ -38,13 +38,13 @@ void new_object_done_callback(ObjectID object_id,
bool is_put,
void *user_context) {
new_object_succeeded = 1;
CHECK(ObjectID_equal(object_id, new_object_id));
CHECK(TaskID_equal(task_id, new_object_task_id));
CHECK(object_id == new_object_id);
CHECK(task_id == new_object_task_id);
event_loop_stop(g_loop);
}
void new_object_lookup_callback(ObjectID object_id, void *user_context) {
CHECK(ObjectID_equal(object_id, new_object_id));
CHECK(object_id == new_object_id);
RetryInfo retry = {
.num_retries = 5,
.timeout = 100,
@@ -78,7 +78,7 @@ void task_table_subscribe_done(TaskID task_id, void *user_context) {
TEST new_object_test(void) {
new_object_failed = 0;
new_object_succeeded = 0;
new_object_id = globally_unique_id();
new_object_id = ObjectID::from_random();
new_object_task = example_task(1, 1, TASK_STATUS_WAITING);
new_object_task_spec = Task_task_execution_spec(new_object_task)->Spec();
new_object_task_id = TaskSpec_task_id(new_object_task_spec);
@@ -91,8 +91,8 @@ TEST new_object_test(void) {
.timeout = 100,
.fail_callback = new_object_fail_callback,
};
task_table_subscribe(db, NIL_ID, TASK_STATUS_WAITING, NULL, NULL, &retry,
task_table_subscribe_done, db);
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
&retry, task_table_subscribe_done, db);
event_loop_run(g_loop);
db_disconnect(db);
destroy_outstanding_callbacks(g_loop);
@@ -109,15 +109,15 @@ void new_object_no_task_callback(ObjectID object_id,
bool is_put,
void *user_context) {
new_object_succeeded = 1;
CHECK(IS_NIL_ID(task_id));
CHECK(task_id.is_nil());
event_loop_stop(g_loop);
}
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();
new_object_id = ObjectID::from_random();
new_object_task_id = TaskID::from_random();
g_loop = event_loop_create();
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
"127.0.0.1", std::vector<std::string>());
@@ -167,7 +167,7 @@ TEST lookup_timeout_test(void) {
RetryInfo retry = {
.num_retries = 5, .timeout = 100, .fail_callback = lookup_fail_callback,
};
object_table_lookup(db, NIL_ID, &retry, lookup_done_callback,
object_table_lookup(db, UniqueID::nil(), &retry, lookup_done_callback,
(void *) lookup_timeout_context);
/* Disconnect the database to see if the lookup times out. */
close(db->context->c.fd);
@@ -206,7 +206,7 @@ TEST add_timeout_test(void) {
RetryInfo retry = {
.num_retries = 5, .timeout = 100, .fail_callback = add_fail_callback,
};
object_table_add(db, NIL_ID, 0, (unsigned char *) NIL_DIGEST, &retry,
object_table_add(db, UniqueID::nil(), 0, (unsigned char *) NIL_DIGEST, &retry,
add_done_callback, (void *) add_timeout_context);
/* Disconnect the database to see if the lookup times out. */
close(db->context->c.fd);
@@ -327,7 +327,7 @@ void add_lookup_callback(ObjectID object_id, bool success, void *user_context) {
.timeout = 100,
.fail_callback = lookup_retry_fail_callback,
};
object_table_lookup(db, NIL_ID, &retry, add_lookup_done_callback,
object_table_lookup(db, UniqueID::nil(), &retry, add_lookup_done_callback,
(void *) db);
}
@@ -346,7 +346,7 @@ TEST add_lookup_test(void) {
.timeout = 100,
.fail_callback = lookup_retry_fail_callback,
};
object_table_add(db, NIL_ID, 0, (unsigned char *) NIL_DIGEST, &retry,
object_table_add(db, UniqueID::nil(), 0, (unsigned char *) NIL_DIGEST, &retry,
add_lookup_callback, (void *) db);
/* Install handler for terminating the event loop. */
event_loop_add_timer(g_loop, 750,
@@ -381,7 +381,8 @@ void add_remove_lookup_callback(ObjectID object_id,
.timeout = 100,
.fail_callback = lookup_retry_fail_callback,
};
object_table_lookup(db, NIL_ID, &retry, add_remove_lookup_done_callback,
object_table_lookup(db, UniqueID::nil(), &retry,
add_remove_lookup_done_callback,
(void *) lookup_retry_context);
}
@@ -393,8 +394,8 @@ void add_remove_callback(ObjectID object_id, bool success, void *user_context) {
.timeout = 100,
.fail_callback = lookup_retry_fail_callback,
};
object_table_remove(db, NIL_ID, NULL, &retry, add_remove_lookup_callback,
(void *) db);
object_table_remove(db, UniqueID::nil(), NULL, &retry,
add_remove_lookup_callback, (void *) db);
}
TEST add_remove_lookup_test(void) {
@@ -408,7 +409,7 @@ TEST add_remove_lookup_test(void) {
.timeout = 100,
.fail_callback = lookup_retry_fail_callback,
};
object_table_add(db, NIL_ID, 0, (unsigned char *) NIL_DIGEST, &retry,
object_table_add(db, UniqueID::nil(), 0, (unsigned char *) NIL_DIGEST, &retry,
add_remove_callback, (void *) db);
/* Install handler for terminating the event loop. */
event_loop_add_timer(g_loop, 750,
@@ -454,7 +455,7 @@ TEST lookup_late_test(void) {
.timeout = 0,
.fail_callback = lookup_late_fail_callback,
};
object_table_lookup(db, NIL_ID, &retry, lookup_late_done_callback,
object_table_lookup(db, UniqueID::nil(), &retry, lookup_late_done_callback,
(void *) lookup_late_context);
/* Install handler for terminating the event loop. */
event_loop_add_timer(g_loop, 750,
@@ -496,7 +497,7 @@ TEST add_late_test(void) {
RetryInfo retry = {
.num_retries = 0, .timeout = 0, .fail_callback = add_late_fail_callback,
};
object_table_add(db, NIL_ID, 0, (unsigned char *) NIL_DIGEST, &retry,
object_table_add(db, UniqueID::nil(), 0, (unsigned char *) NIL_DIGEST, &retry,
add_late_done_callback, (void *) add_late_context);
/* Install handler for terminating the event loop. */
event_loop_add_timer(g_loop, 750,
@@ -594,7 +595,7 @@ void subscribe_success_object_available_callback(
const std::vector<DBClientID> &manager_vector,
void *user_context) {
CHECK(user_context == (void *) subscribe_success_context);
CHECK(ObjectID_equal(object_id, subscribe_id));
CHECK(object_id == subscribe_id);
CHECK(manager_vector.size() == 1);
subscribe_success_succeeded = 1;
}
@@ -609,7 +610,7 @@ TEST subscribe_success_test(void) {
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
"127.0.0.1", db_connect_args);
db_attach(db, g_loop, false);
subscribe_id = globally_unique_id();
subscribe_id = ObjectID::from_random();
RetryInfo retry = {
.num_retries = 0,
@@ -679,7 +680,7 @@ TEST subscribe_object_present_test(void) {
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
"127.0.0.1", db_connect_args);
db_attach(db, g_loop, false);
UniqueID id = globally_unique_id();
UniqueID id = UniqueID::from_random();
RetryInfo retry = {
.num_retries = 0, .timeout = 100, .fail_callback = fatal_fail_callback,
};
@@ -730,7 +731,7 @@ TEST subscribe_object_not_present_test(void) {
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
"127.0.0.1", std::vector<std::string>());
db_attach(db, g_loop, false);
UniqueID id = globally_unique_id();
UniqueID id = UniqueID::from_random();
RetryInfo retry = {
.num_retries = 0, .timeout = 100, .fail_callback = NULL,
};
@@ -795,7 +796,7 @@ TEST subscribe_object_available_later_test(void) {
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
"127.0.0.1", db_connect_args);
db_attach(db, g_loop, false);
UniqueID id = globally_unique_id();
UniqueID id = UniqueID::from_random();
RetryInfo retry = {
.num_retries = 0, .timeout = 100, .fail_callback = NULL,
};
@@ -850,7 +851,7 @@ TEST subscribe_object_available_subscribe_all(void) {
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
"127.0.0.1", db_connect_args);
db_attach(db, g_loop, false);
UniqueID id = globally_unique_id();
UniqueID id = UniqueID::from_random();
RetryInfo retry = {
.num_retries = 0, .timeout = 100, .fail_callback = NULL,
};
+3 -3
View File
@@ -167,7 +167,7 @@ void logging_read_callback(event_loop *loop,
DBHandle *conn = (DBHandle *) context;
char *cmd = read_log_message(fd);
redisAsyncCommand(conn->context, logging_test_callback, NULL, cmd,
(char *) conn->client.id, sizeof(conn->client.id));
(char *) conn->client.data(), sizeof(conn->client));
free(cmd);
}
@@ -200,8 +200,8 @@ TEST logging_test(void) {
int client_fd = connect_ipc_sock(socket_pathname);
ASSERT(client_fd >= 0);
connections.push_back(client_fd);
RayLogger *logger = RayLogger_init("worker", RAY_INFO, 0, &client_fd);
RayLogger_log(logger, RAY_INFO, "TEST", "Message");
RayLogger *logger = RayLogger_init("worker", RAY_LOG_INFO, 0, &client_fd);
RayLogger_log(logger, RAY_LOG_INFO, "TEST", "Message");
event_loop_add_file(loop, socket_fd, EVENT_LOOP_READ, logging_accept_callback,
conn);
-1
View File
@@ -13,7 +13,6 @@ sleep 1s
./src/common/thirdparty/redis/src/redis-cli set NumRedisShards 1
./src/common/thirdparty/redis/src/redis-cli rpush RedisShards 127.0.0.1:6380
./src/common/common_tests
./src/common/db_tests
./src/common/io_tests
./src/common/task_tests
+6 -7
View File
@@ -15,13 +15,12 @@ sleep 1s
./src/common/thirdparty/redis/src/redis-cli set NumRedisShards 1
./src/common/thirdparty/redis/src/redis-cli rpush RedisShards 127.0.0.1:6380
valgrind --leak-check=full --error-exitcode=1 ./src/common/common_tests
valgrind --leak-check=full --error-exitcode=1 ./src/common/db_tests
valgrind --leak-check=full --error-exitcode=1 ./src/common/io_tests
valgrind --leak-check=full --error-exitcode=1 ./src/common/task_tests
valgrind --leak-check=full --error-exitcode=1 ./src/common/redis_tests
valgrind --leak-check=full --error-exitcode=1 ./src/common/task_table_tests
valgrind --leak-check=full --error-exitcode=1 ./src/common/object_table_tests
valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all --leak-check-heuristics=stdstring --error-exitcode=1 ./src/common/db_tests
valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all --leak-check-heuristics=stdstring --error-exitcode=1 ./src/common/io_tests
valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all --leak-check-heuristics=stdstring --error-exitcode=1 ./src/common/task_tests
valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all --leak-check-heuristics=stdstring --error-exitcode=1 ./src/common/redis_tests
valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all --leak-check-heuristics=stdstring --error-exitcode=1 ./src/common/task_table_tests
valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all --leak-check-heuristics=stdstring --error-exitcode=1 ./src/common/object_table_tests
./src/common/thirdparty/redis/src/redis-cli shutdown
./src/common/thirdparty/redis/src/redis-cli -p 6380 shutdown
+15 -15
View File
@@ -38,7 +38,7 @@ void lookup_nil_success_callback(Task *task, void *context) {
}
TEST lookup_nil_test(void) {
lookup_nil_id = globally_unique_id();
lookup_nil_id = TaskID::from_random();
g_loop = event_loop_create();
DBHandle *db = db_connect(std::string("127.0.0.1"), 6379, "plasma_manager",
"127.0.0.1", std::vector<std::string>());
@@ -116,8 +116,8 @@ TEST add_lookup_test(void) {
.fail_callback = add_lookup_fail_callback,
};
/* Wait for subscription to succeed before adding the task. */
task_table_subscribe(db, NIL_ID, TASK_STATUS_WAITING, NULL, NULL, &retry,
subscribe_success_callback, (void *) db);
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
&retry, subscribe_success_callback, (void *) db);
/* Disconnect the database to see if the lookup times out. */
event_loop_run(g_loop);
db_disconnect(db);
@@ -156,8 +156,8 @@ TEST subscribe_timeout_test(void) {
.timeout = 100,
.fail_callback = subscribe_fail_callback,
};
task_table_subscribe(db, NIL_ID, TASK_STATUS_WAITING, NULL, NULL, &retry,
subscribe_done_callback,
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
&retry, subscribe_done_callback,
(void *) subscribe_timeout_context);
/* Disconnect the database to see if the subscribe times out. */
close(db->subscribe_context->c.fd);
@@ -198,8 +198,8 @@ TEST publish_timeout_test(void) {
RetryInfo retry = {
.num_retries = 5, .timeout = 100, .fail_callback = publish_fail_callback,
};
task_table_subscribe(db, NIL_ID, TASK_STATUS_WAITING, NULL, NULL, &retry,
NULL, NULL);
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
&retry, NULL, NULL);
task_table_add_task(db, task, &retry, publish_done_callback,
(void *) publish_timeout_context);
/* Disconnect the database to see if the publish times out. */
@@ -270,8 +270,8 @@ TEST subscribe_retry_test(void) {
.timeout = 100,
.fail_callback = subscribe_retry_fail_callback,
};
task_table_subscribe(db, NIL_ID, TASK_STATUS_WAITING, NULL, NULL, &retry,
subscribe_retry_done_callback,
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
&retry, subscribe_retry_done_callback,
(void *) subscribe_retry_context);
/* Disconnect the database to see if the subscribe times out. */
close(db->subscribe_context->c.fd);
@@ -321,8 +321,8 @@ TEST publish_retry_test(void) {
.timeout = 100,
.fail_callback = publish_retry_fail_callback,
};
task_table_subscribe(db, NIL_ID, TASK_STATUS_WAITING, NULL, NULL, &retry,
NULL, NULL);
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
&retry, NULL, NULL);
task_table_add_task(db, task, &retry, publish_retry_done_callback,
(void *) publish_retry_context);
/* Disconnect the database to see if the publish times out. */
@@ -374,8 +374,8 @@ TEST subscribe_late_test(void) {
.timeout = 0,
.fail_callback = subscribe_late_fail_callback,
};
task_table_subscribe(db, NIL_ID, TASK_STATUS_WAITING, NULL, NULL, &retry,
subscribe_late_done_callback,
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
&retry, subscribe_late_done_callback,
(void *) subscribe_late_context);
/* Install handler for terminating the event loop. */
event_loop_add_timer(g_loop, 750,
@@ -420,8 +420,8 @@ TEST publish_late_test(void) {
.timeout = 0,
.fail_callback = publish_late_fail_callback,
};
task_table_subscribe(db, NIL_ID, TASK_STATUS_WAITING, NULL, NULL, NULL, NULL,
NULL);
task_table_subscribe(db, UniqueID::nil(), TASK_STATUS_WAITING, NULL, NULL,
NULL, NULL, NULL);
task_table_add_task(db, task, &retry, publish_late_done_callback,
(void *) publish_late_context);
/* Install handler for terminating the event loop. */
+50 -42
View File
@@ -12,31 +12,32 @@
SUITE(task_tests);
TEST task_test(void) {
TaskID parent_task_id = globally_unique_id();
FunctionID func_id = globally_unique_id();
TaskID parent_task_id = TaskID::from_random();
FunctionID func_id = FunctionID::from_random();
TaskBuilder *builder = make_task_builder();
TaskSpec_start_construct(builder, NIL_ID, parent_task_id, 0, NIL_ACTOR_ID,
NIL_ACTOR_ID, 0, false, func_id, 2);
TaskSpec_start_construct(builder, DriverID::nil(), parent_task_id, 0,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
2);
UniqueID arg1 = globally_unique_id();
UniqueID arg1 = UniqueID::from_random();
TaskSpec_args_add_ref(builder, &arg1, 1);
TaskSpec_args_add_val(builder, (uint8_t *) "hello", 5);
UniqueID arg2 = globally_unique_id();
UniqueID arg2 = UniqueID::from_random();
TaskSpec_args_add_ref(builder, &arg2, 1);
TaskSpec_args_add_val(builder, (uint8_t *) "world", 5);
/* Finish constructing the spec. This constructs the task ID and the
* return IDs. */
int64_t size;
uint8_t *spec = TaskSpec_finish_construct(builder, &size);
TaskSpec *spec = TaskSpec_finish_construct(builder, &size);
/* Check that the spec was constructed as expected. */
ASSERT(TaskSpec_num_args(spec) == 4);
ASSERT(TaskSpec_num_returns(spec) == 2);
ASSERT(FunctionID_equal(TaskSpec_function(spec), func_id));
ASSERT(ObjectID_equal(TaskSpec_arg_id(spec, 0, 0), arg1));
ASSERT(TaskSpec_arg_id(spec, 0, 0) == arg1);
ASSERT(memcmp(TaskSpec_arg_val(spec, 1), (uint8_t *) "hello",
TaskSpec_arg_length(spec, 1)) == 0);
ASSERT(ObjectID_equal(TaskSpec_arg_id(spec, 2, 0), arg2));
ASSERT(TaskSpec_arg_id(spec, 2, 0) == arg2);
ASSERT(memcmp(TaskSpec_arg_val(spec, 3), (uint8_t *) "world",
TaskSpec_arg_length(spec, 3)) == 0);
@@ -48,22 +49,24 @@ TEST task_test(void) {
TEST deterministic_ids_test(void) {
TaskBuilder *builder = make_task_builder();
/* Define the inputs to the task construction. */
TaskID parent_task_id = globally_unique_id();
FunctionID func_id = globally_unique_id();
UniqueID arg1 = globally_unique_id();
TaskID parent_task_id = TaskID::from_random();
FunctionID func_id = FunctionID::from_random();
UniqueID arg1 = UniqueID::from_random();
uint8_t *arg2 = (uint8_t *) "hello world";
/* Construct a first task. */
TaskSpec_start_construct(builder, NIL_ID, parent_task_id, 0, NIL_ACTOR_ID,
NIL_ACTOR_ID, 0, false, func_id, 3);
TaskSpec_start_construct(builder, DriverID::nil(), parent_task_id, 0,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
3);
TaskSpec_args_add_ref(builder, &arg1, 1);
TaskSpec_args_add_val(builder, arg2, 11);
int64_t size1;
TaskSpec *spec1 = TaskSpec_finish_construct(builder, &size1);
/* Construct a second identical task. */
TaskSpec_start_construct(builder, NIL_ID, parent_task_id, 0, NIL_ACTOR_ID,
NIL_ACTOR_ID, 0, false, func_id, 3);
TaskSpec_start_construct(builder, DriverID::nil(), parent_task_id, 0,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
3);
TaskSpec_args_add_ref(builder, &arg1, 1);
TaskSpec_args_add_val(builder, arg2, 11);
int64_t size2;
@@ -71,52 +74,57 @@ TEST deterministic_ids_test(void) {
/* Check that these tasks have the same task IDs and the same return IDs. */
ASSERT(TaskID_equal(TaskSpec_task_id(spec1), TaskSpec_task_id(spec2)));
ASSERT(ObjectID_equal(TaskSpec_return(spec1, 0), TaskSpec_return(spec2, 0)));
ASSERT(ObjectID_equal(TaskSpec_return(spec1, 1), TaskSpec_return(spec2, 1)));
ASSERT(ObjectID_equal(TaskSpec_return(spec1, 2), TaskSpec_return(spec2, 2)));
ASSERT(TaskSpec_return(spec1, 0) == TaskSpec_return(spec2, 0));
ASSERT(TaskSpec_return(spec1, 1) == TaskSpec_return(spec2, 1));
ASSERT(TaskSpec_return(spec1, 2) == TaskSpec_return(spec2, 2));
/* Check that the return IDs are all distinct. */
ASSERT(!ObjectID_equal(TaskSpec_return(spec1, 0), TaskSpec_return(spec2, 1)));
ASSERT(!ObjectID_equal(TaskSpec_return(spec1, 0), TaskSpec_return(spec2, 2)));
ASSERT(!ObjectID_equal(TaskSpec_return(spec1, 1), TaskSpec_return(spec2, 2)));
ASSERT(!(TaskSpec_return(spec1, 0) == TaskSpec_return(spec2, 1)));
ASSERT(!(TaskSpec_return(spec1, 0) == TaskSpec_return(spec2, 2)));
ASSERT(!(TaskSpec_return(spec1, 1) == TaskSpec_return(spec2, 2)));
/* Create more tasks that are only mildly different. */
/* Construct a task with a different parent task ID. */
TaskSpec_start_construct(builder, NIL_ID, globally_unique_id(), 0,
NIL_ACTOR_ID, NIL_ACTOR_ID, 0, false, func_id, 3);
TaskSpec_start_construct(builder, DriverID::nil(), TaskID::from_random(), 0,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
3);
TaskSpec_args_add_ref(builder, &arg1, 1);
TaskSpec_args_add_val(builder, arg2, 11);
int64_t size3;
TaskSpec *spec3 = TaskSpec_finish_construct(builder, &size3);
/* Construct a task with a different parent counter. */
TaskSpec_start_construct(builder, NIL_ID, parent_task_id, 1, NIL_ACTOR_ID,
NIL_ACTOR_ID, 0, false, func_id, 3);
TaskSpec_start_construct(builder, DriverID::nil(), parent_task_id, 1,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
3);
TaskSpec_args_add_ref(builder, &arg1, 1);
TaskSpec_args_add_val(builder, arg2, 11);
int64_t size4;
TaskSpec *spec4 = TaskSpec_finish_construct(builder, &size4);
/* Construct a task with a different function ID. */
TaskSpec_start_construct(builder, NIL_ID, parent_task_id, 0, NIL_ACTOR_ID,
NIL_ACTOR_ID, 0, false, globally_unique_id(), 3);
TaskSpec_start_construct(builder, DriverID::nil(), parent_task_id, 0,
ActorID::nil(), ActorID::nil(), 0, false,
FunctionID::from_random(), 3);
TaskSpec_args_add_ref(builder, &arg1, 1);
TaskSpec_args_add_val(builder, arg2, 11);
int64_t size5;
TaskSpec *spec5 = TaskSpec_finish_construct(builder, &size5);
/* Construct a task with a different object ID argument. */
TaskSpec_start_construct(builder, NIL_ID, parent_task_id, 0, NIL_ACTOR_ID,
NIL_ACTOR_ID, 0, false, func_id, 3);
ObjectID object_id = globally_unique_id();
TaskSpec_start_construct(builder, DriverID::nil(), parent_task_id, 0,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
3);
ObjectID object_id = ObjectID::from_random();
TaskSpec_args_add_ref(builder, &object_id, 1);
TaskSpec_args_add_val(builder, arg2, 11);
int64_t size6;
TaskSpec *spec6 = TaskSpec_finish_construct(builder, &size6);
/* Construct a task with a different value argument. */
TaskSpec_start_construct(builder, NIL_ID, parent_task_id, 0, NIL_ACTOR_ID,
NIL_ACTOR_ID, 0, false, func_id, 3);
TaskSpec_start_construct(builder, DriverID::nil(), parent_task_id, 0,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
3);
TaskSpec_args_add_ref(builder, &arg1, 1);
TaskSpec_args_add_val(builder, (uint8_t *) "hello_world", 11);
int64_t size7;
@@ -136,9 +144,8 @@ TEST deterministic_ids_test(void) {
for (int task_index2 = 0; task_index2 < 6; ++task_index2) {
for (int return_index2 = 0; return_index2 < 3; ++return_index2) {
if (task_index1 != task_index2 && return_index1 != return_index2) {
ASSERT(!ObjectID_equal(
TaskSpec_return(specs[task_index1], return_index1),
TaskSpec_return(specs[task_index2], return_index2)));
ASSERT(!(TaskSpec_return(specs[task_index1], return_index1) ==
TaskSpec_return(specs[task_index2], return_index2)));
}
}
}
@@ -158,15 +165,16 @@ TEST deterministic_ids_test(void) {
TEST send_task(void) {
TaskBuilder *builder = make_task_builder();
TaskID parent_task_id = globally_unique_id();
FunctionID func_id = globally_unique_id();
TaskSpec_start_construct(builder, NIL_ID, parent_task_id, 0, NIL_ACTOR_ID,
NIL_ACTOR_ID, 0, false, func_id, 2);
ObjectID object_id = globally_unique_id();
TaskID parent_task_id = TaskID::from_random();
FunctionID func_id = FunctionID::from_random();
TaskSpec_start_construct(builder, DriverID::nil(), parent_task_id, 0,
ActorID::nil(), ActorID::nil(), 0, false, func_id,
2);
ObjectID object_id = ObjectID::from_random();
TaskSpec_args_add_ref(builder, &object_id, 1);
TaskSpec_args_add_val(builder, (uint8_t *) "Hello", 5);
TaskSpec_args_add_val(builder, (uint8_t *) "World", 5);
object_id = globally_unique_id();
object_id = ObjectID::from_random();
TaskSpec_args_add_ref(builder, &object_id, 1);
int64_t size;
TaskSpec *spec = TaskSpec_finish_construct(builder, &size);