Test that a low CLOSEPIDER_TIMEOUT does not raise an exception

This commit is contained in:
Adrián Chaves 2022-03-15 12:10:41 +01:00
parent 62a0081266
commit b59a69be17
1 changed files with 33 additions and 0 deletions

View File

@ -12,9 +12,11 @@ module with the ``runserver`` argument::
import os
import re
import subprocess
import sys
import warnings
from collections import defaultdict
from threading import Timer
from urllib.parse import urlparse
import attr
@ -502,6 +504,37 @@ class EngineTest(unittest.TestCase):
self.assertEqual(warning_list[0].category, ScrapyDeprecationWarning)
self.assertEqual(str(warning_list[0].message), "ExecutionEngine.has_capacity is deprecated")
def test_short_timeout(self):
args = (
sys.executable,
'-m',
'scrapy.cmdline',
'fetch',
'-s',
'CLOSESPIDER_TIMEOUT=0.001',
'-s',
'LOG_LEVEL=DEBUG',
'http://toscrape.com',
)
p = subprocess.Popen(
args,
stderr=subprocess.PIPE,
)
def kill_proc():
p.kill()
p.communicate()
assert False, 'Command took too much time to complete'
timer = Timer(15, kill_proc)
try:
timer.start()
_, stderr = p.communicate()
finally:
timer.cancel()
self.assertNotIn(b'Traceback', stderr)
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == 'runserver':