From 8e0fcd3922eece2cddc8c1d880aed33ff5f9a9b4 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 18 Jun 2014 12:08:12 +0900 Subject: [PATCH] Add test for graceful shutdown use case --- tests/main.c | 2 ++ tests/nghttp2_session_test.c | 38 ++++++++++++++++++++++++++++++++++++ tests/nghttp2_session_test.h | 1 + 3 files changed, 41 insertions(+) diff --git a/tests/main.c b/tests/main.c index 5c168ad2..659d19b9 100644 --- a/tests/main.c +++ b/tests/main.c @@ -227,6 +227,8 @@ int main(int argc, char* argv[]) test_nghttp2_session_stream_attach_data_subtree) || !CU_add_test(pSuite, "session_stream_keep_closed_stream", test_nghttp2_session_keep_closed_stream) || + !CU_add_test(pSuite, "session_graceful_shutdown", + test_nghttp2_session_graceful_shutdown) || !CU_add_test(pSuite, "frame_pack_headers", test_nghttp2_frame_pack_headers) || !CU_add_test(pSuite, "frame_pack_headers_frame_too_large", diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index 2609abe0..29f0b652 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -5791,3 +5791,41 @@ void test_nghttp2_session_keep_closed_stream(void) nghttp2_session_del(session); } + +void test_nghttp2_session_graceful_shutdown(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + my_user_data ud; + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.send_callback = block_count_send_callback; + callbacks.on_frame_send_callback = on_frame_send_callback; + + nghttp2_session_server_new(&session, &callbacks, &ud); + + CU_ASSERT(0 == nghttp2_submit_goaway(session, NGHTTP2_FLAG_NONE, + (1u << 31) - 1, NGHTTP2_NO_ERROR, + NULL, 0)); + + ud.block_count = 1; + ud.frame_send_cb_called = 0; + + CU_ASSERT(0 == nghttp2_session_send(session)); + + CU_ASSERT(1 == ud.frame_send_cb_called); + CU_ASSERT((1u << 31) - 1 == session->local_last_stream_id); + + CU_ASSERT(0 == nghttp2_session_terminate_session2(session, 300, + NGHTTP2_NO_ERROR)); + + ud.block_count = 1; + ud.frame_send_cb_called = 0; + + CU_ASSERT(0 == nghttp2_session_send(session)); + + CU_ASSERT(1 == ud.frame_send_cb_called); + CU_ASSERT(300 == session->local_last_stream_id); + + nghttp2_session_del(session); +} diff --git a/tests/nghttp2_session_test.h b/tests/nghttp2_session_test.h index 03834cd0..c6e7f440 100644 --- a/tests/nghttp2_session_test.h +++ b/tests/nghttp2_session_test.h @@ -106,5 +106,6 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void); void test_nghttp2_session_stream_attach_data(void); void test_nghttp2_session_stream_attach_data_subtree(void); void test_nghttp2_session_keep_closed_stream(void); +void test_nghttp2_session_graceful_shutdown(void); #endif /* NGHTTP2_SESSION_TEST_H */