Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add the methods argument in the Subscriber and Puller constructors #17

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

Merged
merged 3 commits into from
Apr 3, 2012
Merged
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
62 changes: 55 additions & 7 deletions tests/test_pubpush.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import zerorpc


def test_pushpull():
endpoint = 'ipc://test_pushpull'
def test_pushpull_inheritance():
endpoint = 'ipc://test_pushpull_inheritance'

pusher = zerorpc.Pusher()
pusher.bind(endpoint)
Expand All @@ -52,11 +52,11 @@ def lolita(self, a, b):
print 'done'


def test_pubsub():
endpoint = 'ipc://test_pubsub'
def test_pubsub_inheritance():
endpoint = 'ipc://test_pubsub_inheritance'

pusher = zerorpc.Publisher()
pusher.bind(endpoint)
publisher = zerorpc.Publisher()
publisher.bind(endpoint)
trigger = gevent.event.Event()

class Subscriber(zerorpc.Subscriber):
Expand All @@ -65,11 +65,59 @@ def lolita(self, a, b):
assert a + b == 3
trigger.set()

puller = Subscriber()
subscriber = Subscriber()
subscriber.connect(endpoint)
gevent.spawn(subscriber.run)

trigger.clear()
publisher.lolita(1, 2)
trigger.wait()
print 'done'


def test_pushpull_composite():
endpoint = 'ipc://test_pushpull_composite'
trigger = gevent.event.Event()

class Puller(object):
def lolita(self, a, b):
print 'lolita', a, b
assert a + b == 3
trigger.set()

pusher = zerorpc.Pusher()
pusher.bind(endpoint)

service = Puller()
puller = zerorpc.Puller(service)
puller.connect(endpoint)
gevent.spawn(puller.run)

trigger.clear()
pusher.lolita(1, 2)
trigger.wait()
print 'done'


def test_pubsub_composite():
endpoint = 'ipc://test_pubsub_composite'
trigger = gevent.event.Event()

class Subscriber(object):
def lolita(self, a, b):
print 'lolita', a, b
assert a + b == 3
trigger.set()

publisher = zerorpc.Publisher()
publisher.bind(endpoint)

service = Subscriber()
subscriber = zerorpc.Subscriber(service)
subscriber.connect(endpoint)
gevent.spawn(subscriber.run)

trigger.clear()
publisher.lolita(1, 2)
trigger.wait()
print 'done'
8 changes: 4 additions & 4 deletions zerorpc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,7 @@ def __getattr__(self, method):

class Puller(SocketBase):

def __init__(self, methods=None, name=None, context=None,
zmq_socket=zmq.PULL):
def __init__(self, methods=None, context=None, zmq_socket=zmq.PULL):
super(Puller, self).__init__(zmq_socket, context=context)

if methods is None:
Expand Down Expand Up @@ -398,6 +397,7 @@ def __init__(self, context=None):

class Subscriber(Puller):

def __init__(self, context=None):
super(Subscriber, self).__init__(context=context, zmq_socket=zmq.SUB)
def __init__(self, methods=None, context=None):
super(Subscriber, self).__init__(methods=methods, context=context,
zmq_socket=zmq.SUB)
self._events.setsockopt(zmq.SUBSCRIBE, '')