Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix(proto): fix merge route logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhxiao committed Sep 12, 2019
1 parent ce43be8 commit e9f065c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 10 additions & 10 deletions gnes/proto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@ def add_route(evlp: 'gnes_pb2.Envelope', name: str):


def merge_routes(msg: 'gnes_pb2.Message', prev_msgs: List['gnes_pb2.Message'], idx: int = -1):
r = msg.envelope.routes[idx]
if len(msg.envelope.routes) > 1:
msg.envelope.routes[idx - 1].service = colored('[%s]' % ', '.join(
[m.envelope.routes[idx - 1].service for m in prev_msgs]), 'yellow')
r.first_start_time.CopyFrom(
sorted((m.envelope.routes[idx].start_time for m in prev_msgs),
key=lambda x: (x.seconds, x.nanos))[0])
r.last_end_time.CopyFrom(
sorted((m.envelope.routes[idx].end_time for m in prev_msgs),
key=lambda x: (x.seconds, x.nanos), reverse=True)[0])
r = msg.envelope.routes.pop(idx)
msg.envelope.routes.extend([m.envelope.routes[idx - 1] for m in prev_msgs[:-1] if len(m.envelope.routes) > 1])
msg.envelope.routes.extend([r])

# r.first_start_time.CopyFrom(
# sorted((m.envelope.routes[idx].start_time for m in prev_msgs),
# key=lambda x: (x.seconds, x.nanos))[0])
# r.last_end_time.CopyFrom(
# sorted((m.envelope.routes[idx].end_time for m in prev_msgs),
# key=lambda x: (x.seconds, x.nanos), reverse=True)[0])


def send_message(sock: 'zmq.Socket', msg: 'gnes_pb2.Message', timeout: int = -1) -> None:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_stream_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def setUp(self):
def test_bm_frontend(self):
args = set_frontend_parser().parse_args([
'--grpc_host', '127.0.0.1',
'--show_route_table'
])

p_args = set_router_parser().parse_args([
Expand All @@ -64,6 +65,7 @@ def test_bm_frontend(self):
def test_grpc_frontend(self):
args = set_frontend_parser().parse_args([
'--grpc_host', '127.0.0.1',
'--show_route_table'
])

p_args = set_router_parser().parse_args([
Expand Down

0 comments on commit e9f065c

Please sign in to comment.