Sha256: 2080c6d7b128d0282fa1474c9f31aa710307485c50d68e7b0ec866389b28dcbe

Contents?: true

Size: 1.84 KB

Versions: 7

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

require_relative "../test_helper"

module Stripe
  class InstrumentationTest < Test::Unit::TestCase
    context ".notify" do
      teardown do
        Stripe::Instrumentation.send(:subscribers).clear
      end

      should "notify subscribers for the right topic" do
        sub1_events = []
        Stripe::Instrumentation.subscribe(:test1, :sub1) { |event| sub1_events << event }
        sub2_events = []
        Stripe::Instrumentation.subscribe(:test2, :sub2) { |event| sub2_events << event }

        Stripe::Instrumentation.notify(:test1, "hello")
        assert_equal(1, sub1_events.size)
        assert_equal(0, sub2_events.size)
      end

      should "notify multiple subscribers of the same topic" do
        sub1_events = []
        Stripe::Instrumentation.subscribe(:test, :sub1) { |event| sub1_events << event }
        sub2_events = []
        Stripe::Instrumentation.subscribe(:test, :sub2) { |event| sub2_events << event }

        Stripe::Instrumentation.notify(:test, "hello")
        assert_equal(1, sub1_events.size)
        assert_equal(1, sub2_events.size)
      end

      should "not notify a subscriber once it has unsubscribed" do
        events = []
        Stripe::Instrumentation.subscribe(:test, :sub) { |event| events << event }

        Stripe::Instrumentation.notify(:test, "hello")
        assert_equal(1, events.size)

        Stripe::Instrumentation.unsubscribe(:test, :sub)
        Stripe::Instrumentation.notify(:test, "hello")
        assert_equal(1, events.size)
      end
    end

    context "RequestEvent" do
      should "return a frozen object" do
        event = Stripe::Instrumentation::RequestEvent.new(
          duration: 0.1,
          http_status: 200,
          method: :get,
          num_retries: 0,
          path: "/v1/test"
        )

        assert(event.frozen?)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
stripe-5.14.0 test/stripe/instrumentation_test.rb
stripe-5.13.0 test/stripe/instrumentation_test.rb
stripe-5.12.1 test/stripe/instrumentation_test.rb
stripe-5.12.0 test/stripe/instrumentation_test.rb
stripe-5.11.0 test/stripe/instrumentation_test.rb
stripe-5.10.0 test/stripe/instrumentation_test.rb
stripe-5.9.0 test/stripe/instrumentation_test.rb