Skip to content

Commit

Permalink
Explain to mutant why unsubscribe interating over objects is crucial
Browse files Browse the repository at this point in the history
  • Loading branch information
mostlyobvious committed May 23, 2024
1 parent cdf27d3 commit e542f71
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
29 changes: 29 additions & 0 deletions contrib/ruby_event_store-profiler/spec/profiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e542f71

Please sign in to comment.