Line data Source code
1 : /*
2 : *
3 : * Copyright 2015, 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/grpc.h>
35 : #include <grpc/support/alloc.h>
36 : #include <grpc/support/log.h>
37 : #include "test/core/end2end/cq_verifier.h"
38 : #include "test/core/util/test_config.h"
39 :
40 2 : static void *tag(gpr_intptr i) { return (void *)i; }
41 :
42 1 : int main(int argc, char **argv) {
43 : grpc_channel *chan;
44 : grpc_call *call;
45 1 : gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(2);
46 : grpc_completion_queue *cq;
47 : cq_verifier *cqv;
48 : grpc_op ops[6];
49 : grpc_op *op;
50 : grpc_metadata_array trailing_metadata_recv;
51 : grpc_status_code status;
52 1 : char *details = NULL;
53 1 : size_t details_capacity = 0;
54 :
55 1 : grpc_test_init(argc, argv);
56 1 : grpc_init();
57 :
58 1 : grpc_metadata_array_init(&trailing_metadata_recv);
59 :
60 1 : cq = grpc_completion_queue_create(NULL);
61 1 : cqv = cq_verifier_create(cq);
62 :
63 : /* create a call, channel to a non existant server */
64 1 : chan = grpc_insecure_channel_create("nonexistant:54321", NULL, NULL);
65 1 : call = grpc_channel_create_call(chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq,
66 : "/Foo", "nonexistant", deadline, NULL);
67 :
68 1 : op = ops;
69 1 : op->op = GRPC_OP_SEND_INITIAL_METADATA;
70 1 : op->data.send_initial_metadata.count = 0;
71 1 : op->flags = 0;
72 1 : op->reserved = NULL;
73 1 : op++;
74 1 : op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
75 1 : op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
76 1 : op->data.recv_status_on_client.status = &status;
77 1 : op->data.recv_status_on_client.status_details = &details;
78 1 : op->data.recv_status_on_client.status_details_capacity = &details_capacity;
79 1 : op->flags = 0;
80 1 : op->reserved = NULL;
81 1 : op++;
82 1 : GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(
83 : call, ops, (size_t)(op - ops), tag(1), NULL));
84 : /* verify that all tags get completed */
85 1 : cq_expect_completion(cqv, tag(1), 1);
86 1 : cq_verify(cqv);
87 :
88 1 : GPR_ASSERT(status == GRPC_STATUS_DEADLINE_EXCEEDED);
89 :
90 1 : grpc_completion_queue_shutdown(cq);
91 2 : while (grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME),
92 1 : NULL).type != GRPC_QUEUE_SHUTDOWN)
93 : ;
94 1 : grpc_completion_queue_destroy(cq);
95 1 : grpc_call_destroy(call);
96 1 : grpc_channel_destroy(chan);
97 1 : cq_verifier_destroy(cqv);
98 :
99 1 : gpr_free(details);
100 1 : grpc_metadata_array_destroy(&trailing_metadata_recv);
101 :
102 1 : grpc_shutdown();
103 :
104 1 : return 0;
105 : }
|