Commit 533f4484 authored by Michael Gray's avatar Michael Gray
Browse files

Z:Protocol->send_command() now sends same timestamp in header and message.

parent 03e14ad7
......@@ -38,6 +38,7 @@ sub _init {
my ($self, $arg_hash) = @_;
$self->{'is_open'} = 1;
$self->request_id(1);
for (qw( app_id context server )) {
my $attribute = $arg_hash->{"-$_"};
......@@ -164,11 +165,22 @@ sub send_goodbye_exit {
sub send_command {
my ($self, $command, $view, $request, $callback) = @_;
$self->is_open or die "the connection is closed\n";
$self->callback($callback);
$self->zircon_trace('send %s #%d', $command, $self->serialiser->request_id);
my $serialised = $self->serialiser->serialise_request($command, $view, $request);
$self->connection->send($serialised);
my $request_id = $self->request_id;
my $headers = {
%{Zircon::Timestamp->timestamp()},
request_id => $request_id,
};
$self->zircon_trace('send %s #%d', $command, $request_id);
my $serialised = $self->serialiser->serialise_request($command, $view, $request, $headers);
$self->connection->send($serialised, $headers);
$self->request_id($request_id + 1);
return;
}
......@@ -362,6 +374,13 @@ sub serialiser {
return $serialiser;
}
sub request_id {
my ($self, @args) = @_;
($self->{'request_id'}) = @args if @args;
my $request_id = $self->{'request_id'};
return $request_id;
}
# tracing
......
......@@ -23,7 +23,6 @@ sub new {
sub _init {
my ($self, $arg_hash) = @_;
$self->request_id(1);
$self->_app_id( $arg_hash->{'-app_id'} ) or croak "missing -app_id parameter";
$self->_connection($arg_hash->{'-connection'}) or croak "missing -connection parameter";
$self->_app_tag( $arg_hash->{'-app_tag'} // $ZIRCON_DEFAULT_APP_TAG );
......@@ -32,13 +31,6 @@ sub _init {
# attributes
sub request_id {
my ($self, @args) = @_;
($self->{'request_id'}) = @args if @args;
my $request_id = $self->{'request_id'};
return $request_id;
}
sub _app_id {
my ($self, @args) = @_;
($self->{'_app_id'}) = @args if @args;
......@@ -66,7 +58,7 @@ sub _app_tag {
# creation
sub serialise_request {
my ($self, $command, $view_id, $request) = @_;
my ($self, $command, $view_id, $request, $headers) = @_;
my $request_body =
ref $request ? $self->serialise_element(@{$request}) : $request;
my $request_element = $self->serialise_element(
......@@ -76,16 +68,14 @@ sub serialise_request {
}, $request_body);
my $app_id = $self->_app_id;
my $socket_id = $self->_connection->remote_endpoint;
my $request_id = $self->request_id;
$self->request_id($request_id + 1);
my $protocol_element = $self->serialise_element(
$self->_app_tag, {
%{ $headers // {} },
'version' => $ZIRCON_PROTOCOL_VERSION,
'type' => 'request',
'app_id' => $app_id,
'socket_id' => $socket_id,
'request_id' => $request_id,
$self->_timestamp,
$self->_timestamp($headers),
}, $request_element);
return $self->finalise_element($protocol_element);
}
......@@ -131,11 +121,14 @@ sub finalise_element {
}
sub _timestamp {
my ($self) = @_;
my ($self, $headers) = @_;
return if $self->inhibit_timestamps;
my $timestamp = Zircon::Timestamp->timestamp;
my ($sec, $usec) = @$timestamp{qw( clock_sec clock_usec )};
unless (exists $headers->{clock_sec} and exists $headers->{clock_usec}) {
$headers = Zircon::Timestamp->timestamp;
}
my ($sec, $usec) = @$headers{qw( clock_sec clock_usec )};
return ('request_time' => "$sec,$usec");
}
......
......@@ -20,17 +20,17 @@ sub request_tt {
my $P = MockProtoJSON->new(-app_tag => 'zircon_test');
eq_or_diff
($P->serialise_request(vanish => 'view4'),
($P->serialise_request(vanish => 'view4' => undef, { request_id => 0 }),
_make_expected_request(0, 'vanish', 'view4', undef),
'request, empty');
eq_or_diff
($P->serialise_request(smudge => view5 => 'with finger'),
($P->serialise_request(smudge => view5 => 'with finger', { request_id => 1 }),
_make_expected_request(1, 'smudge', 'view5', '"with finger"'),
'request, flat');
eq_or_diff
($P->serialise_request(prod => view6 => [ finger => { side => 'left' } ]),
($P->serialise_request(prod => view6 => [ finger => { side => 'left' } ], { request_id => 2}),
_make_expected_request(2, 'prod', 'view6', <<'__EO_REQ__'),
{
"finger" : {
......@@ -42,7 +42,7 @@ __EO_REQ__
eq_or_diff
($P->serialise_request(prod => view7 => [ finger => { side => 'left' },
[ speed => {}, 'quick' ] ]),
[ speed => {}, 'quick' ] ], { request_id => 3}),
_make_expected_request(3, 'prod', 'view7', <<'__EO_REQ__'),
{
"finger" : {
......@@ -241,10 +241,10 @@ sub parse_tt {
my $req = [ finger => { side => 'left' },
undef # optional, but made explicit during parsing
];
my $json = $P->serialise_request(prod => view6 => $req);
my $json = $P->serialise_request(prod => view6 => $req, { request_id => 6 });
eq_or_diff($Q->parse_request($json),
[ 0, 'Bob', 'prod', 'view6', [ $req ] ],
[ 6, 'Bob', 'prod', 'view6', [ $req ] ],
'command: prod');
# Is it important that whitespace is stripped, when it was
......
......@@ -21,13 +21,13 @@ sub request_tt {
my $P = MockProtoXML->new;
eq_or_diff
($P->serialise_request(vanish => 'view4'),
($P->serialise_request(vanish => 'view4' => undef, { request_id => 0 }),
q{<zmap app_id="Bob" request_id="0" socket_id="endpoint_remote" type="request" version="3.0">
<request command="vanish" view_id="view4" />
</zmap>}, 'request, empty');
eq_or_diff
($P->serialise_request(smudge => view5 => 'with finger'),
($P->serialise_request(smudge => view5 => 'with finger', { request_id => 1 }),
q{<zmap app_id="Bob" request_id="1" socket_id="endpoint_remote" type="request" version="3.0">
<request command="smudge" view_id="view5">
with finger
......@@ -35,7 +35,7 @@ with finger
</zmap>}, 'request, flat');
eq_or_diff
($P->serialise_request(prod => view6 => [ finger => { side => 'left' } ]),
($P->serialise_request(prod => view6 => [ finger => { side => 'left' } ], { request_id => 2}),
q{<zmap app_id="Bob" request_id="2" socket_id="endpoint_remote" type="request" version="3.0">
<request command="prod" view_id="view6">
<finger side="left" />
......@@ -44,7 +44,7 @@ with finger
eq_or_diff
($P->serialise_request(prod => view7 => [ finger => { side => 'left' },
[ speed => {}, 'quick' ] ]),
[ speed => {}, 'quick' ] ], { request_id => 3}),
q{<zmap app_id="Bob" request_id="3" socket_id="endpoint_remote" type="request" version="3.0">
<request command="prod" view_id="view7">
<finger side="left">
......@@ -156,10 +156,10 @@ sub parse_tt {
my $req = [ finger => { side => 'left' },
undef # optional, but made explicit during parsing
];
my $xml = $P->serialise_request(prod => view6 => $req);
my $xml = $P->serialise_request(prod => view6 => $req, { request_id => 6 });
eq_or_diff($Q->parse_request($xml),
[ '0', 'Bob', 'prod', 'view6', [ $req ] ],
[ '6', 'Bob', 'prod', 'view6', [ $req ] ],
'command: prod');
......
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