From 6b0c18e921c046d1c14106c629243e96d6cd60f0 Mon Sep 17 00:00:00 2001 From: Andrey Rakhmatullin Date: Thu, 19 Oct 2023 23:13:47 +0400 Subject: [PATCH] Improve signal sending in test_shutdown_forced. --- tests/test_crawler.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_crawler.py b/tests/test_crawler.py index 5c11ca6e0..0a7f9bac8 100644 --- a/tests/test_crawler.py +++ b/tests/test_crawler.py @@ -534,7 +534,10 @@ class CrawlerProcessSubprocess(ScriptRunnerMixin, unittest.TestCase): p.expect_exact("Spider closed (shutdown)") p.wait() + @defer.inlineCallbacks def test_shutdown_forced(self): + from twisted.internet import reactor + sig = signal.SIGINT if sys.platform != "win32" else signal.SIGBREAK args = self.get_script_args("sleeping.py", "-a", "sleep=10") p = PopenSpawn(args, timeout=5) @@ -542,6 +545,10 @@ class CrawlerProcessSubprocess(ScriptRunnerMixin, unittest.TestCase): p.expect_exact("Crawled (200)") p.kill(sig) p.expect_exact("shutting down gracefully") + # sending the second signal too fast often causes problems + d = defer.Deferred() + reactor.callLater(0.1, d.callback, None) + yield d p.kill(sig) p.expect_exact("forcing unclean shutdown") p.wait()