aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/core/surface/BUILD12
-rw-r--r--test/core/surface/alarm_test.cc116
-rw-r--r--test/core/surface/public_headers_must_be_c89.c4
-rw-r--r--test/cpp/common/BUILD4
-rw-r--r--test/cpp/common/alarm_test.cc (renamed from test/cpp/common/alarm_cpp_test.cc)23
5 files changed, 25 insertions, 134 deletions
diff --git a/test/core/surface/BUILD b/test/core/surface/BUILD
index 6cec7feabc..d27123d1a3 100644
--- a/test/core/surface/BUILD
+++ b/test/core/surface/BUILD
@@ -19,18 +19,6 @@ licenses(["notice"]) # Apache v2
grpc_package(name = "test/core/surface")
grpc_cc_test(
- name = "alarm_test",
- srcs = ["alarm_test.cc"],
- language = "C++",
- deps = [
- "//:gpr",
- "//:grpc",
- "//test/core/util:gpr_test_util",
- "//test/core/util:grpc_test_util",
- ],
-)
-
-grpc_cc_test(
name = "grpc_byte_buffer_reader_test",
srcs = ["byte_buffer_reader_test.cc"],
language = "C++",
diff --git a/test/core/surface/alarm_test.cc b/test/core/surface/alarm_test.cc
deleted file mode 100644
index 67fc6833a5..0000000000
--- a/test/core/surface/alarm_test.cc
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- *
- * Copyright 2015 gRPC authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <grpc/grpc.h>
-#include <grpc/support/alloc.h>
-#include <grpc/support/log.h>
-#include <grpc/support/time.h>
-#include <grpc/support/useful.h>
-#include "test/core/util/test_config.h"
-
-#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x)
-
-static void* create_test_tag(void) {
- static intptr_t i = 0;
- return (void*)(++i);
-}
-
-/* helper for tests to shutdown correctly and tersely */
-static void shutdown_and_destroy(grpc_completion_queue* cc) {
- grpc_event ev;
- grpc_completion_queue_shutdown(cc);
- /* By the time grpc_completion_queue_shutdown runs, the cq's internal
- pending event counter might not have been updated yet by a previous
- cq_end_op_for_next (which releases a completed event first and only later
- updates the pending event counter), so we can't rely on a no-polling
- cq_next to never return GRPC_QUEUE_TIMEOUT. Using a deadline in the future
- solves the problem. See https://github.com/grpc/grpc/issues/13693.
- */
- ev = grpc_completion_queue_next(cc, grpc_timeout_seconds_to_deadline(2),
- nullptr);
- GPR_ASSERT(ev.type == GRPC_QUEUE_SHUTDOWN);
- grpc_completion_queue_destroy(cc);
-}
-
-static void test_alarm(void) {
- grpc_completion_queue* cc;
-
- LOG_TEST("test_alarm");
- cc = grpc_completion_queue_create_for_next(nullptr);
- {
- /* regular expiry */
- grpc_event ev;
- void* tag = create_test_tag();
- grpc_alarm* alarm = grpc_alarm_create(nullptr);
- grpc_alarm_set(alarm, cc, grpc_timeout_seconds_to_deadline(1), tag,
- nullptr);
-
- ev = grpc_completion_queue_next(cc, grpc_timeout_seconds_to_deadline(2),
- nullptr);
- GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
- GPR_ASSERT(ev.tag == tag);
- GPR_ASSERT(ev.success);
- grpc_alarm_destroy(alarm, nullptr);
- }
- {
- /* cancellation */
- grpc_event ev;
- void* tag = create_test_tag();
- grpc_alarm* alarm = grpc_alarm_create(nullptr);
- grpc_alarm_set(alarm, cc, grpc_timeout_seconds_to_deadline(2), tag,
- nullptr);
-
- grpc_alarm_cancel(alarm, nullptr);
- ev = grpc_completion_queue_next(cc, grpc_timeout_seconds_to_deadline(1),
- nullptr);
- GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
- GPR_ASSERT(ev.tag == tag);
- GPR_ASSERT(ev.success == 0);
- grpc_alarm_destroy(alarm, nullptr);
- }
- {
- /* alarm_destroy before cq_next */
- grpc_event ev;
- void* tag = create_test_tag();
- grpc_alarm* alarm = grpc_alarm_create(nullptr);
- grpc_alarm_set(alarm, cc, grpc_timeout_seconds_to_deadline(2), tag,
- nullptr);
-
- grpc_alarm_destroy(alarm, nullptr);
- ev = grpc_completion_queue_next(cc, grpc_timeout_seconds_to_deadline(1),
- nullptr);
- GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
- GPR_ASSERT(ev.tag == tag);
- GPR_ASSERT(ev.success == 0);
- }
- {
- /* alarm_destroy before set */
- grpc_alarm* alarm = grpc_alarm_create(nullptr);
- grpc_alarm_destroy(alarm, nullptr);
- }
-
- shutdown_and_destroy(cc);
-}
-
-int main(int argc, char** argv) {
- grpc_test_init(argc, argv);
- grpc_init();
- test_alarm();
- grpc_shutdown();
- return 0;
-}
diff --git a/test/core/surface/public_headers_must_be_c89.c b/test/core/surface/public_headers_must_be_c89.c
index f4de5d7d8a..36d5ad66a5 100644
--- a/test/core/surface/public_headers_must_be_c89.c
+++ b/test/core/surface/public_headers_must_be_c89.c
@@ -97,10 +97,6 @@ int main(int argc, char **argv) {
printf("%lx", (unsigned long) grpc_completion_queue_destroy);
printf("%lx", (unsigned long) grpc_completion_queue_thread_local_cache_init);
printf("%lx", (unsigned long) grpc_completion_queue_thread_local_cache_flush);
- printf("%lx", (unsigned long) grpc_alarm_create);
- printf("%lx", (unsigned long) grpc_alarm_set);
- printf("%lx", (unsigned long) grpc_alarm_cancel);
- printf("%lx", (unsigned long) grpc_alarm_destroy);
printf("%lx", (unsigned long) grpc_channel_check_connectivity_state);
printf("%lx", (unsigned long) grpc_channel_num_external_connectivity_watchers);
printf("%lx", (unsigned long) grpc_channel_watch_connectivity_state);
diff --git a/test/cpp/common/BUILD b/test/cpp/common/BUILD
index e2b6365b13..2cf3ad669f 100644
--- a/test/cpp/common/BUILD
+++ b/test/cpp/common/BUILD
@@ -19,8 +19,8 @@ load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_package")
grpc_package(name = "test/cpp/common")
grpc_cc_test(
- name = "alarm_cpp_test",
- srcs = ["alarm_cpp_test.cc"],
+ name = "alarm_test",
+ srcs = ["alarm_test.cc"],
deps = [
"//:grpc++_unsecure",
"//test/core/util:gpr_test_util",
diff --git a/test/cpp/common/alarm_cpp_test.cc b/test/cpp/common/alarm_test.cc
index 7adc3102f4..2a933a84c4 100644
--- a/test/cpp/common/alarm_cpp_test.cc
+++ b/test/cpp/common/alarm_test.cc
@@ -182,6 +182,29 @@ TEST(AlarmTest, Cancellation) {
EXPECT_EQ(junk, output_tag);
}
+TEST(AlarmTest, SetDestruction) {
+ CompletionQueue cq;
+ void* junk = reinterpret_cast<void*>(1618033);
+ {
+ Alarm alarm;
+ alarm.Set(&cq, grpc_timeout_seconds_to_deadline(2), junk);
+ }
+
+ 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(junk, output_tag);
+}
+
+TEST(AlarmTest, UnsetDestruction) {
+ CompletionQueue cq;
+ Alarm alarm;
+}
+
} // namespace
} // namespace grpc