-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ref: Convert integration tests about dropping transactions to unit tests #1720
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0183c94
ref: convert integration tests to unit tests about dropping transactions
TBS1996 ec3650c
hardcode config value in test
TBS1996 614e7e9
Merge branch 'master' into ref/it_to_ut
TBS1996 5118f7f
rename var
TBS1996 d65931b
merge master
TBS1996 504ec8c
fix tests
TBS1996 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
use bytes::Bytes; | ||
use relay_general::protocol::EventId; | ||
use relay_sampling::{ | ||
DynamicSamplingContext, RuleCondition, RuleId, RuleType, SamplingConfig, SamplingMode, | ||
SamplingRule, | ||
}; | ||
|
||
use crate::actors::project::ProjectState; | ||
use crate::envelope::{Envelope, Item, ItemType}; | ||
|
||
pub fn state_with_rule_and_condition( | ||
sample_rate: Option<f64>, | ||
rule_type: RuleType, | ||
mode: SamplingMode, | ||
condition: RuleCondition, | ||
) -> ProjectState { | ||
let rules = match sample_rate { | ||
Some(sample_rate) => vec![SamplingRule { | ||
condition, | ||
sample_rate, | ||
ty: rule_type, | ||
id: RuleId(1), | ||
time_range: Default::default(), | ||
decaying_fn: relay_sampling::DecayingFunction::Constant, | ||
}], | ||
None => Vec::new(), | ||
}; | ||
|
||
state_with_config(SamplingConfig { | ||
rules, | ||
mode, | ||
next_id: None, | ||
}) | ||
} | ||
|
||
pub fn state_with_config(sampling_config: SamplingConfig) -> ProjectState { | ||
let mut state = ProjectState::allowed(); | ||
state.config.dynamic_sampling = Some(sampling_config); | ||
state | ||
} | ||
|
||
pub fn state_with_rule( | ||
sample_rate: Option<f64>, | ||
rule_type: RuleType, | ||
mode: SamplingMode, | ||
) -> ProjectState { | ||
let rules = match sample_rate { | ||
Some(sample_rate) => vec![SamplingRule { | ||
condition: RuleCondition::all(), | ||
sample_rate, | ||
ty: rule_type, | ||
id: RuleId(1), | ||
time_range: Default::default(), | ||
decaying_fn: relay_sampling::DecayingFunction::Constant, | ||
}], | ||
None => Vec::new(), | ||
}; | ||
|
||
state_with_config(SamplingConfig { | ||
rules, | ||
mode, | ||
next_id: None, | ||
}) | ||
} | ||
pub fn create_sampling_context(sample_rate: Option<f64>) -> DynamicSamplingContext { | ||
DynamicSamplingContext { | ||
trace_id: uuid::Uuid::new_v4(), | ||
public_key: "12345678901234567890123456789012".parse().unwrap(), | ||
release: None, | ||
environment: None, | ||
transaction: None, | ||
sample_rate, | ||
user: Default::default(), | ||
other: Default::default(), | ||
} | ||
} | ||
|
||
/// ugly hack to build an envelope with an optional trace context | ||
pub fn new_envelope<T: Into<String>>(with_dsc: bool, transaction_name: T) -> Box<Envelope> { | ||
let transaction_name = transaction_name.into(); | ||
let dsn = "https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42"; | ||
let event_id = EventId::new(); | ||
|
||
let raw_event = if with_dsc { | ||
format!( | ||
"{{\"transaction\": \"{}\", \"event_id\":\"{}\",\"dsn\":\"{}\", \"trace\": {}}}\n", | ||
transaction_name, | ||
event_id.0.to_simple(), | ||
dsn, | ||
serde_json::to_string(&create_sampling_context(None)).unwrap(), | ||
) | ||
} else { | ||
format!( | ||
"{{\"transaction\": \"{}\", \"event_id\":\"{}\",\"dsn\":\"{}\"}}\n", | ||
transaction_name, | ||
event_id.0.to_simple(), | ||
dsn, | ||
) | ||
}; | ||
|
||
let bytes = Bytes::from(raw_event); | ||
|
||
let mut envelope = Envelope::parse_bytes(bytes).unwrap(); | ||
|
||
let item1 = Item::new(ItemType::Transaction); | ||
envelope.add_item(item1); | ||
|
||
let item2 = Item::new(ItemType::Attachment); | ||
envelope.add_item(item2); | ||
|
||
let item3 = Item::new(ItemType::Attachment); | ||
envelope.add_item(item3); | ||
|
||
envelope | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This starts all the actors/services we have in order for this unit test to work, which is kind of heavy and does not make much sense.
But at this point I'm not sure how to solve this yet.
The current status:
the function you test uses
reject
function onenvelope_context
which triggers theTestStore
capture functionalityrelay/relay-server/src/utils/envelope_context.rs
Lines 190 to 191 in 3b42784
this function also is triggered on
Drop
of theenvelope_context
also the
reject
function triggerstrack_outcome
which also requiresOutcome
actor to be available in the registry.