Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vvromanov committed Dec 8, 2024
1 parent 2605a19 commit a0cb197
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 20 deletions.
4 changes: 0 additions & 4 deletions rrd-writer/rrd_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ static bool rrd_update_history_counter(HistoryCounters::name_rec_t &counter) {
return false;
}
break;
case HistoryUnknown:
return true;
}
}
char update[256];
Expand All @@ -263,8 +261,6 @@ static bool rrd_update_history_counter(HistoryCounters::name_rec_t &counter) {
case HistoryCall: //Учитываем количество и среднее время вызова
snprintf(update, sizeof(update), "%lu:%ld:%ld", time(NULL), d->GetLastCount(), d->GetLastAvg());
break;
case HistoryUnknown:
return true;
}
return rrd_update(filename, update);
}
Expand Down
10 changes: 0 additions & 10 deletions src/HistoryCounterData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ void HistoryCounterData::DumpSimple(std::ostream &s) {
s << ' ' << GetTotalCount();
s << ' ' << GetTotalAvg();
break;
case HistoryUnknown:
s << '?';
}
}

Expand Down Expand Up @@ -132,8 +130,6 @@ void HistoryCounterData::DumpTable(std::ostream &s) {
s << '|';
DumpNumber(s, GetTotalAvg(), 6);
break;
case HistoryUnknown:
break;
}
s << "|" << std::endl;
}
Expand All @@ -152,8 +148,6 @@ void HistoryCounterData::DumpHtml(std::ostream &s) {
case HistoryCall:
DumpNumber(s, GetLastAvg(), 6);
break;
case HistoryUnknown:
break;
}
s << "</td><td align='right'>";
DumpNumber(s, GetIntervalCount(), 6);
Expand All @@ -168,8 +162,6 @@ void HistoryCounterData::DumpHtml(std::ostream &s) {
case HistoryCall:
DumpNumber(s, GetIntervalAvg(), 6);
break;
case HistoryUnknown:
break;
}

s << "</td><td align='right'>";
Expand All @@ -185,8 +177,6 @@ void HistoryCounterData::DumpHtml(std::ostream &s) {
case HistoryCall:
DumpNumber(s, GetTotalAvg(), 6);
break;
case HistoryUnknown:
break;
}
s << "</td></tr>" << std::endl;
}
1 change: 0 additions & 1 deletion src/HistoryCounterData.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ struct HistoryRec {
} __attribute__((__packed__));

typedef enum {
HistoryUnknown,
HistoryCount, //Просто какое-то событие
HistoryVolume, //Учитываем количество и объем. Например, сколько данных передано по сети
HistoryCall //Учитываем количество и среднее время вызова
Expand Down
3 changes: 0 additions & 3 deletions src/HistoryCounters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ void HistoryCounters::Dump(std::ostream &s, const char *prefix, counters_format_
s << '=' << c->GetLastCount();
switch (c->GetType()) {
case HistoryCount:
case HistoryUnknown:
break;
case HistoryVolume:
s << ' ' << name;
Expand All @@ -94,7 +93,6 @@ void HistoryCounters::Dump(std::ostream &s, const char *prefix, counters_format_
s << '=' << c->GetTotalCount();
switch (c->GetType()) {
case HistoryCount:
case HistoryUnknown:
break;
case HistoryVolume:
s << ' ' << name;
Expand All @@ -111,7 +109,6 @@ void HistoryCounters::Dump(std::ostream &s, const char *prefix, counters_format_
s << '=' << c->GetIntervalCount();
switch (c->GetType()) {
case HistoryCount:
case HistoryUnknown:
break;
case HistoryVolume:
s << ' ' << name;
Expand Down
2 changes: 1 addition & 1 deletion src/HistoryCounters.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HistoryCountersData {
void Init(size_t size) {
dict.Clear();
for (int i = 0; i < COUNTER_MAX_AMOUNT_HISTORY; i++) {
counters[i].Init(HistoryUnknown);
counters[i].Init(HistoryCount);
}
}

Expand Down
12 changes: 11 additions & 1 deletion tests/TestHistoryCounters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ TEST_F(TestHistoryCounters, GetCategory) {
EXPECT_TRUE(HistoryCountersClear());
}

static bool HC_TestDump(counters_format_t format, const char* expected, const char* prefix = NULL) {
static bool HC_TestDump(counters_format_t format, const char* expected, const char* prefix = NULL, int interval_before_dump=0) {
EXPECT_TRUE(HistoryCountersClear());
HistoryCounter c1(TEST_COUNTER ".c1", HistoryCount);
HistoryCounter c2(TEST_COUNTER ".c2", HistoryCall);
HistoryCounter c3(TEST_COUNTER ".c3", HistoryVolume);
HistoryCounter xxx("xxx", HistoryVolume);
ClockOverride co;
FillTestData(co, c1, c2, c3);
co.AddSeconds(interval_before_dump);
std::stringstream ss;
GetHistoryCounters().Dump(ss, prefix ? prefix : TEST_COUNTER, format, false);
EXPECT_EQ(expected, ss.str());
Expand All @@ -85,6 +86,15 @@ TEST_F(TestHistoryCounters, DumpSimple) {
));
}

TEST_F(TestHistoryCounters, DumpSimpleBigDelay) {
EXPECT_TRUE(HC_TestDump(format_simple,
"test.level1.level2.c1 0 0 1800\n"
"test.level1.level2.c2 0 0 0 0 360600 10\n"
"test.level1.level2.c3 0 0 0 0 600 18030000\n"
,NULL, 60*10
));
}

TEST_F(TestHistoryCounters, DumpRaw) {
EXPECT_TRUE(HC_TestDump(format_raw,
" 1 60000 300 13515000 600 18030000\n",
Expand Down

0 comments on commit a0cb197

Please sign in to comment.