forked from cory/tildefriends
Allow running read-only sqlite queries from libuv worker threads. Needs so much more testing.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4172 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -127,21 +127,13 @@ static void _ssb_test_idle(uv_idle_t* idle)
|
||||
void tf_ssb_test_ssb(const tf_test_options_t* options)
|
||||
{
|
||||
printf("Testing SSB.\n");
|
||||
sqlite3* db0 = NULL;
|
||||
sqlite3* db1 = NULL;
|
||||
|
||||
int r = sqlite3_open(":memory:", &db0);
|
||||
(void)r;
|
||||
assert(r == SQLITE_OK);
|
||||
r = sqlite3_open(":memory:", &db1);
|
||||
assert(r == SQLITE_OK);
|
||||
|
||||
uv_loop_t loop = { 0 };
|
||||
uv_loop_init(&loop);
|
||||
|
||||
tf_ssb_t* ssb0 = tf_ssb_create(&loop, NULL, db0);
|
||||
tf_ssb_t* ssb0 = tf_ssb_create(&loop, NULL, ":memory:");
|
||||
tf_ssb_register(tf_ssb_get_context(ssb0), ssb0);
|
||||
tf_ssb_t* ssb1 = tf_ssb_create(&loop, NULL, db1);
|
||||
tf_ssb_t* ssb1 = tf_ssb_create(&loop, NULL, ":memory:");
|
||||
tf_ssb_register(tf_ssb_get_context(ssb1), ssb1);
|
||||
|
||||
uv_idle_t idle0 = { .data = ssb0 };
|
||||
@ -267,9 +259,6 @@ void tf_ssb_test_ssb(const tf_test_options_t* options)
|
||||
tf_ssb_destroy(ssb1);
|
||||
|
||||
uv_loop_close(&loop);
|
||||
|
||||
sqlite3_close(db0);
|
||||
sqlite3_close(db1);
|
||||
}
|
||||
|
||||
static void _broadcasts_visit(const char* host, const struct sockaddr_in* addr, tf_ssb_connection_t* tunnel, const uint8_t* pub, void* user_data)
|
||||
@ -302,26 +291,15 @@ static void _broadcasts_changed(tf_ssb_t* ssb, void* user_data)
|
||||
void tf_ssb_test_rooms(const tf_test_options_t* options)
|
||||
{
|
||||
printf("Testing Rooms.\n");
|
||||
sqlite3* db0 = NULL;
|
||||
sqlite3* db1 = NULL;
|
||||
sqlite3* db2 = NULL;
|
||||
|
||||
int r = sqlite3_open(":memory:", &db0);
|
||||
(void)r;
|
||||
assert(r == SQLITE_OK);
|
||||
r = sqlite3_open(":memory:", &db1);
|
||||
assert(r == SQLITE_OK);
|
||||
r = sqlite3_open(":memory:", &db2);
|
||||
assert(r == SQLITE_OK);
|
||||
|
||||
uv_loop_t loop = { 0 };
|
||||
uv_loop_init(&loop);
|
||||
|
||||
tf_ssb_t* ssb0 = tf_ssb_create(&loop, NULL, db0);
|
||||
tf_ssb_t* ssb0 = tf_ssb_create(&loop, NULL, ":memory:");
|
||||
tf_ssb_register(tf_ssb_get_context(ssb0), ssb0);
|
||||
tf_ssb_t* ssb1 = tf_ssb_create(&loop, NULL, db1);
|
||||
tf_ssb_t* ssb1 = tf_ssb_create(&loop, NULL, ":memory:");
|
||||
tf_ssb_register(tf_ssb_get_context(ssb1), ssb1);
|
||||
tf_ssb_t* ssb2 = tf_ssb_create(&loop, NULL, db2);
|
||||
tf_ssb_t* ssb2 = tf_ssb_create(&loop, NULL, ":memory:");
|
||||
tf_ssb_register(tf_ssb_get_context(ssb2), ssb2);
|
||||
|
||||
uv_idle_t idle0 = { .data = ssb0 };
|
||||
@ -462,30 +440,22 @@ void tf_ssb_test_rooms(const tf_test_options_t* options)
|
||||
uv_run(&loop, UV_RUN_DEFAULT);
|
||||
|
||||
uv_loop_close(&loop);
|
||||
|
||||
sqlite3_close(db0);
|
||||
sqlite3_close(db1);
|
||||
sqlite3_close(db2);
|
||||
}
|
||||
|
||||
void tf_ssb_test_following(const tf_test_options_t* options)
|
||||
{
|
||||
printf("Testing following.\n");
|
||||
sqlite3* db0 = NULL;
|
||||
int r = sqlite3_open(":memory:", &db0);
|
||||
(void)r;
|
||||
assert(r == SQLITE_OK);
|
||||
|
||||
uv_loop_t loop = { 0 };
|
||||
uv_loop_init(&loop);
|
||||
|
||||
tf_ssb_t* ssb0 = tf_ssb_create(&loop, NULL, db0);
|
||||
tf_ssb_t* ssb0 = tf_ssb_create(&loop, NULL, ":memory:");
|
||||
tf_ssb_generate_keys(ssb0);
|
||||
|
||||
tf_ssb_t* ssb1 = tf_ssb_create(&loop, NULL, db0);
|
||||
tf_ssb_t* ssb1 = tf_ssb_create(&loop, NULL, ":memory:");
|
||||
tf_ssb_generate_keys(ssb1);
|
||||
|
||||
tf_ssb_t* ssb2 = tf_ssb_create(&loop, NULL, db0);
|
||||
tf_ssb_t* ssb2 = tf_ssb_create(&loop, NULL, ":memory:");
|
||||
tf_ssb_generate_keys(ssb2);
|
||||
|
||||
char id0[k_id_base64_len] = { 0 };
|
||||
@ -553,22 +523,16 @@ void tf_ssb_test_following(const tf_test_options_t* options)
|
||||
tf_ssb_destroy(ssb2);
|
||||
|
||||
uv_loop_close(&loop);
|
||||
|
||||
sqlite3_close(db0);
|
||||
}
|
||||
|
||||
void tf_ssb_test_bench(const tf_test_options_t* options)
|
||||
{
|
||||
printf("Testing following.\n");
|
||||
sqlite3* db0 = NULL;
|
||||
int r = sqlite3_open(":memory:", &db0);
|
||||
(void)r;
|
||||
assert(r == SQLITE_OK);
|
||||
|
||||
uv_loop_t loop = { 0 };
|
||||
uv_loop_init(&loop);
|
||||
|
||||
tf_ssb_t* ssb0 = tf_ssb_create(&loop, NULL, db0);
|
||||
tf_ssb_t* ssb0 = tf_ssb_create(&loop, NULL, ":memory:");
|
||||
tf_ssb_generate_keys(ssb0);
|
||||
|
||||
char id0[k_id_base64_len] = { 0 };
|
||||
@ -585,10 +549,7 @@ void tf_ssb_test_bench(const tf_test_options_t* options)
|
||||
clock_gettime(CLOCK_REALTIME, &end_time);
|
||||
printf("insert = %f seconds\n", (float)(end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec - start_time.tv_nsec) / 1e9f);
|
||||
|
||||
sqlite3* db1 = NULL;
|
||||
sqlite3_open(":memory:", &db1);
|
||||
assert(r == SQLITE_OK);
|
||||
tf_ssb_t* ssb1 = tf_ssb_create(&loop, NULL, db1);
|
||||
tf_ssb_t* ssb1 = tf_ssb_create(&loop, NULL, ":memory:");
|
||||
tf_ssb_generate_keys(ssb1);
|
||||
uint8_t id0bin[k_id_bin_len];
|
||||
tf_ssb_id_str_to_bin(id0bin, id0);
|
||||
@ -629,7 +590,4 @@ void tf_ssb_test_bench(const tf_test_options_t* options)
|
||||
tf_ssb_destroy(ssb0);
|
||||
|
||||
uv_loop_close(&loop);
|
||||
|
||||
sqlite3_close(db0);
|
||||
sqlite3_close(db1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user