tests: add timeout to fixture for ecore tests
authorMike Blumenkrantz <zmike@osg.samsung.com>
Tue, 12 Jun 2018 14:52:12 +0000 (10:52 -0400)
committerJongmin Lee <jm105.lee@samsung.com>
Wed, 13 Jun 2018 23:50:59 +0000 (08:50 +0900)
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
src/tests/ecore/ecore_suite.h
src/tests/ecore/ecore_test_ecore_file.c

index 4db6981..0e67fea 100644 (file)
@@ -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);
 }
 
index 5cd57de..debc203 100644 (file)
@@ -3,6 +3,9 @@
 
 #include <check.h>
 #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);
index 764d007..fb23ffb 100644 (file)
@@ -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);