Skip to content

Commit dd9829b

Browse files
authored
Merge pull request #53 from eldaduzman/TASK/#49
add concurrent code testing
2 parents 0e63734 + 0f68fac commit dd9829b

File tree

7 files changed

+120
-24
lines changed

7 files changed

+120
-24
lines changed

.github/workflows/tox-action.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ jobs:
2727
2828
- name: test with tox
2929
run: tox
30+
31+
- name: Test Reporter
32+
uses: actions/upload-artifact@v1
33+
with:
34+
name: rf-tests-report-${{ matrix.os }}-${{ matrix.python_version }}-${{ matrix.rbf_version }}
35+
path: ./TEST_GeventLibrary.xml
36+

atests/pylibs/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import asyncio
2+
import time
3+
from gevent import joinall, spawn, pool
4+
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
5+
6+
7+
def sleep_threading(iterations: int, seconds: int):
8+
with ThreadPoolExecutor(10) as t:
9+
futures = [t.submit(time.sleep, seconds) for _ in range(iterations)]
10+
11+
for f in futures:
12+
f.result()
13+
14+
15+
def sleep_processing(iterations: int, seconds: int):
16+
with ProcessPoolExecutor(10) as t:
17+
futures = [t.submit(time.sleep, seconds) for _ in range(iterations)]
18+
19+
for f in futures:
20+
f.result()
21+
22+
23+
def sleep_gevent_coros(iterations: int, seconds: int):
24+
jobs = [spawn(time.sleep, seconds) for _ in range(iterations)]
25+
_ = joinall(jobs, timeout=30)
26+
27+
28+
def sleep_asyncio(iterations: int, seconds: int):
29+
async def do_something():
30+
jobs = [asyncio.sleep(seconds) for _ in range(iterations)]
31+
_ = await asyncio.gather(*jobs)
32+
33+
loop = asyncio.get_event_loop()
34+
loop.run_until_complete(do_something())

atests/simple-test.robot

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ Library Collections
66
Library String
77
Library GeventLibrary
88
Library RequestsLibrary
9+
Library ./pylibs/__init__.py
10+
11+
Test Teardown Clear All Bundles
912

10-
Suite Teardown Clear All Bundles
1113

1214
*** Test Cases ***
1315
Test1
1416
[Documentation] Simple test flow with gevent greenlets
1517
Log Hello World
1618
Create Gevent Bundle alias=alias1
17-
Sleep 10s alias=alias1 # synchronous keyword
19+
Sleep 5s alias=alias1 # synchronous keyword
1820
Add Coroutine Sleep Wrapper alias=alias1
19-
Add Coroutine Sleep time_=20s alias=alias1
20-
Add Coroutine Sleep 10s alias=alias1
21+
Add Coroutine Sleep time_=10s alias=alias1
22+
Add Coroutine Sleep 5s alias=alias1
2123
Add Coroutine GET https://jsonplaceholder.typicode.com/posts/1 alias=alias1
2224
Add Coroutine Convert To Lower Case UPPER
2325
Add Coroutine Convert To Integer 1
@@ -39,6 +41,37 @@ Test2
3941
${values} Run Coroutines alias=alias2 gevent_pool_size=40
4042
Log Many @{values}
4143

44+
Test3
45+
[Documentation] Testing a concurrent keyword with threads
46+
Create Gevent Bundle alias=alias1
47+
Add Coroutine Sleep Threading 2 7 alias=alias1
48+
Add Coroutine Sleep 5s alias=alias1
49+
${values} Run Coroutines alias=alias1
50+
Log Many @{values}
51+
52+
Test4
53+
[Documentation] Testing a concurrent keyword with processes
54+
Create Gevent Bundle alias=alias1
55+
Add Coroutine Sleep Processing 2 7 alias=alias1
56+
Add Coroutine Sleep 5s alias=alias1
57+
${values} Run Coroutines alias=alias1
58+
Log Many @{values}
59+
60+
Test5
61+
[Documentation] Testing a concurrent keyword with gevent
62+
Create Gevent Bundle alias=alias1
63+
Add Coroutine Sleep Gevent Coros 3 7 alias=alias1
64+
Add Coroutine Sleep 5s alias=alias1
65+
${values} Run Coroutines alias=alias1
66+
Log Many @{values}
67+
Test6
68+
[Documentation] Testing a concurrent keyword with asyncio
69+
Create Gevent Bundle alias=alias1
70+
Add Coroutine Sleep Asyncio 3 7 alias=alias1
71+
Add Coroutine Sleep 5s alias=alias1
72+
${values} Run Coroutines alias=alias1
73+
Log Many @{values}
74+
4275

4376
*** Keywords ***
4477
Wrapper1

docs/GeventLibrary.html

Lines changed: 31 additions & 18 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "robotframework-gevent"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
description = "Run keywords asynchronously with the power of gevent"
55
authors = ["Eldad Uzman <[email protected]>"]
66
license = "MIT"

src/GeventLibrary/gevent_library.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ class GeventLibrary(DynamicCore):
5454
| ${values} Run Coroutines alias=alias1
5555
| Log Many @{values}
5656
57+
== Calling concurrent keywords ==
58+
=== Multiprocessing ===
59+
Multiprocessing containing code will not result in error, but waiting for process to end is blocking and the event loop will be hanging
60+
=== Multithreading ===
61+
Multithreading containing code will not result in error, but waiting for process to end is blocking and the event loop will be hanging
62+
=== gevent ===
63+
gevent containing code will work properly in a bundle and will be concurrent to the other coroutines.
64+
=== asyncio ===
65+
asyncio containing code will work properly in a bundle and will be concurrent to the other coroutines.
5766
"""
5867

5968
libraries: List[Any] = [GeventKeywords()]

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ commands =
1515
poetry install -v
1616
poetry run coverage run -m unittest discover
1717
coverage report
18-
robot atests
18+
robot -x TEST_GeventLibrary.xml atests

0 commit comments

Comments
 (0)