diff --git a/contrib/ruby_event_store-profiler/lib/ruby_event_store/profiler.rb b/contrib/ruby_event_store-profiler/lib/ruby_event_store/profiler.rb index afae2072ec..f5ac95c58e 100644 --- a/contrib/ruby_event_store-profiler/lib/ruby_event_store/profiler.rb +++ b/contrib/ruby_event_store-profiler/lib/ruby_event_store/profiler.rb @@ -22,7 +22,7 @@ def measure(&block) @instrumenter.instrument("total") { block.call } - subscribers.each { |name| @instrumenter.unsubscribe(name) } + subscribers.each { |s| @instrumenter.unsubscribe(s) } total = output.delete("total") diff --git a/contrib/ruby_event_store-profiler/spec/profiler_spec.rb b/contrib/ruby_event_store-profiler/spec/profiler_spec.rb index 7ff558d190..a43a2279c4 100644 --- a/contrib/ruby_event_store-profiler/spec/profiler_spec.rb +++ b/contrib/ruby_event_store-profiler/spec/profiler_spec.rb @@ -60,5 +60,34 @@ def now expect(return_value).to eq({ "total" => 6000, "serialize" => 1000.0, "append_to_stream" => 1000.0 }) end + + specify "no leftover subscriptions" do + begin + $stdout = File.open("/dev/null", "w") + Profiler.new(instrumenter).measure {} + ensure + $stdout = STDOUT + end + + [/rails_event_store/, /aggregate_root/, "total"].each do |pattern| + expect(instrumenter.notifier.listening?(pattern)).to eq(false) + end + end + + specify "should unsubcribe only its own subscriptions" do + external_subscriber = + instrumenter.subscribe("total") { } + + begin + $stdout = File.open("/dev/null", "w") + Profiler.new(instrumenter).measure {} + ensure + $stdout = STDOUT + end + + expect(instrumenter.notifier.listening?("total")).to eq(true) + ensure + instrumenter.unsubscribe(external_subscriber) + end end end