-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mitch Hartweg
committed
Jan 3, 2025
1 parent
27849c7
commit 2ba429b
Showing
2 changed files
with
81 additions
and
11 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'test_helper' | ||
|
||
require 'scout_apm/sampling' | ||
|
||
class SamplingTest < Minitest::Test | ||
# tr = ScoutApm::TrackedRequest.new(ScoutApm::AgentContext.new, ScoutApm::FakeStore.new) | ||
|
||
def setup | ||
@global_sample_config = FakeConfigOverlay.new( | ||
{ | ||
'sample_rate' => 50, | ||
} | ||
) | ||
|
||
@individual_config = FakeConfigOverlay.new( | ||
{ | ||
'sample_endpoints' => ['/foo:50', '/bar:100'], | ||
'ignore_endpoints' => ['/baz'], | ||
'sample_jobs' => ['joba:50'], | ||
'ignore_jobs' => 'jobb,jobc', | ||
} | ||
) | ||
end | ||
|
||
def test_individual_sample_to_hash | ||
sampling = ScoutApm::Sampling.new(@individual_config) | ||
assert_equal({'/foo' => 50, '/bar' => 100}, sampling.individual_sample_to_hash(@individual_config.value('sample_endpoints'))) | ||
end | ||
|
||
def test_uri_ignore | ||
sampling = ScoutApm::Sampling.new(@individual_config) | ||
assert_equal true, sampling.ignore_uri?('/baz') | ||
assert_equal false, sampling.ignore_uri?('/foo') | ||
end | ||
|
||
def test_uri_sample | ||
sampling = ScoutApm::Sampling.new(@individual_config) | ||
assert_equal true, sampling.sample_uri?('/foo') | ||
assert_equal false, sampling.sample_uri?('/baz') | ||
end | ||
|
||
def test_job_ignore | ||
sampling = ScoutApm::Sampling.new(@individual_config) | ||
assert_equal true, sampling.ignore_job?('jobb') | ||
assert_equal false, sampling.ignore_job?('joba') | ||
end | ||
|
||
def test_job_sample | ||
sampling = ScoutApm::Sampling.new(@individual_config) | ||
assert_equal true, sampling.sample_job?('joba') | ||
assert_equal false, sampling.sample_job?('jobb') | ||
end | ||
|
||
def test_sample | ||
sampling = ScoutApm::Sampling.new(@global_sample_config) | ||
sampling.stub(:rand, 1) do | ||
assert_equal(false, sampling.sample?(50)) | ||
end | ||
sampling.stub(:rand, 99) do | ||
assert_equal(true, sampling.sample?(50)) | ||
end | ||
end | ||
end |