Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
83815eab
Commit
83815eab
authored
9 years ago
by
murgatroid99
Browse files
Options
Downloads
Patches
Plain Diff
Added interval_us delay in Node interop server
parent
a6a9a6df
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/node/interop/interop_server.js
+41
-6
41 additions, 6 deletions
src/node/interop/interop_server.js
with
41 additions
and
6 deletions
src/node/interop/interop_server.js
+
41
−
6
View file @
83815eab
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
var
fs
=
require
(
'
fs
'
);
var
fs
=
require
(
'
fs
'
);
var
path
=
require
(
'
path
'
);
var
path
=
require
(
'
path
'
);
var
async
=
require
(
'
async
'
);
var
_
=
require
(
'
lodash
'
);
var
_
=
require
(
'
lodash
'
);
var
grpc
=
require
(
'
..
'
);
var
grpc
=
require
(
'
..
'
);
var
testProto
=
grpc
.
load
({
var
testProto
=
grpc
.
load
({
...
@@ -86,6 +87,22 @@ function getEchoTrailer(call) {
...
@@ -86,6 +87,22 @@ function getEchoTrailer(call) {
return
response_trailer
;
return
response_trailer
;
}
}
/**
* @typedef Payload
* @type {object}
* @property {string} payload_type The payload type
* @property {Buffer} body The payload body
*/
/**
* Get a payload of the specified type and size. If the requested payload is
* COMPRESSABLE, it returns a zero buffer. If the type is UNCOMRESSABLE, it
* returns a slice of pre-loaded uncompressable data. If the type is RANDOM,
* it returns one of the other choices, chosen at random.
* @param {string} payload_type The type of payload to return
* @param {Number} size The size of the payload body
* @return {Payload} The requested payload
*/
function
getPayload
(
payload_type
,
size
)
{
function
getPayload
(
payload_type
,
size
)
{
if
(
payload_type
===
'
RANDOM
'
)
{
if
(
payload_type
===
'
RANDOM
'
)
{
payload_type
=
[
'
COMPRESSABLE
'
,
payload_type
=
[
'
COMPRESSABLE
'
,
...
@@ -99,6 +116,15 @@ function getPayload(payload_type, size) {
...
@@ -99,6 +116,15 @@ function getPayload(payload_type, size) {
return
{
type
:
payload_type
,
body
:
body
};
return
{
type
:
payload_type
,
body
:
body
};
}
}
function
respondWithStream
(
call
,
request
,
callback
)
{
async
.
eachSeries
(
request
.
response_parameters
,
function
(
resp_param
,
callback
)
{
setTimeout
(
function
()
{
call
.
write
({
payload
:
getPayload
(
request
.
response_type
,
resp_param
.
size
)});
callback
();
},
resp_param
.
interval_us
/
1000
);
},
callback
);
}
/**
/**
* Respond to an empty parameter with an empty response.
* Respond to an empty parameter with an empty response.
* NOTE: this currently does not work due to issue #137
* NOTE: this currently does not work due to issue #137
...
@@ -162,10 +188,13 @@ function handleStreamingOutput(call) {
...
@@ -162,10 +188,13 @@ function handleStreamingOutput(call) {
call
.
emit
(
'
error
'
,
status
);
call
.
emit
(
'
error
'
,
status
);
return
;
return
;
}
}
_
.
each
(
req
.
response_parameters
,
function
(
resp_param
)
{
respondWithStream
(
call
,
req
,
function
(
err
)
{
call
.
write
({
payload
:
getPayload
(
req
.
response_type
,
resp_param
.
size
)});
if
(
err
)
{
call
.
emit
(
err
);
}
else
{
call
.
end
(
getEchoTrailer
(
call
));
}
});
});
call
.
end
(
getEchoTrailer
(
call
));
}
}
/**
/**
...
@@ -175,6 +204,7 @@ function handleStreamingOutput(call) {
...
@@ -175,6 +204,7 @@ function handleStreamingOutput(call) {
*/
*/
function
handleFullDuplex
(
call
)
{
function
handleFullDuplex
(
call
)
{
echoHeader
(
call
);
echoHeader
(
call
);
var
call_ended
;
call
.
on
(
'
data
'
,
function
(
value
)
{
call
.
on
(
'
data
'
,
function
(
value
)
{
if
(
value
.
response_status
)
{
if
(
value
.
response_status
)
{
var
status
=
value
.
response_status
;
var
status
=
value
.
response_status
;
...
@@ -182,12 +212,17 @@ function handleFullDuplex(call) {
...
@@ -182,12 +212,17 @@ function handleFullDuplex(call) {
call
.
emit
(
'
error
'
,
status
);
call
.
emit
(
'
error
'
,
status
);
return
;
return
;
}
}
_
.
each
(
value
.
response_parameters
,
function
(
resp_param
)
{
call
.
pause
();
call
.
write
({
payload
:
getPayload
(
value
.
response_type
,
resp_param
.
size
)});
respondWithStream
(
call
,
value
,
function
(
err
)
{
call
.
resume
();
if
(
call_ended
)
{
call
.
end
(
getEchoTrailer
(
call
));
}
});
});
});
});
call
.
on
(
'
end
'
,
function
()
{
call
.
on
(
'
end
'
,
function
()
{
call
.
end
(
getEchoTrailer
(
call
));
call_ended
=
true
;
});
});
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment