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

PowerDNS / pdns / 18709198868

22 Oct 2025 07:49AM UTC coverage: 73.016% (+0.01%) from 73.006%
18709198868

Pull #16338

github

web-flow
Merge 53c598698 into 8eda540cb
Pull Request #16338: rec: tighten delegation accept

38301 of 63162 branches covered (60.64%)

Branch coverage included in aggregate %.

30 of 35 new or added lines in 2 files covered. (85.71%)

31 existing lines in 8 files now uncovered.

127486 of 163895 relevant lines covered (77.79%)

6129150.01 hits per line

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

95.59
/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();
1,969✔
58
      }
1,969✔
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();
990✔
69
      }
990✔
70
    }
10,000,000✔
71
    done++;
2✔
72
  });
2✔
73
  std::thread thread3([&done] {
2✔
74
    while (done < 2) {
33,701✔
75
      auto counts = global.aggregatedSnap();
33,699✔
76
      BOOST_CHECK_EQUAL(counts.uint64Count[0], counts.uint64Count[1]);
33,699✔
77
      auto avg = counts.at(rec::DoubleWAvgCounter::avgLatencyUsec).avg;
33,699✔
78
      BOOST_CHECK(avg == 0.0 || (avg >= 1.1 && avg <= 2.2));
33,699✔
79
      std::this_thread::yield(); // needed, as otherwise the updates to done might not be spotted under valgrind
33,699✔
80
    }
33,699✔
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!
UNCOV
105
        tlocal.updateSnap();
×
UNCOV
106
      }
×
107
      struct timespec interval{
200✔
108
        0, dns_random(20 * 1000 * 1000)};
200✔
109
      nanosleep(&interval, nullptr);
200✔
110
    }
200✔
111
    done++;
2✔
112
  });
2✔
113
  std::thread thread2([&done] {
2✔
114
    for (size_t i = 0; i < count / 2; i++) {
102✔
115
      ++tlocal.at(rec::Counter::servFails);
100✔
116
      ++tlocal.at(rec::Counter::nxDomains);
100✔
117
      tlocal.at(rec::DoubleWAvgCounter::avgLatencyUsec).add(2.2);
100✔
118
      if (dns_random(10000) == 0) {
100!
119
        tlocal.updateSnap();
×
120
      }
×
121
      struct timespec interval{
100✔
122
        0, dns_random(40 * 1000 * 1000)};
100✔
123
      nanosleep(&interval, nullptr);
100✔
124
    }
100✔
125
    done++;
2✔
126
  });
2✔
127
  std::thread thread3([&done] {
2✔
128
    while (done < 2) {
51✔
129
      auto counts = global.aggregatedSnap();
49✔
130
      BOOST_CHECK_EQUAL(counts.uint64Count[0], counts.uint64Count[1]);
49✔
131
      auto avg = counts.at(rec::DoubleWAvgCounter::avgLatencyUsec).avg;
49✔
132
      // std::cerr << avg << std::endl;
133
      BOOST_CHECK(avg == 0.0 || (avg >= 1.1 && avg <= 2.2));
49✔
134
      struct timespec interval{
49✔
135
        0, dns_random(80 * 1000 * 1000)};
49✔
136
      nanosleep(&interval, nullptr);
49✔
137
    }
49✔
138
  });
2✔
139
  thread1.join();
2✔
140
  thread2.join();
2✔
141
  thread3.join();
2✔
142
  BOOST_CHECK_EQUAL(global.sum(rec::Counter::servFails), count + count / 2);
2✔
143
  BOOST_CHECK_EQUAL(global.sum(rec::Counter::nxDomains), count + count / 2);
2✔
144
  auto avg = global.avg(rec::DoubleWAvgCounter::avgLatencyUsec);
2✔
145
  BOOST_CHECK(avg >= 1.1 && avg <= 2.2);
2✔
146
}
2✔
147

148
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