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
97eb4f67
Commit
97eb4f67
authored
8 years ago
by
Jan Tattermusch
Browse files
Options
Downloads
Patches
Plain Diff
add more tests
parent
6bac7d34
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs
+61
-0
61 additions, 0 deletions
src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs
with
61 additions
and
0 deletions
src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs
+
61
−
0
View file @
97eb4f67
...
...
@@ -32,6 +32,7 @@
#endregion
using
System
;
using
System.Collections.Generic
;
using
System.Runtime.InteropServices
;
using
System.Threading.Tasks
;
...
...
@@ -118,6 +119,14 @@ namespace Grpc.Core.Internal.Tests
AssertUnaryResponseError
(
asyncCall
,
fakeCall
,
resultTask
,
StatusCode
.
Internal
);
}
[
Test
]
public
void
ClientStreaming_StreamingReadNotAllowed
()
{
asyncCall
.
ClientStreamingCallAsync
();
Assert
.
Throws
(
typeof
(
InvalidOperationException
),
()
=>
asyncCall
.
StartReadMessage
((
x
,
y
)
=>
{}));
}
[
Test
]
public
void
ClientStreaming_NoRequest_Success
()
{
...
...
@@ -142,6 +151,47 @@ namespace Grpc.Core.Internal.Tests
AssertUnaryResponseError
(
asyncCall
,
fakeCall
,
resultTask
,
StatusCode
.
InvalidArgument
);
}
[
Test
]
public
void
ServerStreaming_StreamingSendNotAllowed
()
{
asyncCall
.
StartServerStreamingCall
(
"request1"
);
Assert
.
Throws
(
typeof
(
InvalidOperationException
),
()
=>
asyncCall
.
StartSendMessage
(
"abc"
,
new
WriteFlags
(),
(
x
,
y
)
=>
{}));
}
[
Test
]
public
void
ServerStreaming_NoResponse1_Success
()
{
asyncCall
.
StartServerStreamingCall
(
"request1"
);
var
responseStream
=
new
ClientResponseStream
<
string
,
string
>(
asyncCall
);
var
readTask
=
responseStream
.
MoveNext
();
fakeCall
.
ReceivedResponseHeadersHandler
(
true
,
new
Metadata
());
Assert
.
AreEqual
(
0
,
asyncCall
.
ResponseHeadersAsync
.
Result
.
Count
);
fakeCall
.
ReceivedMessageHandler
(
true
,
null
);
fakeCall
.
ReceivedStatusOnClientHandler
(
true
,
new
ClientSideStatus
(
Status
.
DefaultSuccess
,
new
Metadata
()));
AssertStreamingResponseSuccess
(
asyncCall
,
fakeCall
,
readTask
);
}
[
Test
]
public
void
ServerStreaming_NoResponse2_Success
()
{
asyncCall
.
StartServerStreamingCall
(
"request1"
);
var
responseStream
=
new
ClientResponseStream
<
string
,
string
>(
asyncCall
);
var
readTask
=
responseStream
.
MoveNext
();
fakeCall
.
ReceivedResponseHeadersHandler
(
true
,
new
Metadata
());
Assert
.
AreEqual
(
0
,
asyncCall
.
ResponseHeadersAsync
.
Result
.
Count
);
// try alternative order of completions
fakeCall
.
ReceivedStatusOnClientHandler
(
true
,
new
ClientSideStatus
(
Status
.
DefaultSuccess
,
new
Metadata
()));
fakeCall
.
ReceivedMessageHandler
(
true
,
null
);
AssertStreamingResponseSuccess
(
asyncCall
,
fakeCall
,
readTask
);
}
ClientSideStatus
CreateClientSideStatus
(
StatusCode
statusCode
)
{
return
new
ClientSideStatus
(
new
Status
(
statusCode
,
""
),
new
Metadata
());
...
...
@@ -163,6 +213,17 @@ namespace Grpc.Core.Internal.Tests
Assert
.
AreEqual
(
"response1"
,
resultTask
.
Result
);
}
static
void
AssertStreamingResponseSuccess
(
AsyncCall
<
string
,
string
>
asyncCall
,
FakeNativeCall
fakeCall
,
Task
<
bool
>
moveNextTask
)
{
Assert
.
IsTrue
(
moveNextTask
.
IsCompleted
);
Assert
.
IsTrue
(
fakeCall
.
IsDisposed
);
Assert
.
IsFalse
(
moveNextTask
.
Result
);
Assert
.
AreEqual
(
Status
.
DefaultSuccess
,
asyncCall
.
GetStatus
());
Assert
.
AreEqual
(
0
,
asyncCall
.
ResponseHeadersAsync
.
Result
.
Count
);
Assert
.
AreEqual
(
0
,
asyncCall
.
GetTrailers
().
Count
);
}
static
void
AssertUnaryResponseError
(
AsyncCall
<
string
,
string
>
asyncCall
,
FakeNativeCall
fakeCall
,
Task
<
string
>
resultTask
,
StatusCode
expectedStatusCode
)
{
Assert
.
IsTrue
(
resultTask
.
IsCompleted
);
...
...
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