Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: third_party/grpc/test/cpp/common/alarm_cpp_test.cc

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 *
3 * Copyright 2015-2016, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34 #include <grpc++/alarm.h>
35 #include <grpc++/completion_queue.h>
36 #include <gtest/gtest.h>
37
38 #include "test/core/util/test_config.h"
39
40 namespace grpc {
41 namespace {
42
43 TEST(AlarmTest, RegularExpiry) {
44 CompletionQueue cq;
45 void* junk = reinterpret_cast<void*>(1618033);
46 Alarm alarm(&cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1), junk);
47
48 void* output_tag;
49 bool ok;
50 const CompletionQueue::NextStatus status = cq.AsyncNext(
51 (void**)&output_tag, &ok, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(2));
52
53 EXPECT_EQ(status, CompletionQueue::GOT_EVENT);
54 EXPECT_TRUE(ok);
55 EXPECT_EQ(junk, output_tag);
56 }
57
58 TEST(AlarmTest, RegularExpiryChrono) {
59 CompletionQueue cq;
60 void* junk = reinterpret_cast<void*>(1618033);
61 std::chrono::system_clock::time_point one_sec_deadline =
62 std::chrono::system_clock::now() + std::chrono::seconds(1);
63 Alarm alarm(&cq, one_sec_deadline, junk);
64
65 void* output_tag;
66 bool ok;
67 const CompletionQueue::NextStatus status = cq.AsyncNext(
68 (void**)&output_tag, &ok, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(2));
69
70 EXPECT_EQ(status, CompletionQueue::GOT_EVENT);
71 EXPECT_TRUE(ok);
72 EXPECT_EQ(junk, output_tag);
73 }
74
75 TEST(AlarmTest, ZeroExpiry) {
76 CompletionQueue cq;
77 void* junk = reinterpret_cast<void*>(1618033);
78 Alarm alarm(&cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(0), junk);
79
80 void* output_tag;
81 bool ok;
82 const CompletionQueue::NextStatus status = cq.AsyncNext(
83 (void**)&output_tag, &ok, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(0));
84
85 EXPECT_EQ(status, CompletionQueue::GOT_EVENT);
86 EXPECT_TRUE(ok);
87 EXPECT_EQ(junk, output_tag);
88 }
89
90 TEST(AlarmTest, NegativeExpiry) {
91 CompletionQueue cq;
92 void* junk = reinterpret_cast<void*>(1618033);
93 Alarm alarm(&cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(-1), junk);
94
95 void* output_tag;
96 bool ok;
97 const CompletionQueue::NextStatus status = cq.AsyncNext(
98 (void**)&output_tag, &ok, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(0));
99
100 EXPECT_EQ(status, CompletionQueue::GOT_EVENT);
101 EXPECT_TRUE(ok);
102 EXPECT_EQ(junk, output_tag);
103 }
104
105 TEST(AlarmTest, Cancellation) {
106 CompletionQueue cq;
107 void* junk = reinterpret_cast<void*>(1618033);
108 Alarm alarm(&cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(2), junk);
109 alarm.Cancel();
110
111 void* output_tag;
112 bool ok;
113 const CompletionQueue::NextStatus status = cq.AsyncNext(
114 (void**)&output_tag, &ok, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1));
115
116 EXPECT_EQ(status, CompletionQueue::GOT_EVENT);
117 EXPECT_FALSE(ok);
118 EXPECT_EQ(junk, output_tag);
119 }
120
121 } // namespace
122 } // namespace grpc
123
124 int main(int argc, char** argv) {
125 grpc_test_init(argc, argv);
126 ::testing::InitGoogleTest(&argc, argv);
127 return RUN_ALL_TESTS();
128 }
OLDNEW
« no previous file with comments | « third_party/grpc/test/cpp/client/credentials_test.cc ('k') | third_party/grpc/test/cpp/common/auth_property_iterator_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698