Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
443b0c2b
Commit
443b0c2b
authored
Oct 15, 2018
by
TousakaRin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update unit-test
parent
b67ef038
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
16 deletions
+15
-16
brpc_circuit_breaker_unittest.cpp
test/brpc_circuit_breaker_unittest.cpp
+15
-16
No files found.
test/brpc_circuit_breaker_unittest.cpp
View file @
443b0c2b
...
...
@@ -60,14 +60,10 @@ struct FeedbackControl {
:
_req_num
(
req_num
)
,
_error_percent
(
error_percent
)
,
_circuit_breaker
(
circuit_breaker
)
,
_healthy_cnt
(
0
)
,
_unhealthy_cnt
(
0
)
,
_healthy
(
true
)
{}
int
_req_num
;
int
_error_percent
;
brpc
::
CircuitBreaker
*
_circuit_breaker
;
int
_healthy_cnt
;
int
_unhealthy_cnt
;
bool
_healthy
;
};
...
...
@@ -91,10 +87,8 @@ protected:
healthy
=
fc
->
_circuit_breaker
->
OnCallEnd
(
kErrorCodeForSucc
,
kLatency
);
}
fc
->
_healthy
=
healthy
;
if
(
healthy
)
{
++
fc
->
_healthy_cnt
;
}
else
{
++
fc
->
_unhealthy_cnt
;
if
(
!
healthy
)
{
break
;
}
}
return
fc
;
...
...
@@ -126,9 +120,11 @@ TEST_F(CircuitBreakerTest, should_not_isolate) {
void
*
ret_data
=
NULL
;
EXPECT_EQ
(
pthread_join
(
thread_list
[
i
],
&
ret_data
),
0
);
FeedbackControl
*
fc
=
static_cast
<
FeedbackControl
*>
(
ret_data
);
EXPECT_EQ
(
fc
->
_unhealthy_cnt
,
0
);
EXPECT_TRUE
(
fc
->
_healthy
);
}
// MarkAsBroken shoul be called only once.
_circuit_breaker
.
MarkAsBroken
();
_circuit_breaker
.
Reset
();
}
TEST_F
(
CircuitBreakerTest
,
should_isolate
)
{
...
...
@@ -139,12 +135,15 @@ TEST_F(CircuitBreakerTest, should_isolate) {
void
*
ret_data
=
NULL
;
EXPECT_EQ
(
pthread_join
(
thread_list
[
i
],
&
ret_data
),
0
);
FeedbackControl
*
fc
=
static_cast
<
FeedbackControl
*>
(
ret_data
);
EXPECT_GT
(
fc
->
_unhealthy_cnt
,
0
);
EXPECT_FALSE
(
fc
->
_healthy
);
}
// MarkAsBroken shoul be called only once.
_circuit_breaker
.
MarkAsBroken
();
_circuit_breaker
.
Reset
();
}
TEST_F
(
CircuitBreakerTest
,
isolation_duration_grow
)
{
EXPECT_EQ
(
_circuit_breaker
.
isolation_duration_ms
(),
kMinIsolationDurationMs
);
_circuit_breaker
.
Reset
();
std
::
vector
<
pthread_t
>
thread_list
;
std
::
vector
<
std
::
unique_ptr
<
FeedbackControl
>>
fc_list
;
...
...
@@ -154,9 +153,9 @@ TEST_F(CircuitBreakerTest, isolation_duration_grow) {
EXPECT_EQ
(
pthread_join
(
thread_list
[
i
],
&
ret_data
),
0
);
FeedbackControl
*
fc
=
static_cast
<
FeedbackControl
*>
(
ret_data
);
EXPECT_FALSE
(
fc
->
_healthy
);
EXPECT_LE
(
fc
->
_healthy_cnt
,
kShortWindowSize
);
EXPECT_GT
(
fc
->
_unhealthy_cnt
,
0
);
}
// MarkAsBroken shoul be called only once.
_circuit_breaker
.
MarkAsBroken
();
EXPECT_EQ
(
_circuit_breaker
.
isolation_duration_ms
(),
kMinIsolationDurationMs
*
2
);
_circuit_breaker
.
Reset
();
...
...
@@ -167,9 +166,9 @@ TEST_F(CircuitBreakerTest, isolation_duration_grow) {
EXPECT_EQ
(
pthread_join
(
thread_list
[
i
],
&
ret_data
),
0
);
FeedbackControl
*
fc
=
static_cast
<
FeedbackControl
*>
(
ret_data
);
EXPECT_FALSE
(
fc
->
_healthy
);
EXPECT_LE
(
fc
->
_healthy_cnt
,
kShortWindowSize
);
EXPECT_GT
(
fc
->
_unhealthy_cnt
,
0
);
}
// MarkAsBroken shoul be called only once.
_circuit_breaker
.
MarkAsBroken
();
EXPECT_EQ
(
_circuit_breaker
.
isolation_duration_ms
(),
kMinIsolationDurationMs
*
4
);
_circuit_breaker
.
Reset
();
...
...
@@ -180,8 +179,8 @@ TEST_F(CircuitBreakerTest, isolation_duration_grow) {
EXPECT_EQ
(
pthread_join
(
thread_list
[
i
],
&
ret_data
),
0
);
FeedbackControl
*
fc
=
static_cast
<
FeedbackControl
*>
(
ret_data
);
EXPECT_FALSE
(
fc
->
_healthy
);
EXPECT_LE
(
fc
->
_healthy_cnt
,
kShortWindowSize
);
EXPECT_GT
(
fc
->
_unhealthy_cnt
,
0
);
}
// MarkAsBroken shoul be called only once.
_circuit_breaker
.
MarkAsBroken
();
EXPECT_EQ
(
_circuit_breaker
.
isolation_duration_ms
(),
kMinIsolationDurationMs
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment