From 5bed91f0f661b7d7a239406529a2a143b6e82024 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 12 Jun 2018 10:52:12 -0400 Subject: [PATCH] tests: add timeout to fixture for ecore tests Summary: this is mainly to handle the case of ecore-file, which fetches external resources during the test and requires an active network connection which may fail to resolve/connect/download during the test. if this particular test fails then it is almost certainly a network issue a future patch should implement some form of http server to remove the dependency on external network resources also probably all test suites should have timeout timers just in case fix T6950 Depends on D6205 Reviewers: stefan_schmidt, cedric Reviewed By: cedric Subscribers: cedric, #committers Tags: #efl Maniphest Tasks: T6950 Differential Revision: https://phab.enlightenment.org/D6206 --- src/tests/ecore/ecore_suite.c | 26 ++++++++++++++++++++++++++ src/tests/ecore/ecore_suite.h | 3 +++ src/tests/ecore/ecore_test_ecore_file.c | 4 +++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/tests/ecore/ecore_suite.c b/src/tests/ecore/ecore_suite.c index 4db6981..0e67fea 100644 --- a/src/tests/ecore/ecore_suite.c +++ b/src/tests/ecore/ecore_suite.c @@ -35,13 +35,39 @@ static const Efl_Test_Case etc[] = { { NULL, NULL } }; +static Ecore_Timer *timeout; +int timeout_reached = 0; + +static Eina_Bool +timeout_cb() +{ + const char *tcname = tcase_name(); + + timeout_reached = 1; + + if (tcname && strstr(tcname, "download")) + { + fprintf(stderr, "test timeout reached: download failed, probably network issue. skipping\n"); + ecore_main_loop_quit(); + } + else + ck_abort_msg("test timeout reached!"); + timeout = NULL; + return EINA_FALSE; +} + SUITE_INIT(ecore) { + timeout_reached = 0; ck_assert_int_eq(ecore_init(), 1); + timeout = ecore_timer_add(5.0, timeout_cb, NULL); + ck_assert_msg(!!timeout, "timeout timer creation failed!"); } SUITE_SHUTDOWN(ecore) { + ecore_timer_del(timeout); + timeout = NULL; ck_assert_int_eq(ecore_shutdown(), 0); } diff --git a/src/tests/ecore/ecore_suite.h b/src/tests/ecore/ecore_suite.h index 5cd57de..debc203 100644 --- a/src/tests/ecore/ecore_suite.h +++ b/src/tests/ecore/ecore_suite.h @@ -3,6 +3,9 @@ #include #include "../efl_check.h" + +extern int timeout_reached; + void ecore_test_ecore(TCase *tc); void ecore_test_ecore_idle(TCase *tc); void ecore_test_ecore_poller(TCase *tc); diff --git a/src/tests/ecore/ecore_test_ecore_file.c b/src/tests/ecore/ecore_test_ecore_file.c index 764d007..fb23ffb 100644 --- a/src/tests/ecore/ecore_test_ecore_file.c +++ b/src/tests/ecore/ecore_test_ecore_file.c @@ -508,6 +508,7 @@ EFL_START_TEST(ecore_test_ecore_file_download) fail_if(!job); ecore_file_download_abort(job); ecore_main_loop_begin(); + if (timeout_reached) goto end; res = ecore_file_remove(dest_name); fail_if(res != EINA_TRUE); @@ -519,10 +520,11 @@ EFL_START_TEST(ecore_test_ecore_file_download) fail_if(res != EINA_TRUE); fail_if(!job); ecore_main_loop_begin(); + if (timeout_reached) goto end; fprintf(stderr, "Downloaded %lld bytes\n", ecore_file_size(dest_name)); res = ecore_file_exists(dest_name); fail_if(res != EINA_TRUE); - +end: res = ecore_file_recursive_rm(download_dir); fail_if(res != EINA_TRUE); -- 2.7.4