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
b98e1dd7
Commit
b98e1dd7
authored
9 years ago
by
Jan Tattermusch
Browse files
Options
Downloads
Patches
Plain Diff
make some interop tests run as async methods
parent
9b048e52
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/csharp/Grpc.IntegrationTesting/InteropClient.cs
+118
-136
118 additions, 136 deletions
src/csharp/Grpc.IntegrationTesting/InteropClient.cs
src/csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs
+12
-12
12 additions, 12 deletions
...csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs
with
130 additions
and
148 deletions
src/csharp/Grpc.IntegrationTesting/InteropClient.cs
+
118
−
136
View file @
b98e1dd7
...
...
@@ -130,12 +130,12 @@ namespace Grpc.IntegrationTesting
client
.
HeaderInterceptor
=
OAuth2InterceptorFactory
.
Create
(
credential
);
}
RunTestCase
(
options
.
testCase
,
client
);
RunTestCase
Async
(
options
.
testCase
,
client
)
.
Wait
()
;
}
GrpcEnvironment
.
Shutdown
();
}
private
void
RunTestCase
(
string
testCase
,
TestService
.
TestServiceClient
client
)
private
async
Task
RunTestCase
Async
(
string
testCase
,
TestService
.
TestServiceClient
client
)
{
switch
(
testCase
)
{
...
...
@@ -146,16 +146,16 @@ namespace Grpc.IntegrationTesting
RunLargeUnary
(
client
);
break
;
case
"client_streaming"
:
RunClientStreaming
(
client
);
await
RunClientStreaming
Async
(
client
);
break
;
case
"server_streaming"
:
RunServerStreaming
(
client
);
await
RunServerStreaming
Async
(
client
);
break
;
case
"ping_pong"
:
RunPingPong
(
client
);
await
RunPingPong
Async
(
client
);
break
;
case
"empty_stream"
:
RunEmptyStream
(
client
);
await
RunEmptyStream
Async
(
client
);
break
;
case
"service_account_creds"
:
RunServiceAccountCreds
(
client
);
...
...
@@ -170,10 +170,10 @@ namespace Grpc.IntegrationTesting
RunPerRpcCreds
(
client
);
break
;
case
"cancel_after_begin"
:
RunCancelAfterBegin
(
client
);
await
RunCancelAfterBegin
Async
(
client
);
break
;
case
"cancel_after_first_response"
:
RunCancelAfterFirstResponse
(
client
);
await
RunCancelAfterFirstResponse
Async
(
client
);
break
;
case
"benchmark_empty_unary"
:
RunBenchmarkEmptyUnary
(
client
);
...
...
@@ -207,118 +207,106 @@ namespace Grpc.IntegrationTesting
Console
.
WriteLine
(
"Passed!"
);
}
public
static
void
RunClientStreaming
(
TestService
.
ITestServiceClient
client
)
public
static
async
Task
RunClientStreaming
Async
(
TestService
.
ITestServiceClient
client
)
{
Task
.
Run
(
async
()
=>
{
Console
.
WriteLine
(
"running client_streaming"
);
Console
.
WriteLine
(
"running client_streaming"
);
var
bodySizes
=
new
List
<
int
>
{
27182
,
8
,
1828
,
45904
}.
ConvertAll
((
size
)
=>
StreamingInputCallRequest
.
CreateBuilder
().
SetPayload
(
CreateZerosPayload
(
size
)).
Build
());
var
bodySizes
=
new
List
<
int
>
{
27182
,
8
,
1828
,
45904
}.
ConvertAll
((
size
)
=>
StreamingInputCallRequest
.
CreateBuilder
().
SetPayload
(
CreateZerosPayload
(
size
)).
Build
());
using
(
var
call
=
client
.
StreamingInputCall
())
{
await
call
.
RequestStream
.
WriteAll
(
bodySizes
);
using
(
var
call
=
client
.
StreamingInputCall
())
{
await
call
.
RequestStream
.
WriteAll
(
bodySizes
);
var
response
=
await
call
.
ResponseAsync
;
Assert
.
AreEqual
(
74922
,
response
.
AggregatedPayloadSize
);
}
Console
.
WriteLine
(
"Passed!"
);
}).
Wait
();
var
response
=
await
call
.
ResponseAsync
;
Assert
.
AreEqual
(
74922
,
response
.
AggregatedPayloadSize
);
}
Console
.
WriteLine
(
"Passed!"
);
}
public
static
void
RunServerStreaming
(
TestService
.
ITestServiceClient
client
)
public
static
async
Task
RunServerStreaming
Async
(
TestService
.
ITestServiceClient
client
)
{
Task
.
Run
(
async
()
=>
{
Console
.
WriteLine
(
"running server_streaming"
);
Console
.
WriteLine
(
"running server_streaming"
);
var
bodySizes
=
new
List
<
int
>
{
31415
,
9
,
2653
,
58979
};
var
bodySizes
=
new
List
<
int
>
{
31415
,
9
,
2653
,
58979
};
var
request
=
StreamingOutputCallRequest
.
CreateBuilder
()
.
SetResponseType
(
PayloadType
.
COMPRESSABLE
)
.
AddRangeResponseParameters
(
bodySizes
.
ConvertAll
(
(
size
)
=>
ResponseParameters
.
CreateBuilder
().
SetSize
(
size
).
Build
()))
.
Build
();
var
request
=
StreamingOutputCallRequest
.
CreateBuilder
()
.
SetResponseType
(
PayloadType
.
COMPRESSABLE
)
.
AddRangeResponseParameters
(
bodySizes
.
ConvertAll
(
(
size
)
=>
ResponseParameters
.
CreateBuilder
().
SetSize
(
size
).
Build
()))
.
Build
();
using
(
var
call
=
client
.
StreamingOutputCall
(
request
))
using
(
var
call
=
client
.
StreamingOutputCall
(
request
))
{
var
responseList
=
await
call
.
ResponseStream
.
ToList
();
foreach
(
var
res
in
responseList
)
{
var
responseList
=
await
call
.
ResponseStream
.
ToList
();
foreach
(
var
res
in
responseList
)
{
Assert
.
AreEqual
(
PayloadType
.
COMPRESSABLE
,
res
.
Payload
.
Type
);
}
CollectionAssert
.
AreEqual
(
bodySizes
,
responseList
.
ConvertAll
((
item
)
=>
item
.
Payload
.
Body
.
Length
));
Assert
.
AreEqual
(
PayloadType
.
COMPRESSABLE
,
res
.
Payload
.
Type
);
}
Console
.
WriteLine
(
"Passed!"
);
}).
Wait
();
CollectionAssert
.
AreEqual
(
bodySizes
,
responseList
.
ConvertAll
((
item
)
=>
item
.
Payload
.
Body
.
Length
));
}
Console
.
WriteLine
(
"Passed!"
);
}
public
static
void
RunPingPong
(
TestService
.
ITestServiceClient
client
)
public
static
async
Task
RunPingPong
Async
(
TestService
.
ITestServiceClient
client
)
{
Task
.
Run
(
async
()
=>
{
Console
.
WriteLine
(
"running ping_pong"
);
Console
.
WriteLine
(
"running ping_pong"
);
using
(
var
call
=
client
.
FullDuplexCall
())
{
await
call
.
RequestStream
.
WriteAsync
(
StreamingOutputCallRequest
.
CreateBuilder
()
.
SetResponseType
(
PayloadType
.
COMPRESSABLE
)
.
AddResponseParameters
(
ResponseParameters
.
CreateBuilder
().
SetSize
(
31415
))
.
SetPayload
(
CreateZerosPayload
(
27182
)).
Build
());
using
(
var
call
=
client
.
FullDuplexCall
())
{
await
call
.
RequestStream
.
WriteAsync
(
StreamingOutputCallRequest
.
CreateBuilder
()
.
SetResponseType
(
PayloadType
.
COMPRESSABLE
)
.
AddResponseParameters
(
ResponseParameters
.
CreateBuilder
().
SetSize
(
31415
))
.
SetPayload
(
CreateZerosPayload
(
27182
)).
Build
());
Assert
.
IsTrue
(
await
call
.
ResponseStream
.
MoveNext
());
Assert
.
AreEqual
(
PayloadType
.
COMPRESSABLE
,
call
.
ResponseStream
.
Current
.
Payload
.
Type
);
Assert
.
AreEqual
(
31415
,
call
.
ResponseStream
.
Current
.
Payload
.
Body
.
Length
);
Assert
.
IsTrue
(
await
call
.
ResponseStream
.
MoveNext
());
Assert
.
AreEqual
(
PayloadType
.
COMPRESSABLE
,
call
.
ResponseStream
.
Current
.
Payload
.
Type
);
Assert
.
AreEqual
(
31415
,
call
.
ResponseStream
.
Current
.
Payload
.
Body
.
Length
);
await
call
.
RequestStream
.
WriteAsync
(
StreamingOutputCallRequest
.
CreateBuilder
()
.
SetResponseType
(
PayloadType
.
COMPRESSABLE
)
.
AddResponseParameters
(
ResponseParameters
.
CreateBuilder
().
SetSize
(
9
))
.
SetPayload
(
CreateZerosPayload
(
8
)).
Build
());
await
call
.
RequestStream
.
WriteAsync
(
StreamingOutputCallRequest
.
CreateBuilder
()
.
SetResponseType
(
PayloadType
.
COMPRESSABLE
)
.
AddResponseParameters
(
ResponseParameters
.
CreateBuilder
().
SetSize
(
9
))
.
SetPayload
(
CreateZerosPayload
(
8
)).
Build
());
Assert
.
IsTrue
(
await
call
.
ResponseStream
.
MoveNext
());
Assert
.
AreEqual
(
PayloadType
.
COMPRESSABLE
,
call
.
ResponseStream
.
Current
.
Payload
.
Type
);
Assert
.
AreEqual
(
9
,
call
.
ResponseStream
.
Current
.
Payload
.
Body
.
Length
);
Assert
.
IsTrue
(
await
call
.
ResponseStream
.
MoveNext
());
Assert
.
AreEqual
(
PayloadType
.
COMPRESSABLE
,
call
.
ResponseStream
.
Current
.
Payload
.
Type
);
Assert
.
AreEqual
(
9
,
call
.
ResponseStream
.
Current
.
Payload
.
Body
.
Length
);
await
call
.
RequestStream
.
WriteAsync
(
StreamingOutputCallRequest
.
CreateBuilder
()
.
SetResponseType
(
PayloadType
.
COMPRESSABLE
)
.
AddResponseParameters
(
ResponseParameters
.
CreateBuilder
().
SetSize
(
2653
))
.
SetPayload
(
CreateZerosPayload
(
1828
)).
Build
());
await
call
.
RequestStream
.
WriteAsync
(
StreamingOutputCallRequest
.
CreateBuilder
()
.
SetResponseType
(
PayloadType
.
COMPRESSABLE
)
.
AddResponseParameters
(
ResponseParameters
.
CreateBuilder
().
SetSize
(
2653
))
.
SetPayload
(
CreateZerosPayload
(
1828
)).
Build
());
Assert
.
IsTrue
(
await
call
.
ResponseStream
.
MoveNext
());
Assert
.
AreEqual
(
PayloadType
.
COMPRESSABLE
,
call
.
ResponseStream
.
Current
.
Payload
.
Type
);
Assert
.
AreEqual
(
2653
,
call
.
ResponseStream
.
Current
.
Payload
.
Body
.
Length
);
Assert
.
IsTrue
(
await
call
.
ResponseStream
.
MoveNext
());
Assert
.
AreEqual
(
PayloadType
.
COMPRESSABLE
,
call
.
ResponseStream
.
Current
.
Payload
.
Type
);
Assert
.
AreEqual
(
2653
,
call
.
ResponseStream
.
Current
.
Payload
.
Body
.
Length
);
await
call
.
RequestStream
.
WriteAsync
(
StreamingOutputCallRequest
.
CreateBuilder
()
.
SetResponseType
(
PayloadType
.
COMPRESSABLE
)
.
AddResponseParameters
(
ResponseParameters
.
CreateBuilder
().
SetSize
(
58979
))
.
SetPayload
(
CreateZerosPayload
(
45904
)).
Build
());
await
call
.
RequestStream
.
WriteAsync
(
StreamingOutputCallRequest
.
CreateBuilder
()
.
SetResponseType
(
PayloadType
.
COMPRESSABLE
)
.
AddResponseParameters
(
ResponseParameters
.
CreateBuilder
().
SetSize
(
58979
))
.
SetPayload
(
CreateZerosPayload
(
45904
)).
Build
());
Assert
.
IsTrue
(
await
call
.
ResponseStream
.
MoveNext
());
Assert
.
AreEqual
(
PayloadType
.
COMPRESSABLE
,
call
.
ResponseStream
.
Current
.
Payload
.
Type
);
Assert
.
AreEqual
(
58979
,
call
.
ResponseStream
.
Current
.
Payload
.
Body
.
Length
);
Assert
.
IsTrue
(
await
call
.
ResponseStream
.
MoveNext
());
Assert
.
AreEqual
(
PayloadType
.
COMPRESSABLE
,
call
.
ResponseStream
.
Current
.
Payload
.
Type
);
Assert
.
AreEqual
(
58979
,
call
.
ResponseStream
.
Current
.
Payload
.
Body
.
Length
);
await
call
.
RequestStream
.
CompleteAsync
();
await
call
.
RequestStream
.
CompleteAsync
();
Assert
.
IsFalse
(
await
call
.
ResponseStream
.
MoveNext
());
}
Console
.
WriteLine
(
"Passed!"
);
}).
Wait
();
Assert
.
IsFalse
(
await
call
.
ResponseStream
.
MoveNext
());
}
Console
.
WriteLine
(
"Passed!"
);
}
public
static
void
RunEmptyStream
(
TestService
.
ITestServiceClient
client
)
public
static
async
Task
RunEmptyStream
Async
(
TestService
.
ITestServiceClient
client
)
{
Task
.
Run
(
async
()
=>
Console
.
WriteLine
(
"running empty_stream"
);
using
(
var
call
=
client
.
FullDuplexCall
())
{
Console
.
WriteLine
(
"running empty_stream"
);
using
(
var
call
=
client
.
FullDuplexCall
())
{
await
call
.
RequestStream
.
CompleteAsync
();
await
call
.
RequestStream
.
CompleteAsync
();
var
responseList
=
await
call
.
ResponseStream
.
ToList
();
Assert
.
AreEqual
(
0
,
responseList
.
Count
);
}
Console
.
WriteLine
(
"Passed!"
);
}).
Wait
();
var
responseList
=
await
call
.
ResponseStream
.
ToList
();
Assert
.
AreEqual
(
0
,
responseList
.
Count
);
}
Console
.
WriteLine
(
"Passed!"
);
}
public
static
void
RunServiceAccountCreds
(
TestService
.
ITestServiceClient
client
)
...
...
@@ -406,65 +394,59 @@ namespace Grpc.IntegrationTesting
Console
.
WriteLine
(
"Passed!"
);
}
public
static
void
RunCancelAfterBegin
(
TestService
.
ITestServiceClient
client
)
public
static
async
Task
RunCancelAfterBegin
Async
(
TestService
.
ITestServiceClient
client
)
{
Task
.
Run
(
async
()
=>
Console
.
WriteLine
(
"running cancel_after_begin"
);
var
cts
=
new
CancellationTokenSource
();
using
(
var
call
=
client
.
StreamingInputCall
(
cancellationToken
:
cts
.
Token
))
{
Console
.
WriteLine
(
"running cancel_after_begin"
);
// TODO(jtattermusch): we need this to ensure call has been initiated once we cancel it.
await
Task
.
Delay
(
1000
);
cts
.
Cancel
();
var
cts
=
new
CancellationTokenSource
();
using
(
var
call
=
client
.
StreamingInputCall
(
cancellationToken
:
cts
.
Token
))
try
{
// TODO(jtattermusch): we need this to ensure call has been initiated once we cancel it.
await
Task
.
Delay
(
1000
);
cts
.
Cancel
();
try
{
var
response
=
await
call
.
ResponseAsync
;
Assert
.
Fail
();
}
catch
(
RpcException
e
)
{
Assert
.
AreEqual
(
StatusCode
.
Cancelled
,
e
.
Status
.
StatusCode
);
}
var
response
=
await
call
.
ResponseAsync
;
Assert
.
Fail
();
}
catch
(
RpcException
e
)
{
Assert
.
AreEqual
(
StatusCode
.
Cancelled
,
e
.
Status
.
StatusCode
);
}
Console
.
WriteLine
(
"Passed!"
);
})
.
W
a
it
(
);
}
Console
.
W
r
it
eLine
(
"Passed!"
);
}
public
static
void
RunCancelAfterFirstResponse
(
TestService
.
ITestServiceClient
client
)
public
static
async
Task
RunCancelAfterFirstResponse
Async
(
TestService
.
ITestServiceClient
client
)
{
Task
.
Run
(
async
()
=>
{
Console
.
WriteLine
(
"running cancel_after_first_response"
);
Console
.
WriteLine
(
"running cancel_after_first_response"
);
var
cts
=
new
CancellationTokenSource
();
using
(
var
call
=
client
.
FullDuplexCall
(
cancellationToken
:
cts
.
Token
))
{
await
call
.
RequestStream
.
WriteAsync
(
StreamingOutputCallRequest
.
CreateBuilder
()
.
SetResponseType
(
PayloadType
.
COMPRESSABLE
)
.
AddResponseParameters
(
ResponseParameters
.
CreateBuilder
().
SetSize
(
31415
))
.
SetPayload
(
CreateZerosPayload
(
27182
)).
Build
());
var
cts
=
new
CancellationTokenSource
();
using
(
var
call
=
client
.
FullDuplexCall
(
cancellationToken
:
cts
.
Token
))
{
await
call
.
RequestStream
.
WriteAsync
(
StreamingOutputCallRequest
.
CreateBuilder
()
.
SetResponseType
(
PayloadType
.
COMPRESSABLE
)
.
AddResponseParameters
(
ResponseParameters
.
CreateBuilder
().
SetSize
(
31415
))
.
SetPayload
(
CreateZerosPayload
(
27182
)).
Build
());
Assert
.
IsTrue
(
await
call
.
ResponseStream
.
MoveNext
());
Assert
.
AreEqual
(
PayloadType
.
COMPRESSABLE
,
call
.
ResponseStream
.
Current
.
Payload
.
Type
);
Assert
.
AreEqual
(
31415
,
call
.
ResponseStream
.
Current
.
Payload
.
Body
.
Length
);
Assert
.
IsTrue
(
await
call
.
ResponseStream
.
MoveNext
());
Assert
.
AreEqual
(
PayloadType
.
COMPRESSABLE
,
call
.
ResponseStream
.
Current
.
Payload
.
Type
);
Assert
.
AreEqual
(
31415
,
call
.
ResponseStream
.
Current
.
Payload
.
Body
.
Length
);
cts
.
Cancel
();
cts
.
Cancel
();
try
{
await
call
.
ResponseStream
.
MoveNext
();
Assert
.
Fail
();
}
catch
(
RpcException
e
)
{
Assert
.
AreEqual
(
StatusCode
.
Cancelled
,
e
.
Status
.
StatusCode
);
}
try
{
await
call
.
ResponseStream
.
MoveNext
();
Assert
.
Fail
();
}
catch
(
RpcException
e
)
{
Assert
.
AreEqual
(
StatusCode
.
Cancelled
,
e
.
Status
.
StatusCode
);
}
Console
.
WriteLine
(
"Passed!"
);
})
.
W
a
it
(
);
}
Console
.
W
r
it
eLine
(
"Passed!"
);
}
// This is not an official interop test, but it's useful.
...
...
This diff is collapsed.
Click to expand it.
src/csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs
+
12
−
12
View file @
b98e1dd7
...
...
@@ -89,39 +89,39 @@ namespace Grpc.IntegrationTesting
}
[
Test
]
public
void
ClientStreaming
()
public
async
Task
ClientStreaming
()
{
InteropClient
.
RunClientStreaming
(
client
);
await
InteropClient
.
RunClientStreaming
Async
(
client
);
}
[
Test
]
public
void
ServerStreaming
()
public
async
Task
ServerStreaming
()
{
InteropClient
.
RunServerStreaming
(
client
);
await
InteropClient
.
RunServerStreaming
Async
(
client
);
}
[
Test
]
public
void
PingPong
()
public
async
Task
PingPong
()
{
InteropClient
.
RunPingPong
(
client
);
await
InteropClient
.
RunPingPong
Async
(
client
);
}
[
Test
]
public
void
EmptyStream
()
public
async
Task
EmptyStream
()
{
InteropClient
.
RunEmptyStream
(
client
);
await
InteropClient
.
RunEmptyStream
Async
(
client
);
}
[
Test
]
public
void
CancelAfterBegin
()
public
async
Task
CancelAfterBegin
()
{
InteropClient
.
RunCancelAfterBegin
(
client
);
await
InteropClient
.
RunCancelAfterBegin
Async
(
client
);
}
[
Test
]
public
void
CancelAfterFirstResponse
()
public
async
Task
CancelAfterFirstResponse
()
{
InteropClient
.
RunCancelAfterFirstResponse
(
client
);
await
InteropClient
.
RunCancelAfterFirstResponse
Async
(
client
);
}
}
}
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