More bugs.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3785 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2022-01-22 20:47:10 +00:00
parent 6c28ca738e
commit bd81b2acf5
4 changed files with 48 additions and 4 deletions

View File

@ -3,6 +3,7 @@
#include "ssb.db.h"
#include "ssb.js.h"
#include "tests.h"
#include "util.js.h"
#include <assert.h>
#include <stdlib.h>
@ -10,6 +11,8 @@
#include <sqlite3.h>
#include <uv.h>
#include "quickjs-libc.h"
void tf_ssb_test_id_conversion(const tf_test_options_t* options)
{
printf("Testing id conversion.\n");
@ -74,6 +77,30 @@ static void _message_added(tf_ssb_t* ssb, const char* id, void* user_data)
++*(int*)user_data;
}
static void _ssb_test_idle(uv_idle_t* idle)
{
tf_ssb_t* ssb = idle->data;
JSRuntime* runtime = JS_GetRuntime(tf_ssb_get_context(ssb));
while (JS_IsJobPending(runtime))
{
JSContext* context = NULL;
int r = JS_ExecutePendingJob(runtime, &context);
JSValue result = JS_GetException(context);
if (context)
{
tf_util_report_error(context, result);
}
if (r < 0)
{
js_std_dump_error(context);
}
else if (r == 0)
{
break;
}
}
}
void tf_ssb_test_ssb(const tf_test_options_t* options)
{
printf("Testing SSB.\n");
@ -91,6 +118,14 @@ void tf_ssb_test_ssb(const tf_test_options_t* options)
tf_ssb_t* ssb1 = tf_ssb_create(&loop, NULL, db1, NULL);
tf_ssb_register(tf_ssb_get_context(ssb1), ssb1);
uv_idle_t idle0 = { .data = ssb0 };
uv_idle_init(&loop, &idle0);
uv_idle_start(&idle0, _ssb_test_idle);
uv_idle_t idle1 = { .data = ssb1 };
uv_idle_init(&loop, &idle1);
uv_idle_start(&idle1, _ssb_test_idle);
test_t test = {
.ssb0 = ssb0,
.ssb1 = ssb1,
@ -181,6 +216,9 @@ void tf_ssb_test_ssb(const tf_test_options_t* options)
tf_ssb_send_close(ssb1);
uv_close((uv_handle_t*)&idle0, NULL);
uv_close((uv_handle_t*)&idle1, NULL);
uv_run(&loop, UV_RUN_DEFAULT);
tf_ssb_destroy(ssb0);