blob: 6113885171a6e71f6169439fa0c586f32fd09b75 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015 gRPC authors.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080016 *
17 */
18
David Garcia Quintasa301eaa2016-05-06 16:59:03 -070019#include <string.h>
20
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080021#include <grpc/grpc.h>
Craig Tiller5fe7e5d2015-05-01 10:52:35 -070022#include <grpc/support/alloc.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080023#include <grpc/support/log.h>
David Garcia Quintasa301eaa2016-05-06 16:59:03 -070024
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080025#include "test/core/end2end/cq_verifier.h"
26#include "test/core/util/test_config.h"
27
Craig Tillerbaa14a92017-11-03 09:09:36 -070028static void* tag(intptr_t i) { return (void*)i; }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080029
Craig Tillerbaa14a92017-11-03 09:09:36 -070030int main(int argc, char** argv) {
31 grpc_channel* chan;
32 grpc_call* call;
Robbie Shadeca7effc2017-01-17 09:14:29 -050033 gpr_timespec deadline = grpc_timeout_seconds_to_deadline(2);
Craig Tillerbaa14a92017-11-03 09:09:36 -070034 grpc_completion_queue* cq;
35 cq_verifier* cqv;
Craig Tillereeb42882015-04-29 14:00:55 -070036 grpc_op ops[6];
Craig Tillerbaa14a92017-11-03 09:09:36 -070037 grpc_op* op;
Craig Tillereeb42882015-04-29 14:00:55 -070038 grpc_metadata_array trailing_metadata_recv;
39 grpc_status_code status;
Craig Tiller7c70b6c2017-01-23 07:48:42 -080040 grpc_slice details;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080041
42 grpc_test_init(argc, argv);
43 grpc_init();
44
Craig Tillereeb42882015-04-29 14:00:55 -070045 grpc_metadata_array_init(&trailing_metadata_recv);
46
Craig Tiller4ac2b8e2017-11-10 14:14:17 -080047 cq = grpc_completion_queue_create_for_next(nullptr);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080048 cqv = cq_verifier_create(cq);
49
50 /* create a call, channel to a non existant server */
Craig Tiller4ac2b8e2017-11-10 14:14:17 -080051 chan = grpc_insecure_channel_create("nonexistant:54321", nullptr, nullptr);
Craig Tiller7c70b6c2017-01-23 07:48:42 -080052 grpc_slice host = grpc_slice_from_static_string("nonexistant");
Craig Tiller4ac2b8e2017-11-10 14:14:17 -080053 call = grpc_channel_create_call(chan, nullptr, GRPC_PROPAGATE_DEFAULTS, cq,
Craig Tiller7c70b6c2017-01-23 07:48:42 -080054 grpc_slice_from_static_string("/Foo"), &host,
Craig Tiller4ac2b8e2017-11-10 14:14:17 -080055 deadline, nullptr);
Craig Tillereeb42882015-04-29 14:00:55 -070056
David Garcia Quintasa301eaa2016-05-06 16:59:03 -070057 memset(ops, 0, sizeof(ops));
Craig Tillereeb42882015-04-29 14:00:55 -070058 op = ops;
59 op->op = GRPC_OP_SEND_INITIAL_METADATA;
60 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -070061 op->flags = 0;
Craig Tiller4ac2b8e2017-11-10 14:14:17 -080062 op->reserved = nullptr;
Craig Tillereeb42882015-04-29 14:00:55 -070063 op++;
64 op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
65 op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
66 op->data.recv_status_on_client.status = &status;
67 op->data.recv_status_on_client.status_details = &details;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -070068 op->flags = 0;
Craig Tiller4ac2b8e2017-11-10 14:14:17 -080069 op->reserved = nullptr;
Craig Tillereeb42882015-04-29 14:00:55 -070070 op++;
Craig Tillerbe98d242017-11-10 15:26:57 -080071 GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call, ops,
72 (size_t)(op - ops), tag(1),
73 nullptr));
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080074 /* verify that all tags get completed */
Mark D. Roth7187ab92016-08-24 13:49:22 -070075 CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080076 cq_verify(cqv);
77
Craig Tillereeb42882015-04-29 14:00:55 -070078 GPR_ASSERT(status == GRPC_STATUS_DEADLINE_EXCEEDED);
79
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080080 grpc_completion_queue_shutdown(cq);
Craig Tillerbe98d242017-11-10 15:26:57 -080081 while (grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME),
82 nullptr)
83 .type != GRPC_QUEUE_SHUTDOWN)
Craig Tiller64be9f72015-05-04 14:53:51 -070084 ;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080085 grpc_completion_queue_destroy(cq);
Craig Tillerdd36b152017-03-31 08:27:28 -070086 grpc_call_unref(call);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080087 grpc_channel_destroy(chan);
88 cq_verifier_destroy(cqv);
89
Craig Tiller7c70b6c2017-01-23 07:48:42 -080090 grpc_slice_unref(details);
Craig Tiller5fe7e5d2015-05-01 10:52:35 -070091 grpc_metadata_array_destroy(&trailing_metadata_recv);
92
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080093 grpc_shutdown();
94
95 return 0;
Craig Tiller190d3602015-02-18 09:23:38 -080096}