From 010f2caa23d92337bf055a54e00ad088ed360f01 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Mon, 8 Feb 2021 20:52:00 -0600 Subject: [PATCH] try to fix reader and signal test failed (#30960) --- .../reader/reader_blocking_queue_test.cc | 2 +- .../test_imperative_signal_handler.py | 55 +++++++++++++------ 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/paddle/fluid/operators/reader/reader_blocking_queue_test.cc b/paddle/fluid/operators/reader/reader_blocking_queue_test.cc index 86c9f38ad3..98a68ca69c 100644 --- a/paddle/fluid/operators/reader/reader_blocking_queue_test.cc +++ b/paddle/fluid/operators/reader/reader_blocking_queue_test.cc @@ -68,7 +68,7 @@ TEST(BlockingQueue, SenderBlockingTest) { ++send_count; } }); - std::this_thread::sleep_for(std::chrono::milliseconds(200)); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); q.Close(); sender.join(); EXPECT_EQ(send_count, queue_cap); diff --git a/python/paddle/fluid/tests/unittests/test_imperative_signal_handler.py b/python/paddle/fluid/tests/unittests/test_imperative_signal_handler.py index 991d4058d0..b388efc5f3 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_signal_handler.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_signal_handler.py @@ -70,16 +70,26 @@ class TestDygraphDataLoaderSingalHandler(unittest.TestCase): core._set_process_signal_handler() os.kill(os.getpid(), signal.SIGSEGV) - exception = None - try: - test_process = multiprocessing.Process(target=__test_process__) - test_process.start() + def try_except_exit(): + exception = None + try: + test_process = multiprocessing.Process(target=__test_process__) + test_process.start() - set_child_signal_handler(id(self), test_process.pid) - time.sleep(10) - except SystemError as ex: - self.assertIn("Segmentation fault", cpt.get_exception_message(ex)) - exception = ex + set_child_signal_handler(id(self), test_process.pid) + time.sleep(5) + except SystemError as ex: + self.assertIn("Segmentation fault", + cpt.get_exception_message(ex)) + exception = ex + return exception + + try_time = 10 + exception = None + for i in range(try_time): + exception = try_except_exit() + if exception is not None: + break self.assertIsNotNone(exception) @@ -88,16 +98,25 @@ class TestDygraphDataLoaderSingalHandler(unittest.TestCase): core._set_process_signal_handler() os.kill(os.getpid(), signal.SIGBUS) - exception = None - try: - test_process = multiprocessing.Process(target=__test_process__) - test_process.start() + def try_except_exit(): + exception = None + try: + test_process = multiprocessing.Process(target=__test_process__) + test_process.start() - set_child_signal_handler(id(self), test_process.pid) - time.sleep(10) - except SystemError as ex: - self.assertIn("Bus error", cpt.get_exception_message(ex)) - exception = ex + set_child_signal_handler(id(self), test_process.pid) + time.sleep(5) + except SystemError as ex: + self.assertIn("Bus error", cpt.get_exception_message(ex)) + exception = ex + return exception + + try_time = 10 + exception = None + for i in range(try_time): + exception = try_except_exit() + if exception is not None: + break self.assertIsNotNone(exception) -- GitLab