|
|
|
@ -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(), input_tag.tag()); |
|
|
|
|
EXPECT_EQ(junk, output_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(), input_tag.tag()); |
|
|
|
|
EXPECT_EQ(junk, output_tag); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|