Skip to content

Commit 711436f

Browse files
committed
Add a simple test case which verifies that different values for "bufsize" argument don't hang
or block the Python action runner streaming output functionality.
1 parent 2f96d5d commit 711436f

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

contrib/runners/python_runner/tests/unit/test_pythonrunner.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,38 @@ def test_action_stdout_and_stderr_is_stored_in_the_db(self, mock_spawn, mock_pop
406406
self.assertEqual(output_dbs[1].data, mock_stderr[1])
407407
self.assertEqual(output_dbs[2].data, mock_stderr[2])
408408

409+
def test_real_time_output_streaming_bufsize(self):
410+
# Test various values for bufsize and verify it works / doesn't hang the process
411+
cfg.CONF.set_override(name='stream_output', group='actionrunner', override=True)
412+
413+
bufsize_values = [-100, -2, -1, 0, 1, 2, 1024, 2048, 4096, 10000]
414+
415+
for index, bufsize in enumerate(bufsize_values, 1):
416+
cfg.CONF.set_override(name='stream_output_buffer_size', override=bufsize,
417+
group='actionrunner')
418+
419+
output_dbs = ActionExecutionOutput.get_all()
420+
self.assertEqual(len(output_dbs), (index - 1) * 3)
421+
422+
runner = self._get_mock_runner_obj()
423+
runner.runner_parameters = {'log_level': 'INFO'}
424+
runner.entry_point = PASCAL_ROW_ACTION_PATH
425+
runner.pre_run()
426+
(_, output, _) = runner.run({'row_index': 2})
427+
428+
expected_stderr = ''.join([
429+
'st2.actions.python.PascalRowAction: INFO test info log message\n',
430+
'st2.actions.python.PascalRowAction: ERROR test error log message\n'
431+
])
432+
433+
self.assertEqual(output['stdout'], 'Pascal row action\n')
434+
self.assertEqual(output['stderr'], expected_stderr)
435+
self.assertEqual(output['result'], [1, 2, 1])
436+
self.assertEqual(output['exit_code'], 0)
437+
438+
output_dbs = ActionExecutionOutput.get_all()
439+
self.assertEqual(len(output_dbs), (index) * 3)
440+
409441
@mock.patch('st2common.util.concurrency.subprocess_popen')
410442
def test_stdout_interception_and_parsing(self, mock_popen):
411443
values = {'delimiter': ACTION_OUTPUT_RESULT_DELIMITER}

st2tests/st2tests/resources/packs/pythonactions/actions/pascal_row.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def run(self, **kwargs):
3636

3737
@staticmethod
3838
def _compute_pascal_row(row_index=0):
39+
print('Pascal row action')
40+
3941
if row_index == 'a':
4042
return False, 'This is suppose to fail don\'t worry!!'
4143
elif row_index == 'b':

0 commit comments

Comments
 (0)