Skip to content

Commit

Permalink
Change to enable running two unit tests on MacOS (#210)
Browse files Browse the repository at this point in the history
* Increase sleep time in run_interactive_interrupt and run tests on MacOS

In my testing on MacOS, the "test_interactive_interrupt" test passed without
any changes needed, and the "test_headless_interrupt" test only needed to have
this sleep time increased to pass.

* Use different sleep time in test depending on platform

The previous commit caused a unit test to fail on Linux.  This change fixes
that.

* Increase timeout value passed to find_embedding() call in test

* Raise time threshold for exit condition in unit test

* Skip two unit tests on win32 platform
  • Loading branch information
Tim Doyle authored May 20, 2022
1 parent be818c3 commit eb1caec
Showing 1 changed file with 6 additions and 36 deletions.
42 changes: 6 additions & 36 deletions tests/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import signal
import multiprocessing
import unittest
from unittest import SkipTest

# Given that this test is in the tests directory, the calibration data should be
# in a sub directory. Use the path of this source file to find the calibration
Expand Down Expand Up @@ -346,14 +345,6 @@ def check_args(Q, A, initial_chains=None, fixed_chains=None, restrict_chains=Non
u, fullset)) & edgelord, "%s and %s are connected as variables but not as domains" % (u, v)


def skip_if(cond):
if cond:
def _skip():
raise SkipTest
return lambda f: _skip
else:
return lambda f: f

class TestFindEmbedding(unittest.TestCase):
@staticmethod
@success_count(100, 5)
Expand Down Expand Up @@ -848,34 +839,13 @@ def test_variable_components_many():
return find_embedding(K, C, tries=1, chainlength_patience=0)

@staticmethod
@skip_if(
# there appears to be a bug in the osx, py3.8+ version of multiprocessing.
# this has turned into a yak-shaving exercise and I'm not doing any more here
# for the time being -- #TODO if anybody has a mac and they wanna dig in, please do
(sys.version_info[:2] >= (3, 8) and sys.platform == 'darwin') or
# TODO this test seems to actually work on windows but it's doing something funky
# to our appveyor framework. Giving up on yak-shaving 'cause we're going to retire
# appveyor soon
(sys.platform == 'win32')
)
@staticmethod
@unittest.skipIf(sys.platform == 'win32', 'Test may hang on win32, skipping out of caution')
@success_perfect(1)
def test_interactive_interrupt():
return run_interactive_interrupt(True) == 0

@staticmethod
@skip_if(
# there appears to be a bug in the osx, py3.8+ version of multiprocessing.
# this has turned into a yak-shaving exercise and I'm not doing any more here
# for the time being -- #TODO if anybody has a mac and they wanna dig in, please do
(sys.version_info[:2] >= (3, 8) and sys.platform == 'darwin') or
# TODO this test seems to actually work on windows but it's doing something funky
# to our appveyor framework. Giving up on yak-shaving 'cause we're going to retire
# appveyor soon
(sys.platform == 'win32')
)
@unittest.skipIf(sys.platform == 'win32', 'Test hangs on win32')
@success_perfect(1)
def test_headless_interrupt():
return run_interactive_interrupt(False) == 2
Expand All @@ -887,11 +857,11 @@ def _long_running_successful_problem(interactive):
t0 = time.perf_counter()
try:
find_embedding_orig(C, C, chainlength_patience=1 << 20,
interactive=interactive, timeout=1)
interactive=interactive, timeout=2)
except KeyboardInterrupt:
sys.exit(2)
if time.perf_counter() - t0 > .5:
# be a little generous here... but the caller should kill this in way less than .5s
if time.perf_counter() - t0 > 1.5:
# be a little generous here... but the caller should kill this in way less than 1.5s
sys.exit(1)


Expand All @@ -904,7 +874,7 @@ def run_interactive_interrupt(interactive):
p = multiprocessing.Process(
target=_long_running_successful_problem, args=(interactive,))
p.start()
time.sleep(.1)
time.sleep(.1 if sys.platform == 'linux' else 1)
os.kill(p.pid, ctrl_c)
p.join()
# exitcode 0: terminated successfully (interactive mode catches the interrupt)
Expand Down

0 comments on commit eb1caec

Please sign in to comment.