mirror of https://github.com/scrapy/scrapy.git
Fix limiting subprocess run time in tests. (#6933)
* Fix limiting subprocess run time in tests. * Make test_runspider_dnscache_disabled() faster.
This commit is contained in:
parent
7842180b2f
commit
8d82e7bd27
|
|
@ -112,6 +112,11 @@ class MySpider(scrapy.Spider):
|
|||
name = 'myspider'
|
||||
start_urls = ['http://localhost:12345']
|
||||
|
||||
custom_settings = {
|
||||
"ROBOTSTXT_OBEY": False,
|
||||
"RETRY_ENABLED": False,
|
||||
}
|
||||
|
||||
def parse(self, response):
|
||||
return {'test': 'value'}
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -9,10 +9,11 @@ from io import StringIO
|
|||
from pathlib import Path
|
||||
from shutil import rmtree
|
||||
from tempfile import TemporaryFile, mkdtemp
|
||||
from threading import Timer
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
import scrapy
|
||||
from scrapy.cmdline import _pop_command_name, _print_unknown_command_msg
|
||||
from scrapy.commands import ScrapyCommand, ScrapyHelpFormatter, view
|
||||
|
|
@ -100,17 +101,12 @@ class TestProjectBase:
|
|||
**popen_kwargs,
|
||||
)
|
||||
|
||||
def kill_proc():
|
||||
try:
|
||||
stdout, stderr = p.communicate(timeout=15)
|
||||
except subprocess.TimeoutExpired:
|
||||
p.kill()
|
||||
p.communicate()
|
||||
raise AssertionError("Command took too much time to complete")
|
||||
|
||||
timer = Timer(15, kill_proc)
|
||||
try:
|
||||
timer.start()
|
||||
stdout, stderr = p.communicate()
|
||||
finally:
|
||||
timer.cancel()
|
||||
pytest.fail("Command took too much time to complete")
|
||||
|
||||
return p, to_unicode(stdout), to_unicode(stderr)
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ from collections import defaultdict
|
|||
from dataclasses import dataclass
|
||||
from logging import DEBUG
|
||||
from pathlib import Path
|
||||
from threading import Timer
|
||||
from unittest.mock import Mock
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
|
@ -495,17 +494,12 @@ class TestEngine(TestEngineBase):
|
|||
stderr=subprocess.PIPE,
|
||||
)
|
||||
|
||||
def kill_proc():
|
||||
try:
|
||||
_, stderr = p.communicate(timeout=3)
|
||||
except subprocess.TimeoutExpired:
|
||||
p.kill()
|
||||
p.communicate()
|
||||
raise AssertionError("Command took too much time to complete")
|
||||
|
||||
timer = Timer(15, kill_proc)
|
||||
try:
|
||||
timer.start()
|
||||
_, stderr = p.communicate()
|
||||
finally:
|
||||
timer.cancel()
|
||||
pytest.fail("Command took too much time to complete")
|
||||
|
||||
stderr_str = stderr.decode("utf-8")
|
||||
assert "AttributeError" not in stderr_str, stderr_str
|
||||
|
|
|
|||
Loading…
Reference in New Issue