Skip to content

Commit 3894d04

Browse files
committed
make tests/timings easier for CI tests
1 parent 405a89f commit 3894d04

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

test/test_message_sync.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,23 @@
1616

1717
from can import MessageSync, Message
1818

19-
from .config import IS_APPVEYOR
19+
from .config import IS_APPVEYOR, IS_CI
2020
from .message_helper import ComparingMessagesTestCase
2121
from .data.example_data import TEST_MESSAGES_BASE
2222

23+
2324
TEST_FEWER_MESSAGES = TEST_MESSAGES_BASE[::2]
2425

2526

27+
def inc(value):
28+
if IS_CI:
29+
return value * 1.5
30+
else:
31+
return value
32+
33+
2634
@unittest.skipIf(IS_APPVEYOR, "this environment's timings are too unpredictable")
27-
class TestMessageFiltering(unittest.TestCase, ComparingMessagesTestCase):
35+
class TestMessageSync(unittest.TestCase, ComparingMessagesTestCase):
2836

2937
def __init__(self, *args, **kwargs):
3038
unittest.TestCase.__init__(self, *args, **kwargs)
@@ -56,15 +64,14 @@ def test_general(self):
5664
timings.append(now - start)
5765
start = now
5866

59-
6067
self.assertMessagesEqual(messages, collected)
6168
self.assertEqual(len(timings), len(messages), "programming error in test code")
6269

63-
self.assertTrue(0.0 <= timings[0] < 0.005, str(timings[0]))
64-
self.assertTrue(0.0 <= timings[1] < 0.005, str(timings[1]))
65-
self.assertTrue(0.045 <= timings[2] < 0.055, str(timings[2]))
66-
self.assertTrue(0.075 <= timings[3] < 0.085, str(timings[3]))
67-
self.assertTrue(0.0 <= timings[4] < 0.005, str(timings[4]))
70+
self.assertTrue(0.0 <= timings[0] < inc(0.005), str(timings[0]))
71+
self.assertTrue(0.0 <= timings[1] < inc(0.005), str(timings[1]))
72+
self.assertTrue(0.045 <= timings[2] < inc(0.055), str(timings[2]))
73+
self.assertTrue(0.075 <= timings[3] < inc(0.085), str(timings[3]))
74+
self.assertTrue(0.0 <= timings[4] < inc(0.005), str(timings[4]))
6875

6976
@pytest.mark.timeout(0.1 * len(TEST_FEWER_MESSAGES)) # very conservative
7077
def test_skip(self):
@@ -77,7 +84,7 @@ def test_skip(self):
7784
took = after - before
7885

7986
# the handling of the messages itself also take time: ~0.001 s/msg on my laptop
80-
assert 0 < took < len(messages) * (0.005 + 0.003), "took: {}s".format(took)
87+
assert 0 < took < inc(len(messages) * (0.005 + 0.003)), "took: {}s".format(took)
8188

8289
self.assertMessagesEqual(messages, collected)
8390

@@ -104,7 +111,7 @@ def test_gap(timestamp_1, timestamp_2):
104111
gc.enable()
105112
took = after - before
106113

107-
assert 0.1 <= took < 0.3
114+
assert 0.1 <= took < inc(0.3)
108115
assert messages == collected
109116

110117

0 commit comments

Comments
 (0)