Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support use mp spawn mode for tests #263

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dev = [
"pytest>=6.1.1,<8.2.0",
"tornado>=4.0,<7.0; python_version>='3.12'",
"tornado>=4.0,<6.0; python_version<'3.12'",
"multiprocess>=0.70.12.2",
]

tornado = [
Expand Down
24 changes: 17 additions & 7 deletions tests/test_all_protocols_binary_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
import time
import traceback
from multiprocessing import Process
from multiprocess import Process

import pytest
import six
Expand All @@ -26,8 +26,6 @@
from thriftpy2.transport import TBufferedTransportFactory, TCyMemoryBuffer


if sys.platform == "win32":
pytest.skip("requires fork", allow_module_level=True)


protocols = [TApacheJSONProtocolFactory,
Expand Down Expand Up @@ -72,6 +70,11 @@ def test(t):
trans_factory = TBufferedTransportFactory

def run_server():
import thriftpy2
test_thrift = thriftpy2.load(
"apache_json_test.thrift",
module_name="test_thrift"
)
server = server_func[0](
test_thrift.TestService,
handler=Handler(),
Expand Down Expand Up @@ -161,11 +164,16 @@ def test_exceptions(server_func, proto_factory):
)
TestException = test_thrift.TestException

class Handler(object):
def do_error(self, arg):
raise TestException(message=arg)

def do_server():
import thriftpy2
test_thrift = thriftpy2.load(
"apache_json_test.thrift",
module_name="test_thrift"
)
TestException = test_thrift.TestException
class Handler(object):
def do_error(self, arg):
raise TestException(message=arg)
server = server_func[0](
service=test_thrift.TestService,
handler=Handler(),
Expand Down Expand Up @@ -237,6 +245,8 @@ def test(t):
trans_factory = TBufferedTransportFactory

def run_server():
import thriftpy2
spec = thriftpy2.load("bin_test.thrift", module_name="bin_thrift")
server = make_rpc_server(
spec.BinService,
handler=Handler(),
Expand Down
12 changes: 5 additions & 7 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from __future__ import absolute_import

import os
import multiprocessing
import multiprocess
import socket
import sys
import time
import uuid

Expand All @@ -22,10 +21,6 @@
"addressbook.thrift"))


if sys.platform == "win32":
pytest.skip("requires fork", allow_module_level=True)


class Dispatcher():
def __init__(self):
self.ab = addressbook.AddressBook()
Expand Down Expand Up @@ -79,9 +74,12 @@ def get_headers(self):

@pytest.fixture(scope="module")
def server(request):
import thriftpy2
addressbook = thriftpy2.load(os.path.join(os.path.dirname(__file__),
"addressbook.thrift"))
server = make_server(addressbook.AddressBookService, Dispatcher(),
host="127.0.0.1", port=6080)
ps = multiprocessing.Process(target=server.serve)
ps = multiprocess.Process(target=server.serve)
ps.start()

time.sleep(0.1)
Expand Down
12 changes: 4 additions & 8 deletions tests/test_multiplexed.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import
import sys

import multiprocessing
import multiprocess
import os
import sys
import time

import pytest
Expand All @@ -20,10 +20,6 @@
from thriftpy2.transport import TBufferedTransportFactory, TServerSocket


if sys.platform == "win32":
pytest.skip("requires fork", allow_module_level=True)


mux = thriftpy2.load(os.path.join(os.path.dirname(__file__),
"multiplexed.thrift"))
sock_path = "/tmp/thriftpy_test.sock"
Expand Down Expand Up @@ -51,7 +47,7 @@ def server(request):
_server = TThreadedServer(mux_proc, TServerSocket(unix_socket=sock_path),
iprot_factory=TBinaryProtocolFactory(),
itrans_factory=TBufferedTransportFactory())
ps = multiprocessing.Process(target=_server.serve)
ps = multiprocess.Process(target=_server.serve)
ps.start()
time.sleep(0.1)

Expand Down Expand Up @@ -82,7 +78,7 @@ def client_two(timeout=3000):
socket_timeout=timeout, connect_timeout=timeout,
proto_factory=multiplexing_factory)


@pytest.mark.skipif(sys.platform == "win32", reason="Unix domain socket required")
def test_multiplexed_server(server):
with client_one() as c:
assert c.doThingOne() is True
Expand Down
9 changes: 2 additions & 7 deletions tests/test_oneway.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@

import pytest

import multiprocessing
import multiprocess
import thriftpy2
from thriftpy2.rpc import make_client, make_server


if sys.platform == "win32":
pytest.skip("requires fork", allow_module_level=True)


class Dispatcher(object):
def Test(self, req):
print("Get req msg: %s" % req)
Expand All @@ -24,9 +20,8 @@ class TestOneway(object):
oneway_thrift = thriftpy2.load("oneway.thrift")

def setup_class(self):
ctx = multiprocessing.get_context("fork")
server = make_server(self.oneway_thrift.echo, Dispatcher(), '127.0.0.1', 6000)
self.p = ctx.Process(target=server.serve)
self.p = multiprocess.Process(target=server.serve)
self.p.start()
time.sleep(1) # Wait a second for server to start.

Expand Down
11 changes: 3 additions & 8 deletions tests/test_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
from __future__ import absolute_import

import contextlib
import multiprocessing
import multiprocess
import os
import pickle
import random
import socket
import sys
import tempfile
import time

Expand Down Expand Up @@ -56,11 +55,7 @@
except ImportError:
pass
else:
cleanup_on_sigterm()


if sys.platform == "win32":
pytest.skip("requires fork", allow_module_level=True)
cleanup_on_sigterm()


addressbook = thriftpy2.load(os.path.join(os.path.dirname(__file__),
Expand Down Expand Up @@ -191,7 +186,7 @@ def gen_server(port, tracker=tracker, processor=TTrackedProcessor):
server = TSampleServer(processor, server_socket,
prot_factory=TBinaryProtocolFactory(),
trans_factory=TBufferedTransportFactory())
ps = multiprocessing.Process(target=server.serve)
ps = multiprocess.Process(target=server.serve)
ps.start()
return ps, server

Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ deps =
tornado>=4.0,<6.0
cython
py35,py36,py37,py38,py39,pypy3,coverage: pytest_asyncio
multiprocess

[testenv:flake8]
deps =
Expand Down
Loading