Loading spec/labkit/tracing/rails/action_view_subscriber_spec.rb +37 −14 Original line number Diff line number Diff line Loading @@ -5,19 +5,36 @@ describe Labkit::Tracing::Rails::ActionViewSubscriber do shared_examples "an actionview notification" do it "should notify the tracer when the hash contains null values" do expect(Labkit::Tracing::TracingUtils).to receive(:postnotify_span).with(notification_name, start, finish, tags: expected_tags, exception: exception) expect(OpenTracing).to receive(:start_active_span).with(notification_name).and_return(scope) expect(scope).to receive(:span).and_return(span) subject.public_send(notify_method, start, finish, payload) expected_tags.each do |k, v| expect(span).to receive(:set_tag).with(k, v) end expect(span).to receive(:set_tag).with("error", true) if exception subscriber.start(notification_name, id, payload) subscriber.finish(notification_name, id, payload) end it "should notify the tracer when the payload is missing values" do expect(Labkit::Tracing::TracingUtils).to receive(:postnotify_span).with(notification_name, start, finish, tags: expected_tags, exception: exception) expect(OpenTracing).to receive(:start_active_span).with(notification_name).and_return(scope) expect(scope).to receive(:span).and_return(span) expected_tags.each do |k, v| expect(span).to receive(:set_tag).with(k, v) end expect(span).to receive(:set_tag).with("error", true) if exception subject.public_send(notify_method, start, finish, payload.compact) subscriber.start(notification_name, id, payload) subscriber.finish(notification_name, id, payload) end it "should not throw exceptions when with the default tracer" do expect { subject.public_send(notify_method, start, finish, payload) }.not_to raise_error expect { subscriber.start(notification_name, id, payload) subscriber.finish(notification_name, id, payload) }.not_to raise_error end end Loading @@ -33,10 +50,12 @@ describe Labkit::Tracing::Rails::ActionViewSubscriber do describe "#notify_render_template" do subject { described_class.new } let(:start) { Time.now } let(:finish) { Time.now } let(:id) { SecureRandom.hex } let(:notification_name) { "render_template" } let(:notify_method) { :notify_render_template } let(:subscriber) { Labkit::Tracing::Rails::ActionViewSubscriber::RenderTemplateSubscriber.new } let(:scope) { OpenTracing::Scope::new } let(:span) { OpenTracing::Span::new } where(:identifier, :layout, :exception) do [[nil, nil, nil], ["", nil, nil], ["show.haml", nil, nil], [nil, "", nil], [nil, "layout.haml", nil], [nil, nil, StandardError.new]] Loading @@ -54,10 +73,12 @@ describe Labkit::Tracing::Rails::ActionViewSubscriber do describe "#notify_render_collection" do subject { described_class.new } let(:start) { Time.now } let(:finish) { Time.now } let(:id) { SecureRandom.hex } let(:notification_name) { "render_collection" } let(:notify_method) { :notify_render_collection } let(:subscriber) { Labkit::Tracing::Rails::ActionViewSubscriber::RenderCollectionSubscriber.new } let(:scope) { OpenTracing::Scope::new } let(:span) { OpenTracing::Span::new } where(:identifier, :count, :expected_count, :cache_hits, :expected_cache_hits, :exception) do nil | nil | 0 | nil | 0 | nil Loading @@ -84,10 +105,12 @@ describe Labkit::Tracing::Rails::ActionViewSubscriber do describe "#notify_render_partial" do subject { described_class.new } let(:start) { Time.now } let(:finish) { Time.now } let(:id) { SecureRandom.hex } let(:notification_name) { "render_partial" } let(:notify_method) { :notify_render_partial } let(:subscriber) { Labkit::Tracing::Rails::ActionViewSubscriber::RenderPartialSubscriber.new } let(:scope) { OpenTracing::Scope::new } let(:span) { OpenTracing::Span::new } where(:identifier, :exception) do nil | nil Loading spec/labkit/tracing/rails/active_record_subscriber_spec.rb +27 −7 Original line number Diff line number Diff line Loading @@ -15,8 +15,11 @@ describe Labkit::Tracing::Rails::ActiveRecordSubscriber do describe "#notify" do subject { described_class.new } let(:start) { Time.now } let(:finish) { Time.now } let(:id) { SecureRandom.hex } let(:subscriber) { Labkit::Tracing::Rails::ActiveRecordSubscriber::SqlSubscriber.new } let(:scope) { OpenTracing::Scope::new } let(:span) { OpenTracing::Span::new } where(:name, :operation_name, :exception, :connection_id, :cached, :cached_response, :sql) do nil | "active_record:sqlquery" | nil | nil | nil | false | nil Loading Loading @@ -46,19 +49,36 @@ describe Labkit::Tracing::Rails::ActiveRecordSubscriber do end it "should notify the tracer when the hash contains null values" do expect(Labkit::Tracing::TracingUtils).to receive(:postnotify_span).with(operation_name, start, finish, tags: expected_tags, exception: exception) expect(OpenTracing).to receive(:start_active_span).with(operation_name).and_return(scope) expect(scope).to receive(:span).and_return(span) expected_tags.each do |k, v| expect(span).to receive(:set_tag).with(k, v) end expect(span).to receive(:set_tag).with("error", true) if exception subject.notify(start, finish, payload) subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) end it "should notify the tracer when the payload is missing values" do expect(Labkit::Tracing::TracingUtils).to receive(:postnotify_span).with(operation_name, start, finish, tags: expected_tags, exception: exception) expect(OpenTracing).to receive(:start_active_span).with(operation_name).and_return(scope) expect(scope).to receive(:span).and_return(span) expected_tags.each do |k, v| expect(span).to receive(:set_tag).with(k, v) end expect(span).to receive(:set_tag).with("error", true) if exception subject.notify(start, finish, payload.compact) subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) end it "should not throw exceptions when with the default tracer" do expect { subject.notify(start, finish, payload) }.not_to raise_error expect { subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) }.not_to raise_error end end end Loading spec/labkit/tracing/rails/active_support_subscriber_spec.rb +53 −23 Original line number Diff line number Diff line Loading @@ -15,8 +15,13 @@ describe Labkit::Tracing::Rails::ActiveSupportSubscriber do describe "#notify_cache_read" do subject { described_class.new } let(:start) { Time.now } let(:finish) { Time.now } let(:id) { SecureRandom.hex } let(:subscriber) { Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheReadSubscriber.new } let(:scope) { OpenTracing::Scope::new } let(:span) { OpenTracing::Span::new } let(:operation_name) { "cache_read" } where(:key, :hit, :super_operation) do nil | nil | nil Loading @@ -41,19 +46,26 @@ describe Labkit::Tracing::Rails::ActiveSupportSubscriber do end it "should notify the tracer when the hash contains null values" do expect(Labkit::Tracing::TracingUtils).to receive(:postnotify_span).with("cache_read", start, finish, tags: expected_tags, exception: nil) # , start, finish, tags: expected_tags, exception: nil expect(OpenTracing).to receive(:start_active_span).with("cache_read").and_return(OpenTracing::Scope::NOOP_INSTANCE) subject.notify_cache_read(start, finish, payload) subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) end it "should notify the tracer when the payload is missing values" do expect(Labkit::Tracing::TracingUtils).to receive(:postnotify_span).with("cache_read", start, finish, tags: expected_tags, exception: nil) # , start, finish, tags: expected_tags, exception: nil expect(OpenTracing).to receive(:start_active_span).with("cache_read").and_return(OpenTracing::Scope::NOOP_INSTANCE) subject.notify_cache_read(start, finish, payload.compact) subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) end it "should not throw exceptions when with the default tracer" do expect { subject.notify_cache_read(start, finish, payload) }.not_to raise_error expect { subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) }.not_to raise_error end end end Loading @@ -61,18 +73,21 @@ describe Labkit::Tracing::Rails::ActiveSupportSubscriber do describe "#notify_*" do subject { described_class.new } let(:start) { Time.now } let(:finish) { Time.now } let(:id) { SecureRandom.hex } let(:subscriber) { subscriber_klass.new } where(:method, :operation_name, :key) do :notify_cache_generate | "cache_generate" | nil :notify_cache_generate | "cache_generate" | 123 :notify_cache_fetch_hit | "cache_fetch_hit" | nil :notify_cache_fetch_hit | "cache_fetch_hit" | 123 :notify_cache_write | "cache_write" | nil :notify_cache_write | "cache_write" | 123 :notify_cache_delete | "cache_delete" | nil :notify_cache_delete | "cache_delete" | 123 let(:scope) { OpenTracing::Scope::new } let(:span) { OpenTracing::Span::new } where(:method, :operation_name, :key, :subscriber_klass) do :notify_cache_generate | "cache_generate" | nil | Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheGenerateSubscriber :notify_cache_generate | "cache_generate" | 123 | Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheGenerateSubscriber :notify_cache_fetch_hit | "cache_fetch_hit" | nil | Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheFetchHitSubscriber :notify_cache_fetch_hit | "cache_fetch_hit" | 123 | Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheFetchHitSubscriber :notify_cache_write | "cache_write" | nil | Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheWriteSubscriber :notify_cache_write | "cache_write" | 123 | Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheWriteSubscriber :notify_cache_delete | "cache_delete" | nil | Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheDeleteSubscriber :notify_cache_delete | "cache_delete" | 123 | Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheDeleteSubscriber end with_them do Loading @@ -88,19 +103,34 @@ describe Labkit::Tracing::Rails::ActiveSupportSubscriber do end it "should notify the tracer when the hash contains null values" do expect(Labkit::Tracing::TracingUtils).to receive(:postnotify_span).with(operation_name, start, finish, tags: expected_tags, exception: nil) expect(OpenTracing).to receive(:start_active_span).with(operation_name).and_return(scope) expect(scope).to receive(:span).and_return(span) subject.method(method).call(start, finish, payload) expected_tags.each do |k, v| expect(span).to receive(:set_tag).with(k, v) end subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) end it "should notify the tracer when the payload is missing values" do expect(Labkit::Tracing::TracingUtils).to receive(:postnotify_span).with(operation_name, start, finish, tags: expected_tags, exception: nil) expect(OpenTracing).to receive(:start_active_span).with(operation_name).and_return(scope) expect(scope).to receive(:span).and_return(span) expected_tags.each do |k, v| expect(span).to receive(:set_tag).with(k, v) end subject.method(method).call(start, finish, payload.compact) subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) end it "should not throw exceptions when with the default tracer" do expect { subject.method(method).call(start, finish, payload) }.not_to raise_error expect { subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) }.not_to raise_error end end end Loading spec/spec_helper.rb +1 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ require "gitlab-labkit" require "rspec-parameterized" require 'securerandom' RSpec.configure do |config| config.expect_with :rspec do |expectations| Loading Loading
spec/labkit/tracing/rails/action_view_subscriber_spec.rb +37 −14 Original line number Diff line number Diff line Loading @@ -5,19 +5,36 @@ describe Labkit::Tracing::Rails::ActionViewSubscriber do shared_examples "an actionview notification" do it "should notify the tracer when the hash contains null values" do expect(Labkit::Tracing::TracingUtils).to receive(:postnotify_span).with(notification_name, start, finish, tags: expected_tags, exception: exception) expect(OpenTracing).to receive(:start_active_span).with(notification_name).and_return(scope) expect(scope).to receive(:span).and_return(span) subject.public_send(notify_method, start, finish, payload) expected_tags.each do |k, v| expect(span).to receive(:set_tag).with(k, v) end expect(span).to receive(:set_tag).with("error", true) if exception subscriber.start(notification_name, id, payload) subscriber.finish(notification_name, id, payload) end it "should notify the tracer when the payload is missing values" do expect(Labkit::Tracing::TracingUtils).to receive(:postnotify_span).with(notification_name, start, finish, tags: expected_tags, exception: exception) expect(OpenTracing).to receive(:start_active_span).with(notification_name).and_return(scope) expect(scope).to receive(:span).and_return(span) expected_tags.each do |k, v| expect(span).to receive(:set_tag).with(k, v) end expect(span).to receive(:set_tag).with("error", true) if exception subject.public_send(notify_method, start, finish, payload.compact) subscriber.start(notification_name, id, payload) subscriber.finish(notification_name, id, payload) end it "should not throw exceptions when with the default tracer" do expect { subject.public_send(notify_method, start, finish, payload) }.not_to raise_error expect { subscriber.start(notification_name, id, payload) subscriber.finish(notification_name, id, payload) }.not_to raise_error end end Loading @@ -33,10 +50,12 @@ describe Labkit::Tracing::Rails::ActionViewSubscriber do describe "#notify_render_template" do subject { described_class.new } let(:start) { Time.now } let(:finish) { Time.now } let(:id) { SecureRandom.hex } let(:notification_name) { "render_template" } let(:notify_method) { :notify_render_template } let(:subscriber) { Labkit::Tracing::Rails::ActionViewSubscriber::RenderTemplateSubscriber.new } let(:scope) { OpenTracing::Scope::new } let(:span) { OpenTracing::Span::new } where(:identifier, :layout, :exception) do [[nil, nil, nil], ["", nil, nil], ["show.haml", nil, nil], [nil, "", nil], [nil, "layout.haml", nil], [nil, nil, StandardError.new]] Loading @@ -54,10 +73,12 @@ describe Labkit::Tracing::Rails::ActionViewSubscriber do describe "#notify_render_collection" do subject { described_class.new } let(:start) { Time.now } let(:finish) { Time.now } let(:id) { SecureRandom.hex } let(:notification_name) { "render_collection" } let(:notify_method) { :notify_render_collection } let(:subscriber) { Labkit::Tracing::Rails::ActionViewSubscriber::RenderCollectionSubscriber.new } let(:scope) { OpenTracing::Scope::new } let(:span) { OpenTracing::Span::new } where(:identifier, :count, :expected_count, :cache_hits, :expected_cache_hits, :exception) do nil | nil | 0 | nil | 0 | nil Loading @@ -84,10 +105,12 @@ describe Labkit::Tracing::Rails::ActionViewSubscriber do describe "#notify_render_partial" do subject { described_class.new } let(:start) { Time.now } let(:finish) { Time.now } let(:id) { SecureRandom.hex } let(:notification_name) { "render_partial" } let(:notify_method) { :notify_render_partial } let(:subscriber) { Labkit::Tracing::Rails::ActionViewSubscriber::RenderPartialSubscriber.new } let(:scope) { OpenTracing::Scope::new } let(:span) { OpenTracing::Span::new } where(:identifier, :exception) do nil | nil Loading
spec/labkit/tracing/rails/active_record_subscriber_spec.rb +27 −7 Original line number Diff line number Diff line Loading @@ -15,8 +15,11 @@ describe Labkit::Tracing::Rails::ActiveRecordSubscriber do describe "#notify" do subject { described_class.new } let(:start) { Time.now } let(:finish) { Time.now } let(:id) { SecureRandom.hex } let(:subscriber) { Labkit::Tracing::Rails::ActiveRecordSubscriber::SqlSubscriber.new } let(:scope) { OpenTracing::Scope::new } let(:span) { OpenTracing::Span::new } where(:name, :operation_name, :exception, :connection_id, :cached, :cached_response, :sql) do nil | "active_record:sqlquery" | nil | nil | nil | false | nil Loading Loading @@ -46,19 +49,36 @@ describe Labkit::Tracing::Rails::ActiveRecordSubscriber do end it "should notify the tracer when the hash contains null values" do expect(Labkit::Tracing::TracingUtils).to receive(:postnotify_span).with(operation_name, start, finish, tags: expected_tags, exception: exception) expect(OpenTracing).to receive(:start_active_span).with(operation_name).and_return(scope) expect(scope).to receive(:span).and_return(span) expected_tags.each do |k, v| expect(span).to receive(:set_tag).with(k, v) end expect(span).to receive(:set_tag).with("error", true) if exception subject.notify(start, finish, payload) subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) end it "should notify the tracer when the payload is missing values" do expect(Labkit::Tracing::TracingUtils).to receive(:postnotify_span).with(operation_name, start, finish, tags: expected_tags, exception: exception) expect(OpenTracing).to receive(:start_active_span).with(operation_name).and_return(scope) expect(scope).to receive(:span).and_return(span) expected_tags.each do |k, v| expect(span).to receive(:set_tag).with(k, v) end expect(span).to receive(:set_tag).with("error", true) if exception subject.notify(start, finish, payload.compact) subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) end it "should not throw exceptions when with the default tracer" do expect { subject.notify(start, finish, payload) }.not_to raise_error expect { subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) }.not_to raise_error end end end Loading
spec/labkit/tracing/rails/active_support_subscriber_spec.rb +53 −23 Original line number Diff line number Diff line Loading @@ -15,8 +15,13 @@ describe Labkit::Tracing::Rails::ActiveSupportSubscriber do describe "#notify_cache_read" do subject { described_class.new } let(:start) { Time.now } let(:finish) { Time.now } let(:id) { SecureRandom.hex } let(:subscriber) { Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheReadSubscriber.new } let(:scope) { OpenTracing::Scope::new } let(:span) { OpenTracing::Span::new } let(:operation_name) { "cache_read" } where(:key, :hit, :super_operation) do nil | nil | nil Loading @@ -41,19 +46,26 @@ describe Labkit::Tracing::Rails::ActiveSupportSubscriber do end it "should notify the tracer when the hash contains null values" do expect(Labkit::Tracing::TracingUtils).to receive(:postnotify_span).with("cache_read", start, finish, tags: expected_tags, exception: nil) # , start, finish, tags: expected_tags, exception: nil expect(OpenTracing).to receive(:start_active_span).with("cache_read").and_return(OpenTracing::Scope::NOOP_INSTANCE) subject.notify_cache_read(start, finish, payload) subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) end it "should notify the tracer when the payload is missing values" do expect(Labkit::Tracing::TracingUtils).to receive(:postnotify_span).with("cache_read", start, finish, tags: expected_tags, exception: nil) # , start, finish, tags: expected_tags, exception: nil expect(OpenTracing).to receive(:start_active_span).with("cache_read").and_return(OpenTracing::Scope::NOOP_INSTANCE) subject.notify_cache_read(start, finish, payload.compact) subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) end it "should not throw exceptions when with the default tracer" do expect { subject.notify_cache_read(start, finish, payload) }.not_to raise_error expect { subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) }.not_to raise_error end end end Loading @@ -61,18 +73,21 @@ describe Labkit::Tracing::Rails::ActiveSupportSubscriber do describe "#notify_*" do subject { described_class.new } let(:start) { Time.now } let(:finish) { Time.now } let(:id) { SecureRandom.hex } let(:subscriber) { subscriber_klass.new } where(:method, :operation_name, :key) do :notify_cache_generate | "cache_generate" | nil :notify_cache_generate | "cache_generate" | 123 :notify_cache_fetch_hit | "cache_fetch_hit" | nil :notify_cache_fetch_hit | "cache_fetch_hit" | 123 :notify_cache_write | "cache_write" | nil :notify_cache_write | "cache_write" | 123 :notify_cache_delete | "cache_delete" | nil :notify_cache_delete | "cache_delete" | 123 let(:scope) { OpenTracing::Scope::new } let(:span) { OpenTracing::Span::new } where(:method, :operation_name, :key, :subscriber_klass) do :notify_cache_generate | "cache_generate" | nil | Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheGenerateSubscriber :notify_cache_generate | "cache_generate" | 123 | Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheGenerateSubscriber :notify_cache_fetch_hit | "cache_fetch_hit" | nil | Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheFetchHitSubscriber :notify_cache_fetch_hit | "cache_fetch_hit" | 123 | Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheFetchHitSubscriber :notify_cache_write | "cache_write" | nil | Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheWriteSubscriber :notify_cache_write | "cache_write" | 123 | Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheWriteSubscriber :notify_cache_delete | "cache_delete" | nil | Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheDeleteSubscriber :notify_cache_delete | "cache_delete" | 123 | Labkit::Tracing::Rails::ActiveSupportSubscriber::CacheDeleteSubscriber end with_them do Loading @@ -88,19 +103,34 @@ describe Labkit::Tracing::Rails::ActiveSupportSubscriber do end it "should notify the tracer when the hash contains null values" do expect(Labkit::Tracing::TracingUtils).to receive(:postnotify_span).with(operation_name, start, finish, tags: expected_tags, exception: nil) expect(OpenTracing).to receive(:start_active_span).with(operation_name).and_return(scope) expect(scope).to receive(:span).and_return(span) subject.method(method).call(start, finish, payload) expected_tags.each do |k, v| expect(span).to receive(:set_tag).with(k, v) end subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) end it "should notify the tracer when the payload is missing values" do expect(Labkit::Tracing::TracingUtils).to receive(:postnotify_span).with(operation_name, start, finish, tags: expected_tags, exception: nil) expect(OpenTracing).to receive(:start_active_span).with(operation_name).and_return(scope) expect(scope).to receive(:span).and_return(span) expected_tags.each do |k, v| expect(span).to receive(:set_tag).with(k, v) end subject.method(method).call(start, finish, payload.compact) subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) end it "should not throw exceptions when with the default tracer" do expect { subject.method(method).call(start, finish, payload) }.not_to raise_error expect { subscriber.start(operation_name, id, payload) subscriber.finish(operation_name, id, payload) }.not_to raise_error end end end Loading
spec/spec_helper.rb +1 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ require "gitlab-labkit" require "rspec-parameterized" require 'securerandom' RSpec.configure do |config| config.expect_with :rspec do |expectations| Loading