test: add test case for performance

This commit is contained in:
Nick Peng
2023-03-19 14:26:46 +08:00
parent 455dca9ae4
commit aa6f6fd519
10 changed files with 307 additions and 55 deletions

View File

@@ -1,3 +1,21 @@
/*************************************************************************
*
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* smartdns is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "client.h"
#include "dns.h"
#include "include/utils.h"
@@ -6,20 +24,20 @@
TEST(DiscardBlockIP, first_ping)
{
smartdns::MockServer server_upstream1;
smartdns::MockServer server_upstream1;
smartdns::MockServer server_upstream2;
smartdns::Server server;
server_upstream1.Start("udp://0.0.0.0:61053", [](struct smartdns::ServerRequestContext *request) {
unsigned char addr[4] = {0, 0, 0, 0};
unsigned char addr[4] = {0, 0, 0, 0};
dns_add_A(request->response_packet, DNS_RRS_AN, request->domain.c_str(), 611, addr);
request->response_packet->head.rcode = DNS_RC_NOERROR;
return smartdns::SERVER_REQUEST_OK;
});
server_upstream2.Start("udp://0.0.0.0:62053", [](struct smartdns::ServerRequestContext *request) {
unsigned char addr[4] = {1, 2, 3, 4};
usleep(20000);
server_upstream2.Start("udp://0.0.0.0:62053", [](struct smartdns::ServerRequestContext *request) {
unsigned char addr[4] = {1, 2, 3, 4};
usleep(20000);
dns_add_A(request->response_packet, DNS_RRS_AN, request->domain.c_str(), 611, addr);
request->response_packet->head.rcode = DNS_RC_NOERROR;
return smartdns::SERVER_REQUEST_OK;
@@ -37,26 +55,26 @@ cache-persist no)""");
std::cout << client.GetResult() << std::endl;
ASSERT_EQ(client.GetAnswerNum(), 1);
EXPECT_EQ(client.GetStatus(), "NOERROR");
EXPECT_EQ(client.GetAnswer()[0].GetTTL(), 600);
EXPECT_EQ(client.GetAnswer()[0].GetTTL(), 600);
EXPECT_EQ(client.GetAnswer()[0].GetData(), "1.2.3.4");
}
TEST(DiscardBlockIP, first_response)
{
smartdns::MockServer server_upstream1;
smartdns::MockServer server_upstream1;
smartdns::MockServer server_upstream2;
smartdns::Server server;
server_upstream1.Start("udp://0.0.0.0:61053", [](struct smartdns::ServerRequestContext *request) {
unsigned char addr[4] = {0, 0, 0, 0};
unsigned char addr[4] = {0, 0, 0, 0};
dns_add_A(request->response_packet, DNS_RRS_AN, request->domain.c_str(), 611, addr);
request->response_packet->head.rcode = DNS_RC_NOERROR;
return smartdns::SERVER_REQUEST_OK;
});
server_upstream2.Start("udp://0.0.0.0:62053", [](struct smartdns::ServerRequestContext *request) {
unsigned char addr[4] = {1, 2, 3, 4};
usleep(20000);
server_upstream2.Start("udp://0.0.0.0:62053", [](struct smartdns::ServerRequestContext *request) {
unsigned char addr[4] = {1, 2, 3, 4};
usleep(20000);
dns_add_A(request->response_packet, DNS_RRS_AN, request->domain.c_str(), 611, addr);
request->response_packet->head.rcode = DNS_RC_NOERROR;
return smartdns::SERVER_REQUEST_OK;
@@ -75,6 +93,6 @@ cache-persist no)""");
std::cout << client.GetResult() << std::endl;
ASSERT_EQ(client.GetAnswerNum(), 1);
EXPECT_EQ(client.GetStatus(), "NOERROR");
EXPECT_EQ(client.GetAnswer()[0].GetTTL(), 3);
EXPECT_EQ(client.GetAnswer()[0].GetTTL(), 3);
EXPECT_EQ(client.GetAnswer()[0].GetData(), "1.2.3.4");
}