tests: Count bytes written in stdio_test.StdIOTest

This is mainly for peace of mind. With all this non-blocking IO investigation
I'm getting a bit paranoid wrt file objects.

refs #712
pull/1307/head
Alex Willmer 4 months ago
parent 3dfaf83ce7
commit 76f6eb741d

@ -24,6 +24,7 @@ In progress (unreleased)
* :gh:issue:`1306` CI: Report sudo version on Ansible targets
* :gh:issue:`1306` CI: Move sudo test users defaults into ``/etc/sudoers.d``
* :gh:issue:`1306` preamble_size: Fix variability of measured command size
* :gh:issue:`1306` tests: Count bytes written in ``stdio_test.StdIOTest``
v0.3.27 (2025-08-20)

@ -3,9 +3,24 @@ import os
import sys
def _shout_stdout_py3(size):
nwritten = sys.stdout.write('A' * size)
return nwritten
def _shout_stdout_py2(size):
shout = 'A' * size
nwritten = 0
while nwritten < size:
nwritten += os.write(sys.stdout.fileno(), shout[-nwritten:])
return nwritten
def shout_stdout(size):
sys.stdout.write('A' * size)
return 'success'
if sys.version_info > (3, 0):
return _shout_stdout_py3(size)
else:
return _shout_stdout_py2(size)
def file_is_blocking(fobj):

@ -15,8 +15,8 @@ class StdIOTest(testlib.RouterMixin, testlib.TestCase):
"""
size = 1 * 2**20
context = self.router.local()
result = context.call(stdio_checks.shout_stdout, size)
self.assertEqual('success', result)
nwritten = context.call(stdio_checks.shout_stdout, size)
self.assertEqual(nwritten, size)
def test_stdio_is_blocking(self):
context = self.router.local()

Loading…
Cancel
Save