|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# Open Source Initiative OSI - The MIT License (MIT):Licensing |
| 3 | +# |
| 4 | +# The MIT License (MIT) |
| 5 | +# Copyright (c) 2012 DotCloud Inc ([email protected]) |
| 6 | +# |
| 7 | +# Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 8 | +# this software and associated documentation files (the "Software"), to deal in |
| 9 | +# the Software without restriction, including without limitation the rights to |
| 10 | +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 11 | +# of the Software, and to permit persons to whom the Software is furnished to do |
| 12 | +# so, subject to the following conditions: |
| 13 | +# |
| 14 | +# The above copyright notice and this permission notice shall be included in all |
| 15 | +# copies or substantial portions of the Software. |
| 16 | +# |
| 17 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | +# SOFTWARE. |
| 24 | + |
| 25 | + |
| 26 | +import gevent |
| 27 | + |
| 28 | +import zerorpc |
| 29 | +from testutils import teardown, random_ipc_endpoint |
| 30 | + |
| 31 | +def test_client_connect(): |
| 32 | + endpoint = random_ipc_endpoint() |
| 33 | + |
| 34 | + class MySrv(zerorpc.Server): |
| 35 | + |
| 36 | + def lolita(self): |
| 37 | + return 42 |
| 38 | + |
| 39 | + srv = MySrv() |
| 40 | + srv.bind(endpoint) |
| 41 | + gevent.spawn(srv.run) |
| 42 | + |
| 43 | + client = zerorpc.Client() |
| 44 | + client.connect(endpoint) |
| 45 | + |
| 46 | + assert client.lolita() == 42 |
| 47 | + |
| 48 | +def test_client_quick_connect(): |
| 49 | + endpoint = random_ipc_endpoint() |
| 50 | + |
| 51 | + class MySrv(zerorpc.Server): |
| 52 | + |
| 53 | + def lolita(self): |
| 54 | + return 42 |
| 55 | + |
| 56 | + srv = MySrv() |
| 57 | + srv.bind(endpoint) |
| 58 | + gevent.spawn(srv.run) |
| 59 | + |
| 60 | + client = zerorpc.Client(endpoint) |
| 61 | + |
| 62 | + assert client.lolita() == 42 |
0 commit comments