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
8fdafede
Commit
8fdafede
authored
9 years ago
by
vjpai
Browse files
Options
Downloads
Patches
Plain Diff
tag fed in by user should be any arbitrary tag, not a CompletionQueueTag
type
parent
f9f61cf5
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/cpp/common/alarm.cc
+15
-1
15 additions, 1 deletion
src/cpp/common/alarm.cc
test/cpp/common/alarm_cpp_test.cc
+8
-20
8 additions, 20 deletions
test/cpp/common/alarm_cpp_test.cc
with
23 additions
and
21 deletions
src/cpp/common/alarm.cc
+
15
−
1
View file @
8fdafede
...
...
@@ -32,14 +32,28 @@
#include
<grpc++/alarm.h>
#include
<grpc++/completion_queue.h>
#include
<grpc++/impl/codegen/completion_queue_tag.h>
#include
<grpc++/impl/grpc_library.h>
#include
<grpc/grpc.h>
namespace
grpc
{
class
AlarmEntry
:
public
CompletionQueueTag
{
public:
AlarmEntry
(
void
*
tag
)
:
tag_
(
tag
)
{}
bool
FinalizeResult
(
void
**
tag
,
bool
*
status
)
GRPC_OVERRIDE
{
*
tag
=
tag_
;
delete
this
;
return
true
;
}
private
:
void
*
tag_
;
};
static
internal
::
GrpcLibraryInitializer
g_gli_initializer
;
Alarm
::
Alarm
(
CompletionQueue
*
cq
,
gpr_timespec
deadline
,
void
*
tag
)
:
alarm_
(
grpc_alarm_create
(
cq
->
cq
(),
deadline
,
tag
))
{
:
alarm_
(
grpc_alarm_create
(
cq
->
cq
(),
deadline
,
static_cast
<
void
*>
(
new
AlarmEntry
(
tag
))))
{
g_gli_initializer
.
summon
();
}
...
...
This diff is collapsed.
Click to expand it.
test/cpp/common/alarm_cpp_test.cc
+
8
−
20
View file @
8fdafede
...
...
@@ -33,7 +33,6 @@
#include
<grpc++/alarm.h>
#include
<grpc++/completion_queue.h>
#include
<grpc++/impl/codegen/completion_queue_tag.h>
#include
<gtest/gtest.h>
#include
"test/core/util/test_config.h"
...
...
@@ -41,46 +40,35 @@
namespace
grpc
{
namespace
{
class
TestTag
:
public
CompletionQueueTag
{
public:
TestTag
()
:
tag_
(
0
)
{}
TestTag
(
intptr_t
tag
)
:
tag_
(
tag
)
{}
bool
FinalizeResult
(
void
**
tag
,
bool
*
status
)
GRPC_OVERRIDE
{
return
true
;
}
intptr_t
tag
()
{
return
tag_
;
}
private
:
intptr_t
tag_
;
};
TEST
(
AlarmTest
,
RegularExpiry
)
{
CompletionQueue
cq
;
TestTag
input_tag
(
1618033
);
Alarm
alarm
(
&
cq
,
GRPC_TIMEOUT_SECONDS_TO_DEADLINE
(
1
),
&
input_tag
);
void
*
junk
=
reinterpret_cast
<
void
*>
(
1618033
);
Alarm
alarm
(
&
cq
,
GRPC_TIMEOUT_SECONDS_TO_DEADLINE
(
1
),
junk
);
TestTag
*
output_tag
;
void
*
output_tag
;
bool
ok
;
const
CompletionQueue
::
NextStatus
status
=
cq
.
AsyncNext
(
(
void
**
)
&
output_tag
,
&
ok
,
GRPC_TIMEOUT_SECONDS_TO_DEADLINE
(
2
));
EXPECT_EQ
(
status
,
CompletionQueue
::
GOT_EVENT
);
EXPECT_TRUE
(
ok
);
EXPECT_EQ
(
output_tag
->
tag
(),
in
put_tag
.
tag
()
);
EXPECT_EQ
(
junk
,
out
put_tag
);
}
TEST
(
AlarmTest
,
Cancellation
)
{
CompletionQueue
cq
;
TestTag
input_tag
(
1618033
);
Alarm
alarm
(
&
cq
,
GRPC_TIMEOUT_SECONDS_TO_DEADLINE
(
2
),
&
input_tag
);
void
*
junk
=
reinterpret_cast
<
void
*>
(
1618033
);
Alarm
alarm
(
&
cq
,
GRPC_TIMEOUT_SECONDS_TO_DEADLINE
(
2
),
junk
);
alarm
.
Cancel
();
TestTag
*
output_tag
;
void
*
output_tag
;
bool
ok
;
const
CompletionQueue
::
NextStatus
status
=
cq
.
AsyncNext
(
(
void
**
)
&
output_tag
,
&
ok
,
GRPC_TIMEOUT_SECONDS_TO_DEADLINE
(
1
));
EXPECT_EQ
(
status
,
CompletionQueue
::
GOT_EVENT
);
EXPECT_FALSE
(
ok
);
EXPECT_EQ
(
output_tag
->
tag
(),
in
put_tag
.
tag
()
);
EXPECT_EQ
(
junk
,
out
put_tag
);
}
}
// namespace
...
...
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