|
19 | 19 | import os |
20 | 20 | import time |
21 | 21 | import shlex |
| 22 | +import platform |
22 | 23 | import requests |
23 | 24 | import urllib |
24 | | -from subprocess import Popen, PIPE |
| 25 | +from subprocess import Popen, PIPE, TimeoutExpired |
25 | 26 | from copy import deepcopy |
26 | 27 | from ssh import LocalClient |
27 | 28 | from tool import DirectoryUtil |
@@ -380,20 +381,42 @@ def return_true(**kw): |
380 | 381 | LocalClient.execute_command('%s "alter system set _enable_static_typing_engine = %s;select sleep(2);"' % (exec_sql_cmd, opt['_enable_static_typing_engine']), stdio=stdio) |
381 | 382 |
|
382 | 383 | start_time = time.time() |
383 | | - cmd = 'timeout %s %s %s' % (case_timeout, mysqltest_bin, str(Arguments(opt))) |
| 384 | + IS_DARWIN = platform.system() == 'Darwin' |
| 385 | + if IS_DARWIN: |
| 386 | + # macOS does not have GNU timeout; use Python subprocess timeout instead |
| 387 | + cmd = '%s %s' % (mysqltest_bin, str(Arguments(opt))) |
| 388 | + else: |
| 389 | + cmd = 'timeout %s %s %s' % (case_timeout, mysqltest_bin, str(Arguments(opt))) |
384 | 390 | try: |
385 | 391 | stdio.verbose('local execute: %s ' % cmd) |
386 | 392 | p = Popen(shlex.split(cmd), env=test_env, stdout=PIPE, stderr=PIPE) |
387 | | - output, errput = p.communicate() |
388 | | - retcode = p.returncode |
389 | | - if retcode == 124: |
390 | | - output = '' |
391 | | - if 'source_limit' in opt and 'g.buffer' in opt['source_limit']: |
392 | | - errput = "%s secs out of soft limit (%s secs), sql may be hung, please check" % (opt['source_limit']['g.buffer'], case_timeout) |
| 393 | + if IS_DARWIN: |
| 394 | + try: |
| 395 | + output, errput = p.communicate(timeout=case_timeout) |
| 396 | + except TimeoutExpired: |
| 397 | + p.kill() |
| 398 | + output, errput = p.communicate() |
| 399 | + retcode = 124 # mimic GNU timeout exit code |
| 400 | + output = '' |
| 401 | + if 'source_limit' in opt and 'g.buffer' in opt['source_limit']: |
| 402 | + errput = "%s secs out of soft limit (%s secs), sql may be hung, please check" % (opt['source_limit']['g.buffer'], case_timeout) |
| 403 | + else: |
| 404 | + errput = "%s seconds timeout, sql may be hung, please check" % case_timeout |
393 | 405 | else: |
394 | | - errput = "%s seconds timeout, sql may be hung, please check" % case_timeout |
395 | | - elif isinstance(errput, bytes): |
396 | | - errput = errput.decode(errors='replace') |
| 406 | + retcode = p.returncode |
| 407 | + if isinstance(errput, bytes): |
| 408 | + errput = errput.decode(errors='replace') |
| 409 | + else: |
| 410 | + output, errput = p.communicate() |
| 411 | + retcode = p.returncode |
| 412 | + if retcode == 124: |
| 413 | + output = '' |
| 414 | + if 'source_limit' in opt and 'g.buffer' in opt['source_limit']: |
| 415 | + errput = "%s secs out of soft limit (%s secs), sql may be hung, please check" % (opt['source_limit']['g.buffer'], case_timeout) |
| 416 | + else: |
| 417 | + errput = "%s seconds timeout, sql may be hung, please check" % case_timeout |
| 418 | + elif isinstance(errput, bytes): |
| 419 | + errput = errput.decode(errors='replace') |
397 | 420 | except Exception as e: |
398 | 421 | errput = str(e) |
399 | 422 | output = '' |
|
0 commit comments