Skip to content

Commit

Permalink
Move eventlet tests to main folder and to child process
Browse files Browse the repository at this point in the history
  • Loading branch information
psarka committed Sep 16, 2022
1 parent a873ab7 commit 80a3eae
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
1 change: 0 additions & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ jobs:
- name: Test with pytest
run: |
pytest tests/
pytest tests_eventlet/
35 changes: 28 additions & 7 deletions tests_eventlet/test_eventlet.py → tests/test_eventlet.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import eventlet
"""
These tests need to run in child processes, otherwise eventlet monkey_patch
conflicts with multiprocessing and other tests fail.
"""
import concurrent.futures
from multiprocessing import get_context

eventlet.monkey_patch(thread=True)

from fasteners import ReaderWriterLock


def test_eventlet_spawn_n_bug():
def _test_eventlet_spawn_n_bug():
"""Both threads run at the same time thru the lock"""
import eventlet
eventlet.monkey_patch()
from fasteners import ReaderWriterLock

STARTED = eventlet.event.Event()
FINISHED = eventlet.event.Event()
lock = ReaderWriterLock()
Expand All @@ -22,8 +27,12 @@ def other():
assert FINISHED.wait(1) == 'finished'


def test_eventlet_spawn_n_bugfix():
def _test_eventlet_spawn_n_bugfix():
"""Threads wait for each other as they should"""
import eventlet
eventlet.monkey_patch()
from fasteners import ReaderWriterLock

STARTED = eventlet.event.Event()
FINISHED = eventlet.event.Event()
lock = ReaderWriterLock(current_thread_functor=eventlet.getcurrent)
Expand All @@ -39,3 +48,15 @@ def other():
assert FINISHED.wait(1) is None

assert FINISHED.wait(1) == 'finished'


def test_eventlet_spawn_n_bug():
with concurrent.futures.ProcessPoolExecutor(mp_context=get_context('spawn')) as executor:
f = executor.submit(_test_eventlet_spawn_n_bug)
f.result()


def test_eventlet_spawn_n_bugfix():
with concurrent.futures.ProcessPoolExecutor(mp_context=get_context('spawn')) as executor:
f = executor.submit(_test_eventlet_spawn_n_bugfix)
f.result()
Empty file removed tests_eventlet/__init__.py
Empty file.

0 comments on commit 80a3eae

Please sign in to comment.