本文整理汇总了Python中txzmq.test._wait函数的典型用法代码示例。如果您正苦于以下问题:Python _wait函数的具体用法?Python _wait怎么用?Python _wait使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_wait函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_send_recv_multiple_endpoints
def test_send_recv_multiple_endpoints(self):
r = ZmqTestSubConnection(
self.factory,
ZmqEndpoint(ZmqEndpointType.bind, "tcp://127.0.0.1:5556"))
r.addEndpoints([ZmqEndpoint(ZmqEndpointType.bind,
"inproc://endpoint")])
s1 = ZmqPubConnection(
self.factory,
ZmqEndpoint(ZmqEndpointType.connect, "tcp://127.0.0.1:5556"))
s2 = ZmqPubConnection(
self.factory,
ZmqEndpoint(ZmqEndpointType.connect, "inproc://endpoint"))
r.subscribe('')
def publish(ignore):
s1.publish('111', 'tag1')
s2.publish('222', 'tag2')
def check(ignore):
result = getattr(r, 'messages', [])
expected = [['tag1', '111'], ['tag2', '222']]
self.failUnlessEqual(
sorted(result), expected, "Message should have been received")
return _wait(0.1).addCallback(publish) \
.addCallback(lambda _: _wait(0.1)).addCallback(check)
示例2: test_send_lot
def test_send_lot(self):
from txzmq.test import _wait
a_result = []
def a_msg_func(msg):
a_result.append(msg)
b_result = []
def b_msg_func(msg):
b_result.append(msg)
a = self.make_one(callback=a_msg_func)
a.bind("inproc://#1")
b = self.make_one(callback=b_msg_func)
b.connect("inproc://#1")
a2b_msgs = [['a2b %d' % i] for i in range(100)]
for m in a2b_msgs:
a.send(m)
b2a_msgs = [['b2a %d' % i] for i in range(100)]
for m in b2a_msgs:
b.send(m)
def check(ignore):
self.assertEqual(a_result, b2a_msgs)
self.assertEqual(b_result, a2b_msgs)
return _wait(0.1).addCallback(check)
示例3: test_send_recv
def test_send_recv(self):
from txzmq.test import _wait
a_result = []
def a_msg_func(msg):
a_result.append(msg)
b_result = []
def b_msg_func(msg):
b_result.append(msg)
a = self.make_one(callback=a_msg_func)
a.bind("inproc://#1")
b = self.make_one(callback=b_msg_func)
b.connect("inproc://#1")
b.send(['b2a'])
def check(ignore):
expected = [['a2b']]
self.assertEqual(b_result, expected)
def check_and_send(ignore):
expected = [['b2a']]
self.assertEqual(a_result, expected)
a.send(['a2b'])
return _wait(0.1).addCallback(check)
return _wait(0.1).addCallback(check_and_send)
示例4: test_pub_sub_with_filter
def test_pub_sub_with_filter(self):
import zmq
from txzmq.test import _wait
result = []
def msg_func(msg):
result.append(msg)
sub = self.make_sub(callback=msg_func)
sub.bind('inproc://#1')
sub.setsockopt(zmq.SUBSCRIBE, 'a')
pub = self.make_pub()
pub.connect('inproc://#1')
pub.send(['a', 'data1'])
pub.send(['b', 'data2'])
pub.send(['a', 'data3'])
pub.send(['a', 'data4'])
def check(ignore):
expected = [['a', 'data1'], ['a', 'data3'], ['a', 'data4']]
self.assertEqual(result, expected)
return _wait(0.1).addCallback(check)
示例5: test_send_to_multiple_nodes
def test_send_to_multiple_nodes(self):
from txzmq.test import _wait
result = []
def msg_func(msg):
result.append(msg)
pull1 = self.make_pull(callback=msg_func)
pull1.bind("inproc://#1")
pull2 = self.make_pull(callback=msg_func)
pull2.bind("inproc://#2")
pull3 = self.make_pull(callback=msg_func)
pull3.bind("inproc://#3")
push = self.make_push()
push.connect("inproc://#1")
push.connect("inproc://#2")
push.connect("inproc://#3")
for i in range(1, 6+1):
push.send(['msg%d' % i])
def check(ignore):
for i in range(1, 6+1):
self.assertIn(['msg1'], result)
return _wait(0.1).addCallback(check)
示例6: test_send_recv
def test_send_recv(self):
self.s.sendMsg("aaa", "aab")
self.s.sendMsg("bbb")
def check(ignore):
result = getattr(self.r, "messages", [])
expected = [["msg_id_1", ("aaa", "aab")], ["msg_id_2", ("bbb",)]]
self.failUnlessEqual(result, expected, "Message should have been received")
return _wait(0.01).addCallback(check)
示例7: test_send_timeout_fail
def test_send_timeout_fail(self):
b = ZmqEndpoint(ZmqEndpointType.bind, "ipc://#4")
ZmqSlowREPConnection(self.factory, b)
c = ZmqEndpoint(ZmqEndpointType.connect, "ipc://#4")
s = ZmqREQConnection(self.factory, c, identity=b'client2')
return s.sendMsg(b'aaa', timeout=0.05) \
.addCallbacks(lambda _: self.fail("Should timeout"),
lambda fail: fail.trap(ZmqRequestTimeoutError)) \
.addCallback(lambda _: _wait(0.1))
示例8: test_send_recv_pgm
def test_send_recv_pgm(self):
r = ZmqTestSubConnection(self.factory, ZmqEndpoint(
ZmqEndpointType.bind, "epgm://127.0.0.1;239.192.1.1:5556"))
s = ZmqPubConnection(self.factory, ZmqEndpoint(
ZmqEndpointType.connect, "epgm://127.0.0.1;239.192.1.1:5556"))
r.subscribe('tag')
def publish(ignore):
s.publish('xyz', 'different-tag')
s.publish('abcd', 'tag1')
def check(ignore):
result = getattr(r, 'messages', [])
expected = [['tag1', 'abcd']]
self.failUnlessEqual(
result, expected, "Message should have been received")
return _wait(0.2).addCallback(publish) \
.addCallback(lambda _: _wait(0.2)).addCallback(check)
示例9: test_curve_auth
def test_curve_auth(self):
self.auth_req.start()
self.auth_req.allow('127.0.0.1')
public_keys_dir = os.path.join(self._config_prefix, PUBLIC_KEYS_PREFIX)
self.auth_req.configure_curve(domain="*", location=public_keys_dir)
def check(ignored):
authenticator = self.authenticator.authenticator
certs = authenticator.certs['*']
self.failUnlessEqual(authenticator.whitelist, set([u'127.0.0.1']))
self.failUnlessEqual(certs[certs.keys()[0]], True)
return _wait(0.1).addCallback(check)
示例10: test_send_recv
def test_send_recv(self):
r = ZmqTestSubConnection(
self.factory, ZmqEndpoint(ZmqEndpointType.bind, "inproc://test-sock"))
s = ZmqPubConnection(
self.factory, ZmqEndpoint(ZmqEndpointType.connect,
"inproc://test-sock"))
r.subscribe('tag')
def publish(ignore):
s.publish('xyz', 'different-tag')
s.publish('abcd', 'tag1')
s.publish('efgh', 'tag2')
def check(ignore):
result = getattr(r, 'messages', [])
expected = [['tag1', 'abcd'], ['tag2', 'efgh']]
self.failUnlessEqual(
result, expected, "Message should have been received")
return _wait(0.01).addCallback(publish) \
.addCallback(lambda _: _wait(0.01)).addCallback(check)
示例11: test_cancel
def test_cancel(self):
d = self.s.sendMsg(b'aaa')
d.cancel()
def check_requests(_):
self.assertEqual(self.s._requests, {})
self.failUnlessEqual(self.s.UUID_POOL_GEN_SIZE,
len(self.s._uuids) + 1)
return d.addCallbacks(lambda _: self.fail("Should have errored"),
lambda fail: fail.trap(
"twisted.internet.defer.CancelledError")) \
.addCallback(check_requests) \
.addCallback(lambda _: _wait(0.01))
示例12: test_send_recv
def test_send_recv(self):
r = ZmqTestReceiver(
self.factory, ZmqEndpoint(ZmqEndpointType.bind, "inproc://#1"))
s = ZmqTestSender(
self.factory, ZmqEndpoint(ZmqEndpointType.connect, "inproc://#1"))
s.send('abcd')
def check(ignore):
result = getattr(r, 'messages', [])
expected = [['abcd']]
self.failUnlessEqual(
result, expected, "Message should have been received")
return _wait(0.01).addCallback(check)
示例13: test_send_recv_tcp_large
def test_send_recv_tcp_large(self):
r = ZmqTestReceiver(
ZmqEndpoint(ZmqEndpointType.bind, "tcp://127.0.0.1:5555"))
r.listen(self.factory)
s = ZmqTestSender(
ZmqEndpoint(ZmqEndpointType.connect, "tcp://127.0.0.1:5555"))
s.connect(self.factory)
s.send(["0" * 10000, "1" * 10000])
def check(ignore):
result = getattr(r, 'messages', [])
expected = [["0" * 10000, "1" * 10000]]
self.failUnlessEqual(
result, expected, "Messages should have been received")
return _wait(0.01).addCallback(check)
示例14: test_send_recv_tcp
def test_send_recv_tcp(self):
r = ZmqTestReceiver(
self.factory, ZmqEndpoint(ZmqEndpointType.bind,
"tcp://127.0.0.1:5555"))
s = ZmqTestSender(
self.factory, ZmqEndpoint(ZmqEndpointType.connect,
"tcp://127.0.0.1:5555"))
for i in xrange(100):
s.send(str(i))
def check(ignore):
result = getattr(r, 'messages', [])
expected = map(lambda i: [str(i)], xrange(100))
self.failUnlessEqual(
result, expected, "Messages should have been received")
return _wait(0.01).addCallback(check)
示例15: test_send_recv
def test_send_recv(self):
self.count = 0
def get_next_id():
self.count += 1
return 'msg_id_%d' % (self.count,)
self.s._getNextId = get_next_id
self.s.sendMsg('aaa', 'aab')
self.s.sendMsg('bbb')
def check(ignore):
result = getattr(self.r, 'messages', [])
expected = [['msg_id_1', ('aaa', 'aab')], ['msg_id_2', ('bbb',)]]
self.failUnlessEqual(
result, expected, "Message should have been received")
return _wait(0.01).addCallback(check)