Skip to content

Commit

Permalink
Merge pull request #164 from ferozsalam/speed-up-unit-tests
Browse files Browse the repository at this point in the history
Speed up unit tests by adding default parallelism
  • Loading branch information
jertel authored May 18, 2021
2 parents a3fc7de + c4bba1e commit ee212fd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
## Other changes
- None

# Unreleased

## Breaking changes
- None

## New features
- None

## Other changes
- Speed up unit tests by adding default parallelism - [164](https://github.com/jertel/elastalert2/pull/164) - @ferozsalam

# 2.1.0

## Breaking changes
Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ m2r2
pluggy>=0.12.0
pre-commit
pylint<2.9
pytest<3.7.0
pytest==6.0.0
pytest-xdist==2.2.1
setuptools
sphinx_rtd_theme
tox==3.23.1
12 changes: 6 additions & 6 deletions tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ def test_wait_until_responsive(ea):
]


def test_wait_until_responsive_timeout_es_not_available(ea, capsys):
def test_wait_until_responsive_timeout_es_not_available(ea, caplog):
"""Bail out if ElasticSearch doesn't (quickly) become responsive."""

# Never becomes responsive :-)
Expand All @@ -1175,8 +1175,8 @@ def test_wait_until_responsive_timeout_es_not_available(ea, capsys):
assert exc.value.code == 1

# Ensure we get useful diagnostics.
output, errors = capsys.readouterr()
assert 'Could not reach ElasticSearch at "es:14900".' in errors
user, level, message = caplog.record_tuples[0]
assert 'Could not reach ElasticSearch at "es:14900".' in message

# Slept until we passed the deadline.
sleep.mock_calls == [
Expand All @@ -1186,7 +1186,7 @@ def test_wait_until_responsive_timeout_es_not_available(ea, capsys):
]


def test_wait_until_responsive_timeout_index_does_not_exist(ea, capsys):
def test_wait_until_responsive_timeout_index_does_not_exist(ea, caplog):
"""Bail out if ElasticSearch doesn't (quickly) become responsive."""

# Never becomes responsive :-)
Expand All @@ -1202,8 +1202,8 @@ def test_wait_until_responsive_timeout_index_does_not_exist(ea, capsys):
assert exc.value.code == 1

# Ensure we get useful diagnostics.
output, errors = capsys.readouterr()
assert 'Writeback alias "wb_a" does not exist, did you run `elastalert-create-index`?' in errors
user, level, message = caplog.record_tuples[0]
assert 'Writeback alias "wb_a" does not exist, did you run `elastalert-create-index`?' in message

# Slept until we passed the deadline.
sleep.mock_calls == [
Expand Down
2 changes: 1 addition & 1 deletion tests/loaders_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def test_raises_on_missing_config():
mock_rule_open.return_value = test_rule_copy
with mock.patch('os.walk') as mock_walk:
mock_walk.return_value = [('', [], ['testrule.yaml'])]
with pytest.raises(EAException, message='key %s should be required' % key):
with pytest.raises(EAException):
rules = load_conf(test_args)
rules['rules'] = rules['rules_loader'].load(rules)

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ envlist = py39,docs
[testenv]
deps = -rrequirements-dev.txt
commands =
coverage run --source=elastalert/,tests/ -m pytest --strict {posargs}
coverage run --source=elastalert/,tests/ -m pytest --strict -n 4 {posargs}
coverage report -m
flake8 .

Expand Down

0 comments on commit ee212fd

Please sign in to comment.