Skip to content

Commit

Permalink
need to reset the buffer between runs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Fuchs committed Mar 2, 2012
1 parent 70b6e9d commit b0b1e51
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
28 changes: 13 additions & 15 deletions lib/travis/worker/shell/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Shell
class Buffer < String
include Logging

log_header { "#{name}:shell:buffer" }
log_header { 'travis:worker:shell:buffer' }

attr_reader :pos, :interval, :limit, :callback

Expand All @@ -22,23 +22,19 @@ def initialize(interval = nil, options = {}, &callback)

def <<(other)
super.tap do
# make sure limit is initialized and > 0. Appending here happens
# asynchronously and #initialize may or may not have finished running
# by then. In addition, #length here is a regular method which is not
# synchronized. All this leads to #limit_exeeded! being called
# too early (and this explains build logs w/o any output but this length limit
# system message). MK.
if @limit && (@limit > 0) && length > @limit
warn "Log limit exceeded: @limit = #{@limit}, length = #{self.length}"
limit_exeeded!
end
limit_exeeded! if length > limit
end
end

def flush
read.tap do |string|
callback.call(string) if callback
end if !empty?
end unless empty?
end

def reset
replace ''
@pos = 0
end

def empty?
Expand All @@ -49,9 +45,10 @@ def empty?

def read
string = self[pos, length - pos]
# This Update do not happen atomically but it has no practical difference: in case
# total length was updated between local assignment above and increment below, we will just read and flush this
# extra output during next loop tick.
# This update do not happen atomically but it has no practical
# difference: in case total length was updated between local
# assignment above and increment below, we will just read and flush
# this extra output during next loop tick.
@pos += string.length
string
end
Expand All @@ -66,6 +63,7 @@ def start
end

def limit_exeeded!
warn "Log limit exceeded: @limit = #{@limit.inspect}, length = #{self.length.inspect}"
raise Travis::Build::OutputLimitExceeded.new(limit.to_s)
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/travis/worker/shell/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ def connect(silent = false)
@shell = Net::SSH.start(config.host, config.username, options).shell
end

# Closes the Shell and flushes the buffer
# Closes the Shell, flushes and resets the buffer
def close
shell.close!
buffer.flush
buffer.reset
end

# Allows you to set a callback when output is received from the ssh shell.
Expand Down

0 comments on commit b0b1e51

Please sign in to comment.