diff --git a/src/server/test/hotkey_collector_test.cpp b/src/server/test/hotkey_collector_test.cpp index 99913a45fe..781a5a51de 100644 --- a/src/server/test/hotkey_collector_test.cpp +++ b/src/server/test/hotkey_collector_test.cpp @@ -350,19 +350,14 @@ TEST_F(hotkey_collector_test, data_completeness) resp); ASSERT_EQ(resp.err, dsn::ERR_OK); - auto writes = new dsn::message_ex *[1000]; - auto cleanup = dsn::defer([=]() { - for (int i = 0; i < 1000; i++) { - writes[i]->release_ref(); - } - delete[] writes; - }); - for (int i = 0; i < 1000; i++) { + const uint16_t WRITE_REQUEST_COUNT = 1000; + dsn::message_ex *writes[WRITE_REQUEST_COUNT]; + for (int i = 0; i < WRITE_REQUEST_COUNT; i++) { writes[i] = create_put_request(generate_set_req(std::to_string(i))); } - _server->on_batched_write_requests(int64_t(0), uint64_t(0), writes, 1000); + _server->on_batched_write_requests(int64_t(0), uint64_t(0), writes, WRITE_REQUEST_COUNT); - for (int i = 0; i < 1000; i++) { + for (int i = 0; i < WRITE_REQUEST_COUNT; i++) { auto rpc = generate_get_rpc(std::to_string(i)); _server->on_get(rpc); auto value = rpc.response().value.to_string(); diff --git a/src/server/test/pegasus_server_write_test.cpp b/src/server/test/pegasus_server_write_test.cpp index 7506abd42e..44c42a0ac8 100644 --- a/src/server/test/pegasus_server_write_test.cpp +++ b/src/server/test/pegasus_server_write_test.cpp @@ -60,19 +60,18 @@ class pegasus_server_write_test : public pegasus_server_test_base int put_rpc_cnt = dsn::rand::next_u32(1, 10); int remove_rpc_cnt = dsn::rand::next_u32(1, 10); int total_rpc_cnt = put_rpc_cnt + remove_rpc_cnt; - auto writes = new dsn::message_ex *[total_rpc_cnt]; + /** + * writes[0] ~ writes[total_rpc_cnt-1] will be released by their corresponding + * rpc_holders, which created in on_batched_write_requests. So we don't need to + * release them here + **/ + dsn::message_ex *writes[total_rpc_cnt]; for (int i = 0; i < put_rpc_cnt; i++) { writes[i] = pegasus::create_put_request(req); } for (int i = put_rpc_cnt; i < total_rpc_cnt; i++) { writes[i] = pegasus::create_remove_request(key); } - auto cleanup = dsn::defer([=]() { - for (int i = 0; i < total_rpc_cnt; i++) { - writes[i]->release_ref(); - } - delete[] writes; - }); int err = _server_write->on_batched_write_requests(writes, total_rpc_cnt, decree, 0);