]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
test case 10832/head
authorph1 <ph1@slurpee2.phoned.ca>
Tue, 12 Oct 2021 15:29:34 +0000 (09:29 -0600)
committerph1 <ph1@slurpee2.phoned.ca>
Tue, 12 Oct 2021 15:29:34 +0000 (09:29 -0600)
pdns/dnsdistdist/test-dnsdistrules_cc.cc

index 70ccbd0020e5c0faaf80a5dce958df2671a4712a..aed5ee4b53dd02a3f18be072b8a51536207975b7 100644 (file)
@@ -7,6 +7,23 @@
 
 #include "dnsdist-rules.hh"
 
+static DNSQuestion getDQ(const DNSName* providedName = nullptr)
+{
+  static const DNSName qname("powerdns.com.");
+  static const ComboAddress lc("127.0.0.1:53");
+  static const ComboAddress rem("192.0.2.1:42");
+  static struct timespec queryRealTime;
+  static PacketBuffer packet(sizeof(dnsheader));
+
+  uint16_t qtype = QType::A;
+  uint16_t qclass = QClass::IN;
+  auto proto = dnsdist::Protocol::DoUDP;
+  gettime(&queryRealTime, true);
+
+  DNSQuestion dq(providedName ? providedName : &qname, qtype, qclass, &lc, &rem, packet, proto, &queryRealTime);
+  return dq;
+}
+
 BOOST_AUTO_TEST_SUITE(dnsdistluarules_cc)
 
 BOOST_AUTO_TEST_CASE(test_MaxQPSIPRule) {
@@ -101,5 +118,32 @@ BOOST_AUTO_TEST_CASE(test_MaxQPSIPRule) {
   BOOST_CHECK_EQUAL(scanned, 0U);
 }
 
+BOOST_AUTO_TEST_CASE(test_poolOutstandingRule) {
+  auto dq = getDQ();
+
+  ServerPool sp{};
+  auto ds1 = std::make_shared<DownstreamState>(ComboAddress("192.0.2.1:53"));
+  auto ds2 = std::make_shared<DownstreamState>(ComboAddress("192.0.2.2:53"));
+
+  /* increase the outstanding count of both */
+  ds1->outstanding = 400;
+  ds2->outstanding = 30;
+
+  sp.addServer(ds1);
+  sp.addServer(ds2);
+
+  BOOST_CHECK_EQUAL(sp.poolLoad(), 400+30);
+
+  auto localPool = g_pools.getCopy();
+  addServerToPool(localPool, "test", ds1);
+  addServerToPool(localPool, "test", ds2);
+  g_pools.setState(localPool);
+
+  PoolOutstandingRule pOR1("test", 10);
+  BOOST_CHECK_EQUAL(pOR1.matches(&dq), true);
+
+  PoolOutstandingRule pOR2("test", 1000);
+  BOOST_CHECK_EQUAL(pOR2.matches(&dq), false);
+}
 
 BOOST_AUTO_TEST_SUITE_END()