Commit 5beab048 authored by Kirill Smelkov's avatar Kirill Smelkov

go/neo/proto: Test that message codes are the same in between Go and Python NEO versions

This brings some go/py compatibility checks that verify go and python
treat a message code equally. Although messages encoding are tested in
the previous patch there is no explicit tests for go/py compatibility on
messages encoding.
parent ea5f7d61
// Copyright (C) 2016-2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
package proto
// NEO. test wire protocol compatibility with python
//go:generate ./py/pyneo-gen-testdata
import (
"reflect"
"testing"
"github.com/kylelemons/godebug/pretty"
)
// verify that message codes are the same in between py and go.
func TestMsgCodeVsPy(t *testing.T) {
goMsgRegistry := map[uint16]string{} // code -> packet name
for code, pktType := range msgTypeRegistry {
goMsgRegistry[code] = pktType.Name()
}
if !reflect.DeepEqual(goMsgRegistry, pyMsgRegistry) {
t.Fatalf("message registry: py vs go mismatch:\n%s\n",
pretty.Compare(pyMsgRegistry, goMsgRegistry))
}
}
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# Copyright (C) 2017 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
"""generate registry of neo/py packet codes for tests"""
# things that are renamed a bit
# pyname -> goname
renames = {}
def noask(name): renames['Ask'+name] = name
def nonotify(name): renames['Notify'+name] = name
noask('Recovery')
noask('LastIDs')
noask('UnfinishedTransactions')
noask('LockedTransactions')
noask('FinalTID')
noask('BeginTransaction')
noask('FinishTransaction')
noask('LockInformation')
#nonotify('UnlockInformation') # XXX ok?
noask('RebaseTransaction')
noask('RebaseObject')
noask('StoreObject')
noask('StoreTransaction')
noask('VoteTransaction')
noask('TransactionInformation')
noask('ObjectHistory')
noask('PartitionList')
noask('NodeList')
noask('ObjectUndoSerial')
noask('Pack')
noask('CheckTIDRange')
noask('CheckSerialRange')
nonotify('PartitionCorrupted')
noask('LastTransaction')
noask('CheckCurrentSerial')
nonotify('ReplicationDone')
noask('FetchTransactions')
noask('FetchObjects')
_ = renames
_['AskPrimary'] = 'PrimaryMaster'
_['AskObject'] = 'GetObject'
_['NotifyRepair'] = 'RepairOne' # XXX ok?
_['NotifyClusterInformation'] = 'NotifyClusterState'
def main():
pyprotog = {}
execfile('../../../neo/lib/protocol.py', pyprotog)
pypacket = pyprotog['Packet']
pypackets = pyprotog['Packets']
# dump to go what to expect
with open("ztestdata_proto_py_test.go", "w") as f:
def emit(v):
print >>f, v
emit("// Code generated by %s; DO NOT EDIT." % __file__)
emit("package proto")
emit("\nvar pyMsgRegistry = map[uint16]string{")
# access packet structures by names they are defined under Packets
# class and thus in neo/py code which uses them.
#
# ( this is not the same as packet class name as e.g. currently
# AcceptIdentification has class name AnswerRequestIdentification )
pypktv = []
for k in dir(pypackets):
v = getattr(pypackets, k)
if isinstance(v, type) and issubclass(v, pypacket):
v._x_use_name = k
pypktv.append(v)
# order by message code
pypktv.sort(key=lambda pkt: pkt._code)
for pypkt in pypktv:
name = pypkt._x_use_name
name = renames.get(name, name)
emit('\t%d:\t"%s",' % (pypkt._code, name))
#pycodev = pypackets.keys()
#pycodev.sort()
#for pycode in pycodev:
# pymsg = pypackets[pycode]
# emit('\t%d:\t"%s",' % (pycode, pymsg.__name__))
emit("}")
if __name__ == '__main__':
main()
// Code generated by ./py/pyneo-gen-testdata; DO NOT EDIT.
package proto
var pyMsgRegistry = map[uint16]string{
1: "RequestIdentification",
3: "Ping",
5: "CloseClient",
6: "PrimaryMaster",
8: "NotPrimaryMaster",
9: "NotifyNodeInformation",
10: "Recovery",
12: "LastIDs",
14: "AskPartitionTable",
16: "SendPartitionTable",
17: "NotifyPartitionChanges",
18: "StartOperation",
19: "StopOperation",
20: "UnfinishedTransactions",
22: "LockedTransactions",
24: "FinalTID",
26: "ValidateTransaction",
27: "BeginTransaction",
29: "FailedVote",
30: "FinishTransaction",
32: "LockInformation",
34: "InvalidateObjects",
35: "NotifyUnlockInformation",
36: "AskNewOIDs",
38: "NotifyDeadlock",
39: "RebaseTransaction",
41: "RebaseObject",
43: "StoreObject",
45: "AbortTransaction",
46: "StoreTransaction",
48: "VoteTransaction",
50: "GetObject",
52: "AskTIDs",
54: "TransactionInformation",
56: "ObjectHistory",
58: "PartitionList",
60: "NodeList",
62: "SetNodeState",
63: "AddPendingNodes",
64: "TweakPartitionTable",
65: "SetClusterState",
66: "Repair",
67: "RepairOne",
68: "NotifyClusterState",
69: "AskClusterState",
71: "ObjectUndoSerial",
73: "AskTIDsFrom",
75: "Pack",
77: "CheckReplicas",
78: "CheckPartition",
79: "CheckTIDRange",
81: "CheckSerialRange",
83: "PartitionCorrupted",
84: "NotifyReady",
85: "LastTransaction",
87: "CheckCurrentSerial",
89: "NotifyTransactionFinished",
90: "Replicate",
91: "ReplicationDone",
92: "FetchTransactions",
94: "FetchObjects",
96: "AddTransaction",
97: "AddObject",
98: "Truncate",
32768: "Error",
32769: "AcceptIdentification",
32771: "Pong",
32774: "AnswerPrimary",
32778: "AnswerRecovery",
32780: "AnswerLastIDs",
32782: "AnswerPartitionTable",
32788: "AnswerUnfinishedTransactions",
32790: "AnswerLockedTransactions",
32792: "AnswerFinalTID",
32795: "AnswerBeginTransaction",
32798: "AnswerTransactionFinished",
32800: "AnswerInformationLocked",
32804: "AnswerNewOIDs",
32807: "AnswerRebaseTransaction",
32809: "AnswerRebaseObject",
32811: "AnswerStoreObject",
32814: "AnswerStoreTransaction",
32816: "AnswerVoteTransaction",
32818: "AnswerObject",
32820: "AnswerTIDs",
32822: "AnswerTransactionInformation",
32824: "AnswerObjectHistory",
32826: "AnswerPartitionList",
32828: "AnswerNodeList",
32837: "AnswerClusterState",
32839: "AnswerObjectUndoSerial",
32841: "AnswerTIDsFrom",
32843: "AnswerPack",
32847: "AnswerCheckTIDRange",
32849: "AnswerCheckSerialRange",
32853: "AnswerLastTransaction",
32855: "AnswerCheckCurrentSerial",
32860: "AnswerFetchTransactions",
32862: "AnswerFetchObjects",
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment