siso: remove redundant test and consolidate dead then healthy tests.

Bug: b/459690822
Change-Id: I7e3a342d3e5be7b5802275cdce0db2ec6a6a6964
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7244732
Reviewed-by: Fumitoshi Ukai <ukai@google.com>
Reviewed-by: Philipp Wollermann <philwo@google.com>
Commit-Queue: Alex Ovsienko <ovsienko@google.com>
This commit is contained in:
Alex Ovsienko
2025-12-09 22:48:30 -08:00
committed by LUCI CQ
parent a6671ce6c7
commit ecbf89e1da

View File

@@ -930,9 +930,24 @@ ninja --failure_verbose=false -k=0
self.assertFalse(result)
m.is_subcommand_present.assert_called_once_with(siso_path, 'collector')
@mock.patch('sys.platform', new='linux')
@mock.patch('siso.json.loads')
def test_start_collector_dead_then_healthy(self, mock_json_loads):
test_cases = {
'linux': {
'platform': 'linux',
'creationflags': 0,
},
'windows': {
'platform': 'win32',
'creationflags': 512, # subprocess.CREATE_NEW_PROCESS_GROUP
}
}
for name, tc in test_cases.items():
with self.subTest(name), \
mock.patch('sys.platform', new=tc['platform']), \
mock.patch('subprocess.CREATE_NEW_PROCESS_GROUP',
tc['creationflags'], create=True):
m = self._start_collector_mocks()
siso_path = "siso_path"
project = "test-project"
@@ -940,15 +955,9 @@ ninja --failure_verbose=false -k=0
self._configure_http_responses(m.mock_conn,
status_responses=[(404, None),
(200, None)],
config_responses=[(200, None),
(200, None)])
config_responses=[(200, None)])
status_healthy = {'healthy': True, 'status': 'StatusOK'}
config_project_full = {
'exporters': {
'googlecloud': {
'project': project
}
},
config = {
'receivers': {
'otlp': {
'protocols': {
@@ -959,9 +968,7 @@ ninja --failure_verbose=false -k=0
}
}
}
mock_json_loads.side_effect = [
status_healthy, config_project_full, config_project_full
]
mock_json_loads.side_effect = [status_healthy, config]
result = siso._start_collector(siso_path, None, project)
@@ -971,8 +978,9 @@ ninja --failure_verbose=false -k=0
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
start_new_session=True,
creationflags=0)
creationflags=tc['creationflags'])
m.kill_collector.assert_not_called()
mock_json_loads.reset_mock()
@mock.patch('sys.platform', new='linux')
@mock.patch('siso.json.loads')
@@ -1020,92 +1028,7 @@ ninja --failure_verbose=false -k=0
creationflags=0)
m.kill_collector.assert_called_once()
@mock.patch('sys.platform', new='win32')
@mock.patch('siso.json.loads')
def test_start_collector_dead_then_healthy_windows(self, mock_json_loads):
m = self._start_collector_mocks()
siso_path = "siso_path"
project = "test-project"
self._configure_http_responses(m.mock_conn,
status_responses=[(404, None),
(200, None)],
config_responses=[(200, None),
(200, None)])
status_healthy = {'healthy': True, 'status': 'StatusOK'}
config_project_full = {
'exporters': {
'googlecloud': {
'project': project
}
},
'receivers': {
'otlp': {
'protocols': {
'grpc': {
'endpoint': siso._OTLP_DEFAULT_TCP_ENDPOINT
}
}
}
}
}
mock_json_loads.side_effect = [
status_healthy, config_project_full, config_project_full
]
# On non-Windows platforms, subprocess.CREATE_NEW_PROCESS_GROUP does not exist.
# We mock it here to make the test runnable on all platforms.
with mock.patch('subprocess.CREATE_NEW_PROCESS_GROUP', 512,
create=True):
result = siso._start_collector(siso_path, None, project)
self.assertTrue(result)
m.subprocess_popen.assert_called_once_with(
[siso_path, "collector", "--project", project],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
start_new_session=True,
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP)
m.kill_collector.assert_not_called()
@mock.patch('sys.platform', new='linux')
@mock.patch('siso.json.loads')
def test_start_collector_wrong_project_no_restart(self, mock_json_loads):
m = self._start_collector_mocks()
siso_path = "siso_path"
project = "test-project"
self._configure_http_responses(m.mock_conn,
status_responses=[(200, None),
(200, None)],
config_responses=[(200, None),
(200, None)])
status_healthy = {'healthy': True, 'status': 'StatusOK'}
config_wrong_project_full = {
'exporters': {
'googlecloud': {
'project': 'wrong-project'
}
},
'receivers': {
'otlp': {
'protocols': {
'grpc': {
'endpoint': siso._OTLP_DEFAULT_TCP_ENDPOINT
}
}
}
}
}
mock_json_loads.side_effect = [
status_healthy, config_wrong_project_full
]
result = siso._start_collector(siso_path, None, project)
self.assertTrue(result)
m.subprocess_popen.assert_not_called()
m.kill_collector.assert_not_called()
@mock.patch('siso.json.loads')
def test_start_collector_already_healthy(self, mock_json_loads):