Skip to content

Commit

Permalink
Merge pull request #2599 from lunkwill42/test/ipdevpoll-process-pool-…
Browse files Browse the repository at this point in the history
…ping

Add unit tests for ipdevpoll worker euthanization
  • Loading branch information
lunkwill42 authored Mar 28, 2023
2 parents 9c3eaa5 + 52e8756 commit 7d47aa7
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/unittests/ipdevpoll/pool_test.py
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)

0 comments on commit 7d47aa7

Please sign in to comment.