File: rate_limiting_spec.rb

package info (click to toggle)
ruby-jaeger-client 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 624 kB
  • sloc: ruby: 3,381; makefile: 6; sh: 4
file content (33 lines) | stat: -rw-r--r-- 937 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'spec_helper'

RSpec.describe Jaeger::Samplers::RateLimiting do
  let(:sampler) { described_class.new(max_traces_per_second: max_traces_per_second) }
  let(:max_traces_per_second) { 10 }
  let(:sample_args) { { trace_id: Jaeger::TraceId.generate } }
  let(:sample_result) { sampler.sample(sample_args) }
  let(:is_sampled) { sample_result[0] }
  let(:tags) { sample_result[1] }

  context 'when max_traces_per_second is negative' do
    let(:max_traces_per_second) { -1 }

    it 'throws an error' do
      expect { sampler }.to raise_error(
        "max_traces_per_second must not be negative, got #{max_traces_per_second}"
      )
    end
  end

  describe '#sample' do
    it 'returns a boolean' do
      expect(is_sampled).to be(true).or be(false)
    end

    it 'returns tags' do
      expect(tags).to eq(
        'sampler.type' => 'ratelimiting',
        'sampler.param' => max_traces_per_second
      )
    end
  end
end