-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathtest_timeout.py
executable file
·71 lines (62 loc) · 2.62 KB
/
test_timeout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# SPDX-FileCopyrightText: 2013 SAP SE Srdjan Boskovic <srdjan.boskovic@sap.com>
#
# SPDX-License-Identifier: Apache-2.0
import pytest
from pyrfc import Connection, RFCError, ExternalRuntimeError
from tests.config import CONNECTION_DEST
client = Connection(**CONNECTION_DEST)
class TestTimeout:
def test_timeout_call(self):
with pytest.raises(RFCError) as ex:
# Cancel 10 seconds long RFC call after 5 seconds
client.call(
"RFC_PING_AND_WAIT",
options={"timeout": 5},
SECONDS=10,
)
error = ex.value
assert error.code == 7
assert error.key == "RFC_CANCELED"
assert "Connection was canceled" in error.message
# ensure new connection replaced the canceled one
assert client.alive is True
def test_timeout_call_expired(self):
old_handle = client.handle
# Cancel 5 seconds long RFC call after 10 seconds
res = client.call("RFC_PING_AND_WAIT", options={"timeout": 10}, SECONDS=5)
assert res == {}
assert client.alive is True
assert client.handle == old_handle
def test_timeout_connection(self):
client = Connection(**CONNECTION_DEST, config={"timeout": 5})
with pytest.raises(RFCError) as ex:
# Cancel 10 seconds long RFC call after 5 seconds, set on connection
client.call("RFC_PING_AND_WAIT", SECONDS=10)
error = ex.value
assert error.code == 7
assert error.key == "RFC_CANCELED"
assert "Connection was canceled" in error.message
# ensure new connection replaced the cancelled one
assert client.alive is True
def test_timeout_connection_override(self):
client = Connection(**CONNECTION_DEST, config={"timeout": 15})
with pytest.raises(RFCError) as ex:
# Cancel 10 seconds long RFC call after 5 seconds, set on call
client.call(
"RFC_PING_AND_WAIT",
options={"timeout": 5},
SECONDS=10,
)
error = ex.value
assert error.code == 7
assert error.key == "RFC_CANCELED"
assert "Connection was canceled" in error.args[0]
# ensure new connection replaced the canceled one
assert client.alive is True
def test_timeout_with_rfc_error(self):
with pytest.raises(ExternalRuntimeError) as ex:
client.call("STFC_CONNECTION", options={"timeout": 60}, undefined=0)
error = ex.value
assert error.code == 20
assert error.key == "RFC_INVALID_PARAMETER"
assert error.message == "field 'undefined' not found"