Add a test demonstrating forced closure of a stream, and make it work

pull/6080/head
Craig Tiller 9 years ago
parent 4a9a2b9634
commit c48ca71614
  1. 2
      src/core/ext/transport/chttp2/transport/chttp2_transport.c
  2. 11
      src/core/lib/surface/call.c
  3. 6
      test/core/end2end/tests/filter_causes_close.c

@ -1147,6 +1147,7 @@ static void cancel_from_api(grpc_exec_ctx *exec_ctx,
grpc_chttp2_transport_global *transport_global, grpc_chttp2_transport_global *transport_global,
grpc_chttp2_stream_global *stream_global, grpc_chttp2_stream_global *stream_global,
grpc_status_code status) { grpc_status_code status) {
if (!stream_global->read_closed || !stream_global->write_closed) {
if (stream_global->id != 0) { if (stream_global->id != 0) {
gpr_slice_buffer_add( gpr_slice_buffer_add(
&transport_global->qbuf, &transport_global->qbuf,
@ -1157,6 +1158,7 @@ static void cancel_from_api(grpc_exec_ctx *exec_ctx,
} }
grpc_chttp2_fake_status(exec_ctx, transport_global, stream_global, status, grpc_chttp2_fake_status(exec_ctx, transport_global, stream_global, status,
NULL); NULL);
}
grpc_chttp2_mark_stream_closed(exec_ctx, transport_global, stream_global, 1, grpc_chttp2_mark_stream_closed(exec_ctx, transport_global, stream_global, 1,
1); 1);
} }

@ -1074,10 +1074,12 @@ static void receiving_initial_metadata_ready(grpc_exec_ctx *exec_ctx,
gpr_mu_lock(&call->mu); gpr_mu_lock(&call->mu);
if (!success) {
bctl->success = false;
} else {
grpc_metadata_batch *md = grpc_metadata_batch *md =
&call->metadata_batch[1 /* is_receiving */][0 /* is_trailing */]; &call->metadata_batch[1 /* is_receiving */][0 /* is_trailing */];
grpc_metadata_batch_filter(md, recv_initial_filter, call); grpc_metadata_batch_filter(md, recv_initial_filter, call);
call->has_initial_md_been_received = true;
if (gpr_time_cmp(md->deadline, gpr_inf_future(md->deadline.clock_type)) != if (gpr_time_cmp(md->deadline, gpr_inf_future(md->deadline.clock_type)) !=
0 && 0 &&
@ -1086,12 +1088,15 @@ static void receiving_initial_metadata_ready(grpc_exec_ctx *exec_ctx,
set_deadline_alarm(exec_ctx, call, md->deadline); set_deadline_alarm(exec_ctx, call, md->deadline);
GPR_TIMER_END("set_deadline_alarm", 0); GPR_TIMER_END("set_deadline_alarm", 0);
} }
}
call->has_initial_md_been_received = true;
if (call->saved_receiving_stream_ready_ctx.bctlp != NULL) { if (call->saved_receiving_stream_ready_ctx.bctlp != NULL) {
grpc_closure *saved_rsr_closure = grpc_closure_create( grpc_closure *saved_rsr_closure = grpc_closure_create(
receiving_stream_ready, call->saved_receiving_stream_ready_ctx.bctlp); receiving_stream_ready, call->saved_receiving_stream_ready_ctx.bctlp);
grpc_exec_ctx_enqueue(exec_ctx, saved_rsr_closure, grpc_exec_ctx_enqueue(
call->saved_receiving_stream_ready_ctx.success, NULL); exec_ctx, saved_rsr_closure,
call->saved_receiving_stream_ready_ctx.success && success, NULL);
call->saved_receiving_stream_ready_ctx.bctlp = NULL; call->saved_receiving_stream_ready_ctx.bctlp = NULL;
} }

@ -110,7 +110,6 @@ static void test_request(grpc_end2end_test_config config) {
grpc_byte_buffer *request_payload = grpc_byte_buffer *request_payload =
grpc_raw_byte_buffer_create(&request_payload_slice, 1); grpc_raw_byte_buffer_create(&request_payload_slice, 1);
gpr_timespec deadline = five_seconds_time(); gpr_timespec deadline = five_seconds_time();
grpc_metadata meta;
grpc_end2end_test_fixture f = grpc_end2end_test_fixture f =
begin_test(config, "filter_causes_close", NULL, NULL); begin_test(config, "filter_causes_close", NULL, NULL);
cq_verifier *cqv = cq_verifier_create(f.cq); cq_verifier *cqv = cq_verifier_create(f.cq);
@ -177,8 +176,6 @@ static void test_request(grpc_end2end_test_config config) {
GPR_ASSERT(status == GRPC_STATUS_PERMISSION_DENIED); GPR_ASSERT(status == GRPC_STATUS_PERMISSION_DENIED);
GPR_ASSERT(0 == strcmp(details, "Random failure that's not preventable.")); GPR_ASSERT(0 == strcmp(details, "Random failure that's not preventable."));
GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world"));
GPR_ASSERT(contains_metadata(&request_metadata_recv, "key", meta.value));
gpr_free(details); gpr_free(details);
grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&initial_metadata_recv);
@ -187,15 +184,12 @@ static void test_request(grpc_end2end_test_config config) {
grpc_call_details_destroy(&call_details); grpc_call_details_destroy(&call_details);
grpc_call_destroy(c); grpc_call_destroy(c);
grpc_call_destroy(s);
cq_verifier_destroy(cqv); cq_verifier_destroy(cqv);
grpc_byte_buffer_destroy(request_payload); grpc_byte_buffer_destroy(request_payload);
grpc_byte_buffer_destroy(request_payload_recv); grpc_byte_buffer_destroy(request_payload_recv);
gpr_free((char *)meta.value);
end_test(&f); end_test(&f);
config.tear_down_data(&f); config.tear_down_data(&f);
} }

Loading…
Cancel
Save