• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PowerDNS / pdns / 12595591960

03 Jan 2025 09:27AM UTC coverage: 62.774% (+2.5%) from 60.245%
12595591960

Pull #15008

github

web-flow
Merge c2a2749d3 into 788f396a7
Pull Request #15008: Do not follow CNAME records for ANY or CNAME queries

30393 of 78644 branches covered (38.65%)

Branch coverage included in aggregate %.

105822 of 138350 relevant lines covered (76.49%)

4613078.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.77
/pdns/recursordist/test-rec-tcounters_cc.cc
1
#ifndef BOOST_TEST_DYN_LINK
2
#define BOOST_TEST_DYN_LINK
3
#endif
4

5
#define BOOST_TEST_NO_MAIN
6

7
#ifdef HAVE_CONFIG_H
8
#include "config.h"
9
#endif
10

11
#include <boost/test/unit_test.hpp>
12

13
#include <unistd.h>
14
#include <thread>
15
#include "dns_random.hh"
16
#include "rec-tcounters.hh"
17

18
static rec::GlobalCounters global;
19
static thread_local rec::TCounters tlocal(global);
20

21
BOOST_AUTO_TEST_SUITE(test_rec_tcounters_cc)
22

23
BOOST_AUTO_TEST_CASE(destruct)
24
{
2✔
25
  global.reset();
2✔
26

27
  const size_t count = 100000;
2✔
28
  std::thread thread1([] {
2✔
29
    for (size_t i = 0; i < count; i++) {
200,002✔
30
      ++tlocal.at(rec::Counter::servFails);
200,000✔
31
    }
200,000✔
32
  });
2✔
33
  std::thread thread2([] {
2✔
34
    for (size_t i = 0; i < count; i++) {
200,002✔
35
      ++tlocal.at(rec::Counter::nxDomains);
200,000✔
36
    }
200,000✔
37
  });
2✔
38
  thread1.join();
2✔
39
  thread2.join();
2✔
40
  BOOST_CHECK_EQUAL(global.sum(rec::Counter::servFails), count);
2✔
41
  BOOST_CHECK_EQUAL(global.sum(rec::Counter::nxDomains), count);
2✔
42
}
2✔
43

44
BOOST_AUTO_TEST_CASE(update_fast)
45
{
2✔
46
  global.reset();
2✔
47

48
  std::atomic<uint64_t> done{};
2✔
49

50
  const size_t count = 10000000;
2✔
51
  std::thread thread1([&done] {
2✔
52
    for (size_t i = 0; i < count; i++) {
20,000,002✔
53
      ++tlocal.at(rec::Counter::servFails);
20,000,000✔
54
      ++tlocal.at(rec::Counter::nxDomains);
20,000,000✔
55
      tlocal.at(rec::DoubleWAvgCounter::avgLatencyUsec).add(1.1);
20,000,000✔
56
      if (dns_random(10000) == 0) {
20,000,000✔
57
        tlocal.updateSnap();
2,019✔
58
      }
2,019✔
59
    }
20,000,000✔
60
    done++;
2✔
61
  });
2✔
62
  std::thread thread2([&done] {
2✔
63
    for (size_t i = 0; i < count / 2; i++) {
10,000,002✔
64
      ++tlocal.at(rec::Counter::servFails);
10,000,000✔
65
      ++tlocal.at(rec::Counter::nxDomains);
10,000,000✔
66
      tlocal.at(rec::DoubleWAvgCounter::avgLatencyUsec).add(2.2);
10,000,000✔
67
      if (dns_random(10000) == 0) {
10,000,000✔
68
        tlocal.updateSnap();
1,021✔
69
      }
1,021✔
70
    }
10,000,000✔
71
    done++;
2✔
72
  });
2✔
73
  std::thread thread3([&done] {
2✔
74
    while (done < 2) {
40,631✔
75
      auto counts = global.aggregatedSnap();
40,629✔
76
      BOOST_CHECK_EQUAL(counts.uint64Count[0], counts.uint64Count[1]);
40,629✔
77
      auto avg = counts.at(rec::DoubleWAvgCounter::avgLatencyUsec).avg;
40,629✔
78
      BOOST_CHECK(avg == 0.0 || (avg >= 1.1 && avg <= 2.2));
40,629✔
79
      std::this_thread::yield(); // needed, as otherwise the updates to done might not be spotted under valgrind
40,629✔
80
    }
40,629✔
81
  });
2✔
82
  thread1.join();
2✔
83
  thread2.join();
2✔
84
  thread3.join();
2✔
85
  BOOST_CHECK_EQUAL(global.sum(rec::Counter::servFails), count + count / 2);
2✔
86
  BOOST_CHECK_EQUAL(global.sum(rec::Counter::nxDomains), count + count / 2);
2✔
87
  auto avg = global.avg(rec::DoubleWAvgCounter::avgLatencyUsec);
2✔
88
  BOOST_CHECK(avg >= 1.1 && avg <= 2.2);
2✔
89
}
2✔
90

91
BOOST_AUTO_TEST_CASE(update_with_sleep)
92
{
2✔
93

94
  global.reset();
2✔
95

96
  std::atomic<int> done{};
2✔
97

98
  const size_t count = 100;
2✔
99
  std::thread thread1([&done] {
2✔
100
    for (size_t i = 0; i < count; i++) {
202✔
101
      ++tlocal.at(rec::Counter::servFails);
200✔
102
      ++tlocal.at(rec::Counter::nxDomains);
200✔
103
      tlocal.at(rec::DoubleWAvgCounter::avgLatencyUsec).add(1.1);
200✔
104
      if (dns_random(10000) == 0) {
200!
105
        tlocal.updateSnap();
×
106
      }
×
107
      struct timespec interval
200✔
108
      {
200✔
109
        0, dns_random(20 * 1000 * 1000)
200✔
110
      };
200✔
111
      nanosleep(&interval, nullptr);
200✔
112
    }
200✔
113
    done++;
2✔
114
  });
2✔
115
  std::thread thread2([&done] {
2✔
116
    for (size_t i = 0; i < count / 2; i++) {
102✔
117
      ++tlocal.at(rec::Counter::servFails);
100✔
118
      ++tlocal.at(rec::Counter::nxDomains);
100✔
119
      tlocal.at(rec::DoubleWAvgCounter::avgLatencyUsec).add(2.2);
100✔
120
      if (dns_random(10000) == 0) {
100!
121
        tlocal.updateSnap();
×
122
      }
×
123
      struct timespec interval
100✔
124
      {
100✔
125
        0, dns_random(40 * 1000 * 1000)
100✔
126
      };
100✔
127
      nanosleep(&interval, nullptr);
100✔
128
    }
100✔
129
    done++;
2✔
130
  });
2✔
131
  std::thread thread3([&done] {
2✔
132
    while (done < 2) {
57✔
133
      auto counts = global.aggregatedSnap();
55✔
134
      BOOST_CHECK_EQUAL(counts.uint64Count[0], counts.uint64Count[1]);
55✔
135
      auto avg = counts.at(rec::DoubleWAvgCounter::avgLatencyUsec).avg;
55✔
136
      // std::cerr << avg << std::endl;
137
      BOOST_CHECK(avg == 0.0 || (avg >= 1.1 && avg <= 2.2));
55✔
138
      struct timespec interval
55✔
139
      {
55✔
140
        0, dns_random(80 * 1000 * 1000)
55✔
141
      };
55✔
142
      nanosleep(&interval, nullptr);
55✔
143
    }
55✔
144
  });
2✔
145
  thread1.join();
2✔
146
  thread2.join();
2✔
147
  thread3.join();
2✔
148
  BOOST_CHECK_EQUAL(global.sum(rec::Counter::servFails), count + count / 2);
2✔
149
  BOOST_CHECK_EQUAL(global.sum(rec::Counter::nxDomains), count + count / 2);
2✔
150
  auto avg = global.avg(rec::DoubleWAvgCounter::avgLatencyUsec);
2✔
151
  BOOST_CHECK(avg >= 1.1 && avg <= 2.2);
2✔
152
}
2✔
153

154
BOOST_AUTO_TEST_SUITE_END()
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc