Skip to content

Commit

Permalink
Bug 1828528 - add TextMetric entry to private mod.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
perrymcmanis144 committed Apr 19, 2023
1 parent ca6aea8 commit 6c1724e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions glean-core/rlb/src/private/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub use glean_core::RateMetric;
pub use glean_core::RecordedExperiment;
pub use glean_core::StringListMetric;
pub use glean_core::StringMetric;
pub use glean_core::TextMetric;
pub use glean_core::TimespanMetric;
pub use glean_core::TimingDistributionMetric;
pub use glean_core::UrlMetric;
Expand Down
27 changes: 26 additions & 1 deletion glean-core/rlb/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use flate2::read::GzDecoder;
use serde_json::Value as JsonValue;

use crate::private::PingType;
use crate::private::{BooleanMetric, CounterMetric, EventMetric, StringMetric};
use crate::private::{BooleanMetric, CounterMetric, EventMetric, StringMetric, TextMetric};

use super::*;
use crate::common_test::{lock_test, new_glean, GLOBAL_APPLICATION_ID};
Expand Down Expand Up @@ -1369,6 +1369,31 @@ fn test_boolean_get_num_errors() {
assert_eq!(result, 0);
}

#[test]
fn test_text_can_hold_long_string() {
let _lock = lock_test();

let _t = new_glean(None, false);

let metric = TextMetric::new(CommonMetricData {
name: "text_metric".into(),
category: "test".into(),
send_in_pings: vec!["custom1".into()],
lifetime: Lifetime::Application,
disabled: false,
dynamic_label: Some(str::to_string("text")),
});

// 216 characters, which would overflow StringMetric
metric.set(str::to_string("I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhäuser Gate. All those moments will be lost in time, like tears in rain"));

let result = metric.test_get_num_recorded_errors(ErrorType::InvalidValue);
assert_eq!(result, 0);

let result = metric.test_get_num_recorded_errors(ErrorType::InvalidOverflow);
assert_eq!(result, 0);
}

#[test]
fn signaling_done() {
let _lock = lock_test();
Expand Down

0 comments on commit 6c1724e

Please sign in to comment.