@@ -36,7 +36,7 @@ def __init__(self, *args, **kwargs):
36
36
37
37
@classmethod
38
38
async def current_server (self ):
39
- await sleep (0 )
39
+ await sleep (0.05 )
40
40
return self .sessions [0 ]
41
41
42
42
async def connection_lost (self ):
@@ -190,12 +190,13 @@ async def test_error_base_cost(self, server_port):
190
190
server_session = await MyServerSession .current_server ()
191
191
server_session .error_base_cost = server_session .cost_hard_limit * 1.1
192
192
await session ._send_message (b'' )
193
- await sleep (0.01 )
193
+ await sleep (0.05 )
194
194
assert server_session .errors == 1
195
195
assert server_session .cost > server_session .cost_hard_limit
196
196
# Check next request raises and cuts us off
197
197
with pytest .raises (RPCError ):
198
198
await session .send_request ('echo' , [23 ])
199
+ await sleep (0.02 )
199
200
assert session .is_closing ()
200
201
201
202
@pytest .mark .asyncio
@@ -207,7 +208,7 @@ async def test_RPCError_cost(self, server_port):
207
208
with pytest .raises (RPCError ):
208
209
await session .send_request ('costly_error' , [1000 ])
209
210
# It can trigger a cost recalc which refunds a tad
210
- epsilon = 0. 1
211
+ epsilon = 1
211
212
assert server_session .cost > server_session .error_base_cost + 1000 - epsilon
212
213
213
214
@pytest .mark .asyncio
@@ -381,9 +382,9 @@ async def test_concurrency_decay(self, server_port):
381
382
async with connect_rs ('localhost' , server_port ) as session :
382
383
session .cost_decay_per_sec = 100
383
384
session .cost = 1000
384
- await sleep (0.01 )
385
+ await sleep (0.1 )
385
386
session .recalc_concurrency ()
386
- assert 990 < session .cost < 999.1
387
+ assert 970 < session .cost < 992
387
388
388
389
@pytest .mark .asyncio
389
390
async def test_concurrency_hard_limit_0 (self , server_port ):
@@ -442,14 +443,15 @@ async def test_reply_and_disconnect_value(self, server_port):
442
443
async with connect_rs ('localhost' , server_port ) as session :
443
444
value = 42
444
445
assert await session .send_request ('disconnect' , [value ]) == value
445
- await sleep (0 )
446
+ await sleep (0.01 )
446
447
assert session .is_closing ()
447
448
448
449
@pytest .mark .asyncio
449
450
async def test_reply_and_disconnect_error (self , server_port ):
450
451
async with connect_rs ('localhost' , server_port ) as session :
451
452
with pytest .raises (RPCError ) as e :
452
453
assert await session .send_request ('disconnect' )
454
+ await sleep (0.01 )
453
455
exc = e .value
454
456
assert exc .code == 1 and exc .message == 'incompatible version'
455
457
assert session .is_closing ()
@@ -806,6 +808,7 @@ async def test_errors(self, msg_server_port, caplog):
806
808
await session .send_message ((b'syntax' , b'' ))
807
809
await session .send_message ((b'protocol' , b'' ))
808
810
await session .send_message ((b'cancel' , b'' ))
811
+ await sleep (0.01 )
809
812
assert in_caplog (caplog , 'exception handling' )
810
813
assert in_caplog (caplog , 'Not allowed' )
811
814
@@ -814,6 +817,7 @@ async def test_bad_magic(self, msg_server_port, caplog):
814
817
framer = BitcoinFramer (magic = bytes (4 ))
815
818
async with connect_message_session ('localhost' , msg_server_port , framer = framer ) as session :
816
819
await session .send_message ((b'version' , b'' ))
820
+ await sleep (0.01 )
817
821
assert in_caplog (caplog , 'bad network magic' )
818
822
819
823
@pytest .mark .asyncio
@@ -822,6 +826,7 @@ async def test_bad_checksum(self, msg_server_port, caplog):
822
826
framer ._checksum = lambda payload : bytes (32 )
823
827
async with connect_message_session ('localhost' , msg_server_port , framer = framer ) as session :
824
828
await session .send_message ((b'version' , b'' ))
829
+ await sleep (0.01 )
825
830
assert in_caplog (caplog , 'checksum mismatch' )
826
831
827
832
@pytest .mark .asyncio
@@ -832,6 +837,7 @@ async def test_oversized_message(self, msg_server_port, caplog):
832
837
assert not in_caplog (caplog , 'oversized payload' )
833
838
async with connect_message_session ('localhost' , msg_server_port ) as session :
834
839
await session .send_message ((b'version' , bytes (big + 1 )))
840
+ await sleep (0.01 )
835
841
assert in_caplog (caplog , 'oversized payload' )
836
842
837
843
@pytest .mark .asyncio
@@ -855,7 +861,7 @@ async def test_request_over_hard_limit(self, msg_server_port):
855
861
server = await MessageServer .current_server ()
856
862
server .bump_cost (server .cost_hard_limit + 100 )
857
863
await session .send_message ((b'version' , b'abc' ))
858
- await sleep (0.005 )
864
+ await sleep (0.05 )
859
865
assert session .is_closing ()
860
866
861
867
@pytest .mark .asyncio
@@ -867,6 +873,7 @@ async def test_server_busy(self, msg_server_port, caplog):
867
873
await session .send_message ((b'sleep' , b'' ))
868
874
await sleep (0.02 )
869
875
assert server .errors == 1
876
+ await sleep (0.01 )
870
877
assert in_caplog (caplog , 'timed out' )
871
878
872
879
0 commit comments