Skip to content

Commit

Permalink
fixing test signal handling
Browse files Browse the repository at this point in the history
signal handling has changed and there is a ValueError if a subthread is trying to do signal handling. This signal mocking is addressing this issue
  • Loading branch information
viennaa committed Feb 26, 2024
1 parent 1948bfc commit 1fc2086
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tests/TestCollectors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys

sys.path.append('.')
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch
from threading import Thread
from exporter import run_prometheus_server
from tools.helper import yaml_read
Expand Down Expand Up @@ -29,7 +29,8 @@ def test_environment(self):
self.assertTrue(os.getenv('TARGET'), 'no target set')
self.assertEqual(os.getenv('TARGET'), "vrops-vcenter-test.company.com", "The test must be run with the target: vrops-vcenter-test.company.com")

def test_collector_metrics(self):
@patch('exporter.signal.signal')
def test_collector_metrics(self, mock_signal):
self.metrics_yaml = yaml_read('tests/metrics.yaml')
self.collector_config = yaml_read(os.environ['COLLECTOR_CONFIG'])
self.target = os.getenv('TARGET')
Expand Down Expand Up @@ -191,7 +192,7 @@ def create_resource_objects(resourcekind) -> list:

# start prometheus server to provide metrics later on

thread1 = Thread(target=run_prometheus_server, args=(self.random_prometheus_port, [collector_instance]))
thread1 = Thread(target=run_prometheus_server, args=(self.random_prometheus_port, [collector_instance], mock_signal))
thread1.daemon = True
thread1.start()
thread_list.append(thread1)
Expand Down

0 comments on commit 1fc2086

Please sign in to comment.