Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 5 | * 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 Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 11 | * 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 Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 19 | #include <string.h> |
| 20 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 21 | #include <grpc/grpc.h> |
Craig Tiller | 5fe7e5d | 2015-05-01 10:52:35 -0700 | [diff] [blame] | 22 | #include <grpc/support/alloc.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 23 | #include <grpc/support/log.h> |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 24 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 25 | #include "test/core/end2end/cq_verifier.h" |
| 26 | #include "test/core/util/test_config.h" |
| 27 | |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 28 | static void* tag(intptr_t i) { return (void*)i; } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 29 | |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 30 | int main(int argc, char** argv) { |
| 31 | grpc_channel* chan; |
| 32 | grpc_call* call; |
Robbie Shade | ca7effc | 2017-01-17 09:14:29 -0500 | [diff] [blame] | 33 | gpr_timespec deadline = grpc_timeout_seconds_to_deadline(2); |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 34 | grpc_completion_queue* cq; |
| 35 | cq_verifier* cqv; |
Craig Tiller | eeb4288 | 2015-04-29 14:00:55 -0700 | [diff] [blame] | 36 | grpc_op ops[6]; |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 37 | grpc_op* op; |
Craig Tiller | eeb4288 | 2015-04-29 14:00:55 -0700 | [diff] [blame] | 38 | grpc_metadata_array trailing_metadata_recv; |
| 39 | grpc_status_code status; |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 40 | grpc_slice details; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 41 | |
| 42 | grpc_test_init(argc, argv); |
| 43 | grpc_init(); |
| 44 | |
Craig Tiller | eeb4288 | 2015-04-29 14:00:55 -0700 | [diff] [blame] | 45 | grpc_metadata_array_init(&trailing_metadata_recv); |
| 46 | |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 47 | cq = grpc_completion_queue_create_for_next(nullptr); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 48 | cqv = cq_verifier_create(cq); |
| 49 | |
| 50 | /* create a call, channel to a non existant server */ |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 51 | chan = grpc_insecure_channel_create("nonexistant:54321", nullptr, nullptr); |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 52 | grpc_slice host = grpc_slice_from_static_string("nonexistant"); |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 53 | call = grpc_channel_create_call(chan, nullptr, GRPC_PROPAGATE_DEFAULTS, cq, |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 54 | grpc_slice_from_static_string("/Foo"), &host, |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 55 | deadline, nullptr); |
Craig Tiller | eeb4288 | 2015-04-29 14:00:55 -0700 | [diff] [blame] | 56 | |
David Garcia Quintas | a301eaa | 2016-05-06 16:59:03 -0700 | [diff] [blame] | 57 | memset(ops, 0, sizeof(ops)); |
Craig Tiller | eeb4288 | 2015-04-29 14:00:55 -0700 | [diff] [blame] | 58 | op = ops; |
| 59 | op->op = GRPC_OP_SEND_INITIAL_METADATA; |
| 60 | op->data.send_initial_metadata.count = 0; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 61 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 62 | op->reserved = nullptr; |
Craig Tiller | eeb4288 | 2015-04-29 14:00:55 -0700 | [diff] [blame] | 63 | 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 Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 68 | op->flags = 0; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 69 | op->reserved = nullptr; |
Craig Tiller | eeb4288 | 2015-04-29 14:00:55 -0700 | [diff] [blame] | 70 | op++; |
Craig Tiller | be98d24 | 2017-11-10 15:26:57 -0800 | [diff] [blame] | 71 | GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call, ops, |
| 72 | (size_t)(op - ops), tag(1), |
| 73 | nullptr)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 74 | /* verify that all tags get completed */ |
Mark D. Roth | 7187ab9 | 2016-08-24 13:49:22 -0700 | [diff] [blame] | 75 | CQ_EXPECT_COMPLETION(cqv, tag(1), 1); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 76 | cq_verify(cqv); |
| 77 | |
Craig Tiller | eeb4288 | 2015-04-29 14:00:55 -0700 | [diff] [blame] | 78 | GPR_ASSERT(status == GRPC_STATUS_DEADLINE_EXCEEDED); |
| 79 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 80 | grpc_completion_queue_shutdown(cq); |
Craig Tiller | be98d24 | 2017-11-10 15:26:57 -0800 | [diff] [blame] | 81 | while (grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), |
| 82 | nullptr) |
| 83 | .type != GRPC_QUEUE_SHUTDOWN) |
Craig Tiller | 64be9f7 | 2015-05-04 14:53:51 -0700 | [diff] [blame] | 84 | ; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 85 | grpc_completion_queue_destroy(cq); |
Craig Tiller | dd36b15 | 2017-03-31 08:27:28 -0700 | [diff] [blame] | 86 | grpc_call_unref(call); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 87 | grpc_channel_destroy(chan); |
| 88 | cq_verifier_destroy(cqv); |
| 89 | |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 90 | grpc_slice_unref(details); |
Craig Tiller | 5fe7e5d | 2015-05-01 10:52:35 -0700 | [diff] [blame] | 91 | grpc_metadata_array_destroy(&trailing_metadata_recv); |
| 92 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 93 | grpc_shutdown(); |
| 94 | |
| 95 | return 0; |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 96 | } |