From 271c547f058d4fbbba19d4945bf4e1ab0710d8c9 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Wed, 2 Aug 2017 17:50:53 +0200 Subject: [PATCH] Initialize monitor and copy internal filters list on FilterChain#dup --- lib/rackstash/filter_chain.rb | 9 +++++++++ spec/rackstash/filter_chain_spec.rb | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/rackstash/filter_chain.rb b/lib/rackstash/filter_chain.rb index ff6d7e1..5957d01 100644 --- a/lib/rackstash/filter_chain.rb +++ b/lib/rackstash/filter_chain.rb @@ -273,6 +273,15 @@ module Rackstash private + def initialize_copy(orig) + super + + mon_initialize + synchronize do + @filters = orig.to_a + end + end + def index_at(index) case index when Integer, ->(o) { o.respond_to?(:to_int) } diff --git a/spec/rackstash/filter_chain_spec.rb b/spec/rackstash/filter_chain_spec.rb index 8adf6c6..b12cfa7 100644 --- a/spec/rackstash/filter_chain_spec.rb +++ b/spec/rackstash/filter_chain_spec.rb @@ -225,6 +225,16 @@ describe Rackstash::FilterChain do end end + describe '#dup' do + it 'duplicates the filters array' do + filter_chain << a_filter + dupped = filter_chain.dup + + expect(filter_chain.length).to eql dupped.length + expect { filter_chain << a_filter }.not_to change { dupped.length } + end + end + describe '#each' do it 'yields each filter' do filter_chain << -> {}