-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2599 from lunkwill42/test/ipdevpoll-process-pool-…
…ping Add unit tests for ipdevpoll worker euthanization
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import signal | ||
from unittest.mock import patch, Mock | ||
|
||
import pytest | ||
import pytest_twisted | ||
import twisted.internet.defer | ||
|
||
from nav.ipdevpoll.pool import Worker | ||
|
||
|
||
class TestWorker: | ||
@pytest.mark.twisted | ||
@pytest_twisted.inlineCallbacks | ||
def test_mock_process_should_not_respond_to_ping(self): | ||
worker = Worker(pool=None, threadpoolsize=0, max_jobs=5) | ||
worker.process = Mock() | ||
ping_response = yield worker.responds_to_ping() | ||
assert not ping_response # Mock process cannot respond | ||
|
||
@pytest.mark.twisted | ||
@pytest_twisted.inlineCallbacks | ||
def test_unresponsive_worker_should_be_euthanized(self): | ||
worker = Worker(pool=None, threadpoolsize=0, max_jobs=5) | ||
worker._pid = 666 | ||
with patch.object(worker, 'responds_to_ping') as ping: | ||
ping.side_effect = twisted.internet.defer.TimeoutError("Mock timeout") | ||
with patch('os.kill') as mock_kill: | ||
yield worker._euthanize_unresponsive_worker() | ||
|
||
mock_kill.assert_called_with(worker.pid, signal.SIGTERM) |