mirror of https://github.com/zulip/zulip.git
test_logging_handlers: Mock out `git describe` because can be slow.
This cuts out about 11 calls to `git describe`. In a nice fast LXC container following our instructions for development on a Linux host, this might save "only" about 1.5s; in a dev environment on a Windows host, the savings have been clocked at 49s, presumably due to an extremely slow filesystem in the VM. The tests weren't doing much with this codepath as they were, and there isn't a lot of value to be gained by testing it anyway; it's totally non-critical and rarely changes. [Commit message rewritten by greg.]
This commit is contained in:
parent
b9fdb2cbf5
commit
d32d7a9b4d
|
@ -18,7 +18,7 @@ from zerver.lib.queue import queue_json_publish
|
||||||
from version import ZULIP_VERSION
|
from version import ZULIP_VERSION
|
||||||
|
|
||||||
def try_git_describe() -> Optional[str]:
|
def try_git_describe() -> Optional[str]:
|
||||||
try:
|
try: # nocoverage
|
||||||
return subprocess.check_output(
|
return subprocess.check_output(
|
||||||
['git',
|
['git',
|
||||||
'--git-dir', os.path.join(os.path.dirname(__file__), '../.git'),
|
'--git-dir', os.path.join(os.path.dirname(__file__), '../.git'),
|
||||||
|
|
|
@ -9,7 +9,7 @@ from django.http import HttpRequest, HttpResponse
|
||||||
from django.test import RequestFactory, TestCase
|
from django.test import RequestFactory, TestCase
|
||||||
from django.utils.log import AdminEmailHandler
|
from django.utils.log import AdminEmailHandler
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from mock import patch
|
from mock import MagicMock, patch
|
||||||
from mypy_extensions import NoReturn
|
from mypy_extensions import NoReturn
|
||||||
from typing import Any, Callable, Dict, Mapping, Optional, Text, Iterator
|
from typing import Any, Callable, Dict, Mapping, Optional, Text, Iterator
|
||||||
|
|
||||||
|
@ -61,7 +61,9 @@ class AdminNotifyHandlerTest(ZulipTestCase):
|
||||||
if isinstance(h, AdminNotifyHandler)
|
if isinstance(h, AdminNotifyHandler)
|
||||||
][0]
|
][0]
|
||||||
|
|
||||||
def test_basic(self) -> None:
|
@patch('zerver.logging_handlers.try_git_describe')
|
||||||
|
def test_basic(self, mock_function: MagicMock) -> None:
|
||||||
|
mock_function.return_value = None
|
||||||
"""A random exception passes happily through AdminNotifyHandler"""
|
"""A random exception passes happily through AdminNotifyHandler"""
|
||||||
handler = self.get_admin_zulip_handler()
|
handler = self.get_admin_zulip_handler()
|
||||||
try:
|
try:
|
||||||
|
@ -92,7 +94,9 @@ class AdminNotifyHandlerTest(ZulipTestCase):
|
||||||
patched_notify.assert_called_once()
|
patched_notify.assert_called_once()
|
||||||
return patched_notify.call_args[0][0]
|
return patched_notify.call_args[0][0]
|
||||||
|
|
||||||
def test_long_exception_request(self) -> None:
|
@patch('zerver.logging_handlers.try_git_describe')
|
||||||
|
def test_long_exception_request(self, mock_function: MagicMock) -> None:
|
||||||
|
mock_function.return_value = None
|
||||||
"""A request with no stack and multi-line report.getMessage() is handled properly"""
|
"""A request with no stack and multi-line report.getMessage() is handled properly"""
|
||||||
record = self.simulate_error()
|
record = self.simulate_error()
|
||||||
record.exc_info = None
|
record.exc_info = None
|
||||||
|
@ -105,7 +109,9 @@ class AdminNotifyHandlerTest(ZulipTestCase):
|
||||||
self.assertEqual(report['stack_trace'], 'message\nmoremesssage\nmore')
|
self.assertEqual(report['stack_trace'], 'message\nmoremesssage\nmore')
|
||||||
self.assertEqual(report['message'], 'message')
|
self.assertEqual(report['message'], 'message')
|
||||||
|
|
||||||
def test_request(self) -> None:
|
@patch('zerver.logging_handlers.try_git_describe')
|
||||||
|
def test_request(self, mock_function: MagicMock) -> None:
|
||||||
|
mock_function.return_value = None
|
||||||
"""A normal request is handled properly"""
|
"""A normal request is handled properly"""
|
||||||
record = self.simulate_error()
|
record = self.simulate_error()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue