Skip to content

Commit

Permalink
correctly flush printed output
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-mangin committed Jul 14, 2024
1 parent fa80cdb commit c572ac3
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions qa/bin/functional
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class Alarm(Exception):
pass


def flush(*args, **kwars):
print(*args, **kwars)
sys.stdout.flush()


def alarm_handler(number, frame): # pylint: disable=W0613
raise Alarm()

Expand Down Expand Up @@ -127,12 +132,12 @@ class Exec(object):
return True

def report(self, reason='issue with exabgp'):
print(reason)
print(f'> {self.command}')
print(f'return: {self.code}')
print(f'stdout: {self.stdout.decode()}')
print(f'stderr: {self.stderr.decode()}')
print(f'message: {self.message}')
flush(reason)
flush(f'command> {self.command}')
flush(f'return: {self.code}')
flush(f'stdout: {self.stdout.decode()}')
flush(f'stderr: {self.stderr.decode()}')
flush(f'message: {self.message}')

def collect(self):
if self.stdout:
Expand Down Expand Up @@ -377,7 +382,7 @@ class EncodingTests(Tests):
template += 'export exabgp_debug_rotate=true\n'
template += 'export exabgp_debug_defensive=true\n'

print(
flush(
template
% {
'client': self.client(nick),
Expand Down Expand Up @@ -701,7 +706,7 @@ def add_test(subparser, name, tests, extra):
sys.exit('no file for the test')
editor = os.environ.get('EDITOR', 'vi')
command = '%s %s' % (editor, ' '.join(test.files))
print(f'> {command}')
flush(f'> {command}')
if not parsed.dry:
sys.exit(os.system(command))
return
Expand All @@ -712,14 +717,14 @@ def add_test(subparser, name, tests, extra):

if 'client' in extra and parsed.client:
command = tests.client(parsed.test)
print(f'> {command}')
flush(f'client> {command}')
if not parsed.dry:
sys.exit(os.system(command))
return

if 'server' in extra and parsed.server:
command = tests.server(parsed.test)
print(f'> {command}')
flush(f'server> {command}')
if not parsed.dry:
sys.exit(os.system(command))
return
Expand All @@ -735,7 +740,7 @@ def add_test(subparser, name, tests, extra):

if parsed.dry:
command = tests.dry()
print(command)
flush(command)
sys.exit(0)

exit = tests.run_selected(parsed.timeout)
Expand Down

0 comments on commit c572ac3

Please sign in to comment.