Skip to content

Commit e446a46

Browse files
committed
Use a separate action for bufsize test case.
1 parent e7d62d1 commit e446a46

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363

6464
PRINT_CONFIG_ITEM_ACTION = os.path.join(tests_base.get_resources_path(), 'packs',
6565
'pythonactions/actions/print_config_item_doesnt_exist.py')
66+
PRINT_TO_STDOUT_STDERR_ACTION = os.path.join(tests_base.get_resources_path(), 'packs',
67+
'pythonactions/actions/print_to_stdout_and_stderr.py')
6668

6769

6870
# Note: runner inherits parent args which doesn't work with tests since test pass additional
@@ -417,26 +419,19 @@ def test_real_time_output_streaming_bufsize(self):
417419
group='actionrunner')
418420

419421
output_dbs = ActionExecutionOutput.get_all()
420-
self.assertEqual(len(output_dbs), (index - 1) * 3)
422+
self.assertEqual(len(output_dbs), (index - 1) * 4)
421423

422424
runner = self._get_mock_runner_obj()
423-
runner.runner_parameters = {'log_level': 'INFO'}
424-
runner.entry_point = PASCAL_ROW_ACTION_PATH
425+
runner.entry_point = PRINT_TO_STDOUT_STDERR_ACTION
425426
runner.pre_run()
426-
(_, output, _) = runner.run({'row_index': 2})
427+
(_, output, _) = runner.run({'stdout_count': 2, 'stderr_count': 2})
427428

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])
429+
self.assertEqual(output['stdout'], 'stdout line 0\nstdout line 1\n')
430+
self.assertEqual(output['stderr'], 'stderr line 0\nstderr line 1\n')
436431
self.assertEqual(output['exit_code'], 0)
437432

438433
output_dbs = ActionExecutionOutput.get_all()
439-
self.assertEqual(len(output_dbs), (index) * 3)
434+
self.assertEqual(len(output_dbs), (index) * 4)
440435

441436
@mock.patch('st2common.util.concurrency.subprocess_popen')
442437
def test_stdout_interception_and_parsing(self, mock_popen):
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2019 Extreme Networks, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import absolute_import
16+
17+
import sys
18+
19+
from st2common.runners.base_action import Action
20+
from six.moves import range
21+
22+
23+
class PrintToStdoutAndStderrAction(Action):
24+
def run(self, stdout_count=3, stderr_count=3):
25+
for index in range(0, stdout_count):
26+
sys.stdout.write('stdout line %s\n' % (index))
27+
28+
for index in range(0, stderr_count):
29+
sys.stderr.write('stderr line %s\n' % (index))

0 commit comments

Comments
 (0)