diff --git a/test/core/end2end/tests/filter_call_init_fails.c b/test/core/end2end/tests/filter_call_init_fails.c index a1699e86c9f..1be6b8bdeaa 100644 --- a/test/core/end2end/tests/filter_call_init_fails.c +++ b/test/core/end2end/tests/filter_call_init_fails.c @@ -33,6 +33,7 @@ #include "test/core/end2end/end2end_tests.h" +#include #include #include #include @@ -238,15 +239,22 @@ static const grpc_channel_filter test_filter = { static bool maybe_add_filter(grpc_channel_stack_builder *builder, void *arg) { if (g_enable_filter) { - return grpc_channel_stack_builder_append_filter(builder, &test_filter, - NULL, NULL); + // Want to add the filter as close to the end as possible, to make + // sure that all of the filters work well together. However, we + // can't add it at the very end, because the connected channel filter + // must be the last one. So we add it right before the last one. + grpc_channel_stack_builder_iterator *it = + grpc_channel_stack_builder_create_iterator_at_last(builder); + GPR_ASSERT(grpc_channel_stack_builder_move_prev(it)); + return grpc_channel_stack_builder_add_filter_before(it, &test_filter, + NULL, NULL); } else { return true; } } static void init_plugin(void) { - grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, MAX_INT, + grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX, maybe_add_filter, NULL); }