Skip to content

Commit 6303601

Browse files
committed
refactor iop code to support multi-sync requests
1 parent d15ecf6 commit 6303601

File tree

7 files changed

+147
-1
lines changed

7 files changed

+147
-1
lines changed

src/tests/bench/bo.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from iop import BusinessOperation
2+
3+
class BenchIoPOperation(BusinessOperation):
4+
def on_message(self, request):
5+
6+
return request
7+
8+

src/tests/bench/bp.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from iop import BusinessProcess
2+
3+
class BenchIoPProcess(BusinessProcess):
4+
def on_init(self):
5+
if not hasattr(self, 'size'):
6+
self.size = 100
7+
8+
def on_message(self, request):
9+
for _ in range(self.size):
10+
_ = self.send_request_sync("Python.BenchIoPOperation",request)

src/tests/bench/msg.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from grongier.pex import Message
2+
from dataclasses import dataclass
3+
4+
@dataclass
5+
class MyMessage(Message):
6+
message : str = None

src/tests/bench/settings.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from bo import BenchIoPOperation
2+
from bp import BenchIoPProcess
3+
4+
import os
5+
6+
# get current directory
7+
current_dir = os.path.dirname(os.path.realpath(__file__))
8+
# get working directory
9+
working_dir = os.path.abspath(os.path.join(current_dir, os.pardir))
10+
# get the absolute path of 'src'
11+
src_dir = os.path.abspath(os.path.join(working_dir, os.pardir))
12+
13+
# create a strings with current_dir and src_dir with a | separator
14+
classpaths = f"{current_dir}|{src_dir}"
15+
16+
CLASSES = {
17+
"Python.BenchIoPOperation": BenchIoPOperation,
18+
"Python.BenchIoPProcess": BenchIoPProcess,
19+
}
20+
21+
PRODUCTIONS = [{
22+
"Bench.Production": {
23+
"@Name": "Bench.Production",
24+
"@TestingEnabled": "true",
25+
"@LogGeneralTraceEvents": "false",
26+
"Description": "",
27+
"ActorPoolSize": "1",
28+
"Item": [
29+
{
30+
"@Name": "Python.BenchIoPOperation",
31+
"@Category": "",
32+
"@ClassName": "Python.BenchIoPOperation",
33+
"@PoolSize": "1",
34+
"@Enabled": "true",
35+
"@Foreground": "false",
36+
"@Comment": "",
37+
"@LogTraceEvents": "false",
38+
"@Schedule": "",
39+
"Setting": {
40+
"@Target": "Host",
41+
"@Name": "%classpaths",
42+
"#text": classpaths
43+
}
44+
},
45+
{
46+
"@Name": "Python.BenchIoPProcess",
47+
"@Category": "",
48+
"@ClassName": "Python.BenchIoPProcess",
49+
"@PoolSize": "0",
50+
"@Enabled": "true",
51+
"@Foreground": "false",
52+
"@Comment": "",
53+
"@LogTraceEvents": "false",
54+
"@Schedule": "",
55+
"Setting": {
56+
"@Target": "Host",
57+
"@Name": "%classpaths",
58+
"#text": classpaths
59+
}
60+
}
61+
]
62+
}
63+
}
64+
]

src/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
# add registerFiles to the path
77
sys.path.append(join(join(root_dir, 'tests'), 'registerFiles'))
88

9-
from grongier.pex import Utils
9+
from iop import Utils
1010

1111
Utils.setup()

src/tests/test_bench.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from iop._director import _Director
2+
from iop._utils import _Utils
3+
4+
import timeit
5+
import os
6+
7+
import sys
8+
9+
class TestBenchIoP:
10+
11+
#before all tests
12+
@classmethod
13+
def setup_class(cls):
14+
# Add the 'bench' to sys.path
15+
sys.path.insert(0,os.path.abspath('src/tests/bench'))
16+
# migrate the production
17+
_Utils.migrate()
18+
# stop all productions
19+
_Director.stop_production()
20+
# set the default production
21+
_Director.set_default_production('Bench.Production')
22+
# start the production
23+
_Director.start_production()
24+
25+
def test_bench_iris_message(self):
26+
body = "test"
27+
result = timeit.timeit(lambda: _Director.test_component('Python.BenchIoPProcess','','iris.Ens.StringRequest',body), number=1)
28+
# print the time in pytest output
29+
print(f"Time: {result}")
30+
# assert the result
31+
assert result > 0
32+
33+
def test_bench_python_message(self):
34+
body = "test"*200000
35+
result = timeit.timeit(lambda: _Director.test_component('Python.BenchIoPProcess','','msg.MyMessage',f'{{"message":"{body}"}}'), number=1)
36+
# print the time in pytest output
37+
print(f"Time: {result}")
38+
# assert the result
39+
assert result > 0
40+
41+
#after all tests
42+
@classmethod
43+
def teardown_class(cls):
44+
# stop all productions
45+
_Director.stop_production()
46+
# set the default production
47+
_Director.set_default_production('test')
48+
# Remove the 'bench' from sys.path
49+
sys.path.remove(os.path.abspath('src/tests/bench'))

src/tests/test_iop_business_host.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@ def test_deseialize_message():
168168
assert msg.integer == 1
169169
assert msg.string == 'test'
170170

171+
def test_big_message():
172+
bh = _BusinessHost()
173+
huge_string = 'test'*1000000
174+
msg = TestSimpleMessage(integer=1, string=huge_string)
175+
result = bh._serialize_message(msg)
176+
msg = bh._deserialize_message(result)
177+
assert msg.integer == 1
178+
assert msg.string == huge_string
179+
171180
def test_deseialize_message_japanese():
172181
bh = _BusinessHost()
173182
msg = TestSimpleMessage(integer=1, string='あいうえお')

0 commit comments

Comments
 (0)