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
bbbbf621
Commit
bbbbf621
authored
8 years ago
by
Vijay Pai
Browse files
Options
Downloads
Patches
Plain Diff
Add a concurrent test for sync client, async server case
parent
e5cc05b5
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
test/cpp/end2end/thread_stress_test.cc
+144
-18
144 additions, 18 deletions
test/cpp/end2end/thread_stress_test.cc
with
144 additions
and
18 deletions
test/cpp/end2end/thread_stress_test.cc
+
144
−
18
View file @
bbbbf621
...
@@ -58,6 +58,7 @@ using std::chrono::system_clock;
...
@@ -58,6 +58,7 @@ using std::chrono::system_clock;
const
int
kNumThreads
=
100
;
// Number of threads
const
int
kNumThreads
=
100
;
// Number of threads
const
int
kNumAsyncSendThreads
=
2
;
const
int
kNumAsyncSendThreads
=
2
;
const
int
kNumAsyncReceiveThreads
=
50
;
const
int
kNumAsyncReceiveThreads
=
50
;
const
int
kNumAsyncServerThreads
=
50
;
const
int
kNumRpcs
=
1000
;
// Number of RPCs per thread
const
int
kNumRpcs
=
1000
;
// Number of RPCs per thread
namespace
grpc
{
namespace
grpc
{
...
@@ -174,39 +175,142 @@ class TestServiceImplDupPkg
...
@@ -174,39 +175,142 @@ class TestServiceImplDupPkg
}
}
};
};
template
<
class
Service
>
class
CommonStressTest
{
class
CommonStressTest
{
public:
public:
CommonStressTest
()
:
kMaxMessageSize_
(
8192
)
{}
CommonStressTest
()
:
kMaxMessageSize_
(
8192
)
{}
void
SetUp
()
{
virtual
void
SetUp
()
=
0
;
int
port
=
grpc_pick_unused_port_or_die
();
virtual
void
TearDown
()
=
0
;
server_address_
<<
"localhost:"
<<
port
;
// Setup server
ServerBuilder
builder
;
builder
.
AddListeningPort
(
server_address_
.
str
(),
InsecureServerCredentials
());
builder
.
RegisterService
(
&
service_
);
builder
.
SetMaxMessageSize
(
kMaxMessageSize_
);
// For testing max message size.
builder
.
RegisterService
(
&
dup_pkg_service_
);
server_
=
builder
.
BuildAndStart
();
}
void
TearDown
()
{
server_
->
Shutdown
();
}
void
ResetStub
()
{
void
ResetStub
()
{
std
::
shared_ptr
<
Channel
>
channel
=
std
::
shared_ptr
<
Channel
>
channel
=
CreateChannel
(
server_address_
.
str
(),
InsecureChannelCredentials
());
CreateChannel
(
server_address_
.
str
(),
InsecureChannelCredentials
());
stub_
=
grpc
::
testing
::
EchoTestService
::
NewStub
(
channel
);
stub_
=
grpc
::
testing
::
EchoTestService
::
NewStub
(
channel
);
}
}
grpc
::
testing
::
EchoTestService
::
Stub
*
GetStub
()
{
return
stub_
.
get
();
}
grpc
::
testing
::
EchoTestService
::
Stub
*
GetStub
()
{
return
stub_
.
get
();
}
protected
:
void
SetUpStart
(
ServerBuilder
*
builder
,
Service
*
service
)
{
int
port
=
grpc_pick_unused_port_or_die
();
server_address_
<<
"localhost:"
<<
port
;
// Setup server
builder
->
AddListeningPort
(
server_address_
.
str
(),
InsecureServerCredentials
());
builder
->
RegisterService
(
service
);
builder
->
SetMaxMessageSize
(
kMaxMessageSize_
);
// For testing max message size.
builder
->
RegisterService
(
&
dup_pkg_service_
);
}
void
SetUpEnd
(
ServerBuilder
*
builder
)
{
server_
=
builder
->
BuildAndStart
();
}
void
TearDownStart
()
{
server_
->
Shutdown
();
}
void
TearDownEnd
()
{
}
private
:
private
:
std
::
unique_ptr
<
grpc
::
testing
::
EchoTestService
::
Stub
>
stub_
;
std
::
unique_ptr
<
grpc
::
testing
::
EchoTestService
::
Stub
>
stub_
;
std
::
unique_ptr
<
Server
>
server_
;
std
::
unique_ptr
<
Server
>
server_
;
std
::
ostringstream
server_address_
;
std
::
ostringstream
server_address_
;
const
int
kMaxMessageSize_
;
const
int
kMaxMessageSize_
;
TestServiceImpl
service_
;
TestServiceImplDupPkg
dup_pkg_service_
;
TestServiceImplDupPkg
dup_pkg_service_
;
};
};
class
CommonStressTestSyncServer
:
public
CommonStressTest
<
TestServiceImpl
>
{
public:
void
SetUp
()
GRPC_OVERRIDE
{
ServerBuilder
builder
;
SetUpStart
(
&
builder
,
&
service_
);
SetUpEnd
(
&
builder
);
}
void
TearDown
()
GRPC_OVERRIDE
{
TearDownStart
();
TearDownEnd
();
}
private
:
TestServiceImpl
service_
;
};
class
CommonStressTestAsyncServer
:
public
CommonStressTest
<
::
grpc
::
testing
::
EchoTestService
::
AsyncService
>
{
public:
void
SetUp
()
GRPC_OVERRIDE
{
shutting_down_
=
false
;
ServerBuilder
builder
;
SetUpStart
(
&
builder
,
&
service_
);
cq_
=
builder
.
AddCompletionQueue
();
SetUpEnd
(
&
builder
);
contexts_
=
new
Context
[
kNumAsyncServerThreads
*
100
];
for
(
int
i
=
0
;
i
<
kNumAsyncServerThreads
*
100
;
i
++
)
{
RefreshContext
(
i
);
}
for
(
int
i
=
0
;
i
<
kNumAsyncServerThreads
;
i
++
)
{
server_threads_
.
push_back
(
new
std
::
thread
(
&
CommonStressTestAsyncServer
::
ProcessRpcs
,
this
));
}
}
void
TearDown
()
GRPC_OVERRIDE
{
{
unique_lock
<
mutex
>
l
(
mu_
);
TearDownStart
();
shutting_down_
=
true
;
cq_
->
Shutdown
();
}
for
(
int
i
=
0
;
i
<
kNumAsyncServerThreads
;
i
++
)
{
server_threads_
[
i
]
->
join
();
delete
server_threads_
[
i
];
}
void
*
ignored_tag
;
bool
ignored_ok
;
while
(
cq_
->
Next
(
&
ignored_tag
,
&
ignored_ok
))
;
TearDownEnd
();
delete
[]
contexts_
;
}
private
:
void
ProcessRpcs
()
{
void
*
tag
;
bool
ok
;
while
(
cq_
->
Next
(
&
tag
,
&
ok
))
{
if
(
ok
)
{
int
i
=
static_cast
<
int
>
(
reinterpret_cast
<
intptr_t
>
(
tag
));
switch
(
contexts_
[
i
].
state
)
{
case
Context
::
READY
:
{
contexts_
[
i
].
state
=
Context
::
DONE
;
EchoResponse
send_response
;
send_response
.
set_message
(
contexts_
[
i
].
recv_request
.
message
());
contexts_
[
i
].
response_writer
->
Finish
(
send_response
,
Status
::
OK
,
tag
);
break
;
}
case
Context
::
DONE
:
RefreshContext
(
i
);
break
;
}
}
}
}
void
RefreshContext
(
int
i
)
{
unique_lock
<
mutex
>
l
(
mu_
);
if
(
!
shutting_down_
)
{
contexts_
[
i
].
state
=
Context
::
READY
;
contexts_
[
i
].
srv_ctx
.
reset
(
new
ServerContext
);
contexts_
[
i
].
response_writer
.
reset
(
new
grpc
::
ServerAsyncResponseWriter
<
EchoResponse
>
(
contexts_
[
i
].
srv_ctx
.
get
()));
service_
.
RequestEcho
(
contexts_
[
i
].
srv_ctx
.
get
(),
&
contexts_
[
i
].
recv_request
,
contexts_
[
i
].
response_writer
.
get
(),
cq_
.
get
(),
cq_
.
get
(),
(
void
*
)(
intptr_t
)
i
);
}
}
struct
Context
{
std
::
unique_ptr
<
ServerContext
>
srv_ctx
;
std
::
unique_ptr
<
grpc
::
ServerAsyncResponseWriter
<
EchoResponse
>>
response_writer
;
EchoRequest
recv_request
;
enum
{
READY
,
DONE
}
state
;
}
*
contexts_
;
::
grpc
::
testing
::
EchoTestService
::
AsyncService
service_
;
std
::
unique_ptr
<
ServerCompletionQueue
>
cq_
;
bool
shutting_down_
;
mutex
mu_
;
std
::
vector
<
std
::
thread
*>
server_threads_
;
};
class
End2endTest
:
public
::
testing
::
Test
{
class
End2endTest
:
public
::
testing
::
Test
{
protected:
protected:
End2endTest
()
{}
End2endTest
()
{}
...
@@ -214,7 +318,17 @@ class End2endTest : public ::testing::Test {
...
@@ -214,7 +318,17 @@ class End2endTest : public ::testing::Test {
void
TearDown
()
GRPC_OVERRIDE
{
common_
.
TearDown
();
}
void
TearDown
()
GRPC_OVERRIDE
{
common_
.
TearDown
();
}
void
ResetStub
()
{
common_
.
ResetStub
();
}
void
ResetStub
()
{
common_
.
ResetStub
();
}
CommonStressTest
common_
;
CommonStressTestSyncServer
common_
;
};
class
End2endTestAsyncServer
:
public
::
testing
::
Test
{
protected:
End2endTestAsyncServer
()
{}
void
SetUp
()
GRPC_OVERRIDE
{
common_
.
SetUp
();
}
void
TearDown
()
GRPC_OVERRIDE
{
common_
.
TearDown
();
}
void
ResetStub
()
{
common_
.
ResetStub
();
}
CommonStressTestAsyncServer
common_
;
};
};
static
void
SendRpc
(
grpc
::
testing
::
EchoTestService
::
Stub
*
stub
,
int
num_rpcs
)
{
static
void
SendRpc
(
grpc
::
testing
::
EchoTestService
::
Stub
*
stub
,
int
num_rpcs
)
{
...
@@ -242,6 +356,18 @@ TEST_F(End2endTest, ThreadStress) {
...
@@ -242,6 +356,18 @@ TEST_F(End2endTest, ThreadStress) {
}
}
}
}
TEST_F
(
End2endTestAsyncServer
,
ThreadStress
)
{
common_
.
ResetStub
();
std
::
vector
<
std
::
thread
*>
threads
;
for
(
int
i
=
0
;
i
<
kNumThreads
;
++
i
)
{
threads
.
push_back
(
new
std
::
thread
(
SendRpc
,
common_
.
GetStub
(),
kNumRpcs
));
}
for
(
int
i
=
0
;
i
<
kNumThreads
;
++
i
)
{
threads
[
i
]
->
join
();
delete
threads
[
i
];
}
}
class
AsyncClientEnd2endTest
:
public
::
testing
::
Test
{
class
AsyncClientEnd2endTest
:
public
::
testing
::
Test
{
protected:
protected:
AsyncClientEnd2endTest
()
:
rpcs_outstanding_
(
0
)
{}
AsyncClientEnd2endTest
()
:
rpcs_outstanding_
(
0
)
{}
...
@@ -309,7 +435,7 @@ class AsyncClientEnd2endTest : public ::testing::Test {
...
@@ -309,7 +435,7 @@ class AsyncClientEnd2endTest : public ::testing::Test {
}
}
}
}
CommonStressTest
common_
;
CommonStressTest
SyncServer
common_
;
CompletionQueue
cq_
;
CompletionQueue
cq_
;
mutex
mu_
;
mutex
mu_
;
condition_variable
cv_
;
condition_variable
cv_
;
...
...
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