Run the selenium automation tests from C, so that they all run in once place, and because I get better errors for some reason. Fix more issues along the way.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4847 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-02-16 00:47:54 +00:00
parent 08a2436b8f
commit aeb5c6ee25
5 changed files with 82 additions and 14 deletions

View File

@ -737,6 +737,71 @@ static void _test_http(const tf_test_options_t* options)
uv_thread_join(&thread);
}
static void _test_auto_process_exit(uv_process_t* process, int64_t status, int termination_signal)
{
tf_printf("Process exit %d signal=%d.\n", (int)WEXITSTATUS(status), termination_signal);
assert(WEXITSTATUS(status) == 0);
process->data = NULL;
uv_close((uv_handle_t*)process, NULL);
}
static void _test_auto(const tf_test_options_t* options)
{
uv_loop_t loop = { 0 };
uv_loop_init(&loop);
char executable[1024];
size_t size = sizeof(executable);
uv_exepath(executable, &size);
unlink("out/selenium.sqlite");
unlink("out/selenium.sqlite-shm");
unlink("out/selenium.sqlite-wal");
char* args[] = { executable, "run", "-d", "out/selenium.sqlite", "-b", "0", "-p", "8888", NULL };
uv_stdio_container_t io[3] =
{
{ .flags = UV_INHERIT_FD },
{ .flags = UV_INHERIT_FD },
{ .flags = UV_INHERIT_FD },
};
uv_process_options_t process_options = {0};
process_options.args = args;
process_options.exit_cb = _test_auto_process_exit;
process_options.stdio = io;
process_options.stdio_count = sizeof(io) / sizeof(*io);
process_options.file = args[0];
uv_process_t process = { .data = &process };
int spawn_result = uv_spawn(&loop, &process, &process_options);
if (spawn_result)
{
abort();
}
char* selenium_args[] = { "python3", "tools/autotest.py", NULL };
process_options.args = selenium_args;
process_options.exit_cb = _test_auto_process_exit;
process_options.file = selenium_args[0];
uv_process_t selenium = { .data = &selenium };
spawn_result = uv_spawn(&loop, &selenium, &process_options);
if (spawn_result)
{
abort();
}
while (selenium.data)
{
uv_run(&loop, UV_RUN_ONCE);
}
uv_process_kill(&process, SIGTERM);
uv_run(&loop, UV_RUN_DEFAULT);
uv_loop_close(&loop);
}
static void _tf_test_run(const tf_test_options_t* options, const char* name, void (*test)(const tf_test_options_t* options), bool opt_in)
{
bool specified = false;
@ -800,6 +865,7 @@ void tf_tests(const tf_test_options_t* options)
_tf_test_run(options, "b64", _test_b64, false);
_tf_test_run(options, "rooms", tf_ssb_test_rooms, false);
_tf_test_run(options, "bench", tf_ssb_test_bench, false);
_tf_test_run(options, "auto", _test_auto, false);
_tf_test_run(options, "go-ssb-room", tf_ssb_test_go_ssb_room, true);
tf_printf("Tests completed.\n");
#endif