Make the http test complete successfully.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4680 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2023-12-18 17:51:15 +00:00
parent 7b3a9e0f63
commit 03e4b37c04
3 changed files with 81 additions and 8 deletions

View File

@ -670,24 +670,40 @@ static void _test_b64(const tf_test_options_t* options)
unlink("out/test.js");
}
typedef struct _test_http_t
{
uv_loop_t* loop;
uv_async_t async;
bool done;
} test_http_t;
static void _test_http_async(uv_async_t* async)
{
}
static void _test_http_thread(void* data)
{
#if defined(__linux__)
test_http_t* test = data;
int r = system("curl -v http://localhost:23456/");
*(int*)data = WEXITSTATUS(r);
assert(WEXITSTATUS(r) == 0);
tf_printf("curl returned %d\n", WEXITSTATUS(r));
test->done = true;
/* All to wake up the loop. */
uv_async_send(&test->async);
#endif
}
static void _test_http_handler(tf_http_request_t* request)
{
tf_printf("HANDLER %d\n", request->phase);
const char* headers[] =
{
"Connection", "close",
};
tf_http_respond(request, 200, headers, 1, "Hello, world!", strlen("Hello, world!"));
const char* k_payload = "Hello, world!\n";
tf_http_respond(request, 200, headers, 1, k_payload, strlen(k_payload));
}
static void _test_http(const tf_test_options_t* options)
@ -698,16 +714,19 @@ static void _test_http(const tf_test_options_t* options)
tf_http_add_handler(http, NULL, _test_http_handler, NULL);
tf_http_listen(http, 23456);
int result = -1;
test_http_t test = { .loop = &loop };
uv_async_init(&loop, &test.async, _test_http_async);
uv_thread_t thread = { 0 };
uv_thread_create(&thread, _test_http_thread, &result);
while (result == -1)
uv_thread_create(&thread, _test_http_thread, &test);
while (!test.done)
{
uv_run(&loop, UV_RUN_ONCE);
}
uv_close((uv_handle_t*)&test.async, NULL);
tf_printf("Done running.\n");
tf_http_destroy(http);
uv_run(&loop, UV_RUN_DEFAULT);
uv_loop_close(&loop);
uv_thread_join(&thread);