Skip to content

Commit

Permalink
Merge pull request #670 from connamara/thread_interceptor
Browse files Browse the repository at this point in the history
Fixes intermittent ConcurrencyError seen in JRuby
  • Loading branch information
os97673 committed Apr 25, 2014
2 parents 27582e6 + 9d02a08 commit 9c926b0
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/cucumber/formatter/interceptor.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
require 'thread'

module Cucumber
module Formatter
module Interceptor
class Pipe
attr_reader :pipe, :buffer
attr_reader :pipe
def initialize(pipe)
@pipe = pipe
@buffer = []
@wrapped = true
end

def write(str)
@buffer << str if @wrapped
return @pipe.write(str)
lock.synchronize do
@buffer << str if @wrapped
return @pipe.write(str)
end
end

def buffer
lock.synchronize do
return @buffer.dup
end
end

def unwrap!
Expand Down Expand Up @@ -60,6 +69,11 @@ def self.wrap(pipe)
return $stdout
end
end

private
def lock
@lock||=Mutex.new
end
end
end
end
Expand Down

0 comments on commit 9c926b0

Please sign in to comment.