forked from cory/tildefriends
Move the bulk of ssb.privateMessageEncrypt work (CPU + DB) off the main thread.
This commit is contained in:
@ -819,3 +819,42 @@ void tf_ssb_test_go_ssb_room(const tf_test_options_t* options)
|
||||
|
||||
uv_loop_close(&loop);
|
||||
}
|
||||
|
||||
static void _write_file(const char* path, const char* contents)
|
||||
{
|
||||
FILE* file = fopen(path, "w");
|
||||
if (!file)
|
||||
{
|
||||
printf("Unable to write %s: %s.\n", path, strerror(errno));
|
||||
fflush(stdout);
|
||||
abort();
|
||||
}
|
||||
fputs(contents, file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
#define TEST_ARGS " --ssb-port=0 --http-port=0 --https-port=0"
|
||||
|
||||
void tf_ssb_test_encrypt(const tf_test_options_t* options)
|
||||
{
|
||||
_write_file("out/test.js",
|
||||
"async function main() {\n"
|
||||
" let a = await ssb.createIdentity('test');\n"
|
||||
" let b = await ssb.createIdentity('test');\n"
|
||||
" let c = await ssb.privateMessageEncrypt('test', a, [a, b], {'foo': 1});\n"
|
||||
" if (!c.endsWith('.box')) {\n"
|
||||
" exit(1);\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"main().catch(() => exit(2));\n");
|
||||
|
||||
unlink("out/testdb.sqlite");
|
||||
char command[256];
|
||||
snprintf(command, sizeof(command), "%s run --db-path=out/testdb.sqlite -s out/test.js" TEST_ARGS, options->exe_path);
|
||||
tf_printf("%s\n", command);
|
||||
int result = system(command);
|
||||
(void)result;
|
||||
assert(WIFEXITED(result));
|
||||
printf("returned %d\n", WEXITSTATUS(result));
|
||||
assert(WEXITSTATUS(result) == 0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user