Bug 723846 - Part 3: add tests for FlagHistogram. r=taras

This commit is contained in:
Nathan Froyd 2012-03-02 10:15:46 -05:00
Родитель 7233fee884
Коммит 4966e02284
3 изменённых файлов: 52 добавлений и 0 удалений

Просмотреть файл

@ -414,6 +414,7 @@ HISTOGRAM(RANGE_CHECKSUM_ERRORS, 1, 3000, 10, EXPONENTIAL, "Number of histograms
HISTOGRAM(BUCKET_ORDER_ERRORS, 1, 3000, 10, EXPONENTIAL, "Number of histograms with bucket order errors")
HISTOGRAM(TOTAL_COUNT_HIGH_ERRORS, 1, 3000, 10, EXPONENTIAL, "Number of histograms with total count high errors")
HISTOGRAM(TOTAL_COUNT_LOW_ERRORS, 1, 3000, 10, EXPONENTIAL, "Number of histograms with total count low errors")
HISTOGRAM_FLAG(TELEMETRY_TEST_FLAG, "a testing histogram; not meant to be touched")
#undef HISTOGRAM_BOOLEAN
#undef HISTOGRAM_FLAG

Просмотреть файл

@ -121,6 +121,7 @@ function checkHistograms(request, response) {
const TELEMETRY_PING = "TELEMETRY_PING";
const TELEMETRY_SUCCESS = "TELEMETRY_SUCCESS";
const TELEMETRY_TEST_FLAG = "TELEMETRY_TEST_FLAG";
do_check_true(TELEMETRY_PING in payload.histograms);
let rh = Telemetry.registeredHistograms;
for (let name in rh) {
@ -131,6 +132,17 @@ function checkHistograms(request, response) {
do_check_false(IGNORE_HISTOGRAM in payload.histograms);
do_check_false(IGNORE_CLONED_HISTOGRAM in payload.histograms);
// Flag histograms should automagically spring to life.
const expected_flag = {
range: [1, 2],
bucket_count: 3,
histogram_type: 3,
values: {0:1, 1:0},
sum: 1
};
let flag = payload.histograms[TELEMETRY_TEST_FLAG];
do_check_eq(uneval(flag), uneval(expected_flag));
// There should be one successful report from the previous telemetry ping.
const expected_tc = {
range: [1, 2],

Просмотреть файл

@ -85,6 +85,32 @@ function test_boolean_histogram()
do_check_eq(s.counts[0], 2);
}
function test_flag_histogram()
{
var h = Telemetry.newHistogram("test::flag histogram", 130, 4, 5, Telemetry.HISTOGRAM_FLAG);
var r = h.snapshot().ranges;
// Flag histograms ignore numeric parameters.
do_check_eq(uneval(r), uneval([0, 1, 2]))
// Should already have a 0 counted.
var c = h.snapshot().counts;
var s = h.snapshot().sum;
do_check_eq(uneval(c), uneval([1, 0, 0]));
do_check_eq(s, 1);
// Should switch counts.
h.add(2);
var c2 = h.snapshot().counts;
var s2 = h.snapshot().sum;
do_check_eq(uneval(c2), uneval([0, 1, 0]));
do_check_eq(s, 1);
// Should only switch counts once.
h.add(3);
var c3 = h.snapshot().counts;
var s3 = h.snapshot().sum;
do_check_eq(uneval(c3), uneval([0, 1, 0]));
do_check_eq(s3, 1);
do_check_eq(h.snapshot().histogram_type, Telemetry.FLAG_HISTOGRAM);
}
function test_getHistogramById() {
try {
Telemetry.getHistogramById("nonexistent");
@ -148,10 +174,19 @@ function test_addons() {
expect_success(function ()
register(extra_addon, name1, 0, 1, 2, Telemetry.HISTOGRAM_BOOLEAN));
// Check that we can register flag histograms.
var flag_addon = "testing-flag-addon";
var flag_histogram = "flag-histogram";
expect_success(function()
register(flag_addon, flag_histogram, 0, 1, 2, Telemetry.HISTOGRAM_FLAG))
expect_success(function()
register(flag_addon, name2, 2, 4, 4, Telemetry.HISTOGRAM_LINEAR));
// Check that we reflect registered addons and histograms.
snapshots = Telemetry.addonHistogramSnapshots;
do_check_true(addon_id in snapshots)
do_check_true(extra_addon in snapshots);
do_check_true(flag_addon in snapshots);
// Check that we have data for our created histograms.
do_check_true(name1 in snapshots[addon_id]);
@ -168,6 +203,10 @@ function test_addons() {
// Even though we've registered it, it shouldn't show up until data is added to it.
do_check_false(name1 in snapshots[extra_addon]);
// Flag histograms should show up automagically.
do_check_true(flag_histogram in snapshots[flag_addon]);
do_check_false(name2 in snapshots[flag_addon]);
// Check that we can remove addon histograms.
Telemetry.unregisterAddonHistograms(addon_id);
snapshots = Telemetry.addonHistogramSnapshots;