|
| 1 | +""" |
| 2 | +Original Tarantool's test box-py/iproto.test.py had a problem when output with |
| 3 | +running under Python 2 was not the same as with running under Python 3. |
| 4 | +
|
| 5 | +Fixed in commit 697b79781cc63e2d87d86d43713998261d602334 |
| 6 | +"test: make output of box-py/iproto.test.py deterministic". |
| 7 | +""" |
| 8 | + |
| 9 | +from __future__ import print_function |
| 10 | + |
| 11 | +import msgpack |
| 12 | +from tarantool.const import * |
| 13 | +from tarantool import Connection |
| 14 | +from tarantool.response import Response |
| 15 | +from lib.tarantool_connection import TarantoolConnection |
| 16 | + |
| 17 | +# Note re IPROTO_SQL_INFO_* keys: they cannot appear in the |
| 18 | +# response map at the top level, but have the same codes as other |
| 19 | +# IPROTO_* constants. Exclude those names so. |
| 20 | +key_names = {} |
| 21 | +for (k,v) in list(globals().items()): |
| 22 | + if type(k) == str and k.startswith("IPROTO_") and \ |
| 23 | + not k.startswith("IPROTO_SQL_INFO_") and type(v) == int: |
| 24 | + key_names[v] = k |
| 25 | + |
| 26 | +def repr_dict(todump): |
| 27 | + d = {} |
| 28 | + for (k, v) in todump.items(): |
| 29 | + k_name = key_names.get(k, k) |
| 30 | + d[k_name] = v |
| 31 | + return repr(sorted(d.items())) |
| 32 | + |
| 33 | + |
| 34 | +def test(header, body): |
| 35 | + # Connect and authenticate |
| 36 | + c = Connection("localhost", server.iproto.port) |
| 37 | + c.connect() |
| 38 | + print("query", repr_dict(header), repr_dict(body)) |
| 39 | + header = msgpack.dumps(header) |
| 40 | + body = msgpack.dumps(body) |
| 41 | + query = msgpack.dumps(len(header) + len(body)) + header + body |
| 42 | + # Send raw request using connected socket |
| 43 | + s = c._socket |
| 44 | + try: |
| 45 | + s.send(query) |
| 46 | + except OSError as e: |
| 47 | + print(" => ", "Failed to send request") |
| 48 | + c.close() |
| 49 | + print(iproto.py_con.ping() > 0) |
| 50 | + |
| 51 | +print("IPROTO_UPDATE") |
| 52 | +test({ IPROTO_CODE : REQUEST_TYPE_UPDATE }, { IPROTO_SPACE_ID: 280 }) |
| 53 | +test({ IPROTO_CODE : REQUEST_TYPE_UPDATE }, |
| 54 | + { IPROTO_SPACE_ID: 280, IPROTO_KEY: (1, )}) |
| 55 | +print("\n") |
0 commit comments