Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Completely remove EventStream class, rename EventStreamOld
Browse files Browse the repository at this point in the history
EventStream wasn't instantiated anywhere.

Signed-off-by: Steven Danna <[email protected]>
  • Loading branch information
stevendanna committed Nov 18, 2016
1 parent 21d4e16 commit 49224e0
Showing 1 changed file with 2 additions and 65 deletions.
67 changes: 2 additions & 65 deletions oc-pushy-pedant/spec/pushy/support/sse_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def events_so_far
end
end

class EventStreamOld
class EventStream
def initialize(url, user, last_id, receive_timeout)
host = URI.parse(url).host
@evs = []
Expand Down Expand Up @@ -156,69 +156,6 @@ def close

end

class EventStream
def initialize(url, user, last_id, receive_timeout)
host = URI.parse(url).host
@evs = []
@complete = false
# XXX May need to disable SSL verification, if possible
@queue = Queue.new

auth_headers = user.signing_headers(:GET, url, "")
require 'chef/version'
headers =
{
'Accept' => 'text/event-stream',
'User-Agent' => 'chef-pedant rspec tests',
'X-Chef-Version' => Chef::VERSION,
'Host' => host,
'Cache-Control' => 'no-cache' # spec says clients should always set this
}
headers.merge!(auth_headers)
if last_id then
headers.merge!({'Last-Event-ID' => last_id})
end

@ep = EventParser.new
Thread.new {
req = Typhoeus::Request.new(
url,
headers: headers,
timeout: receive_timeout,
verbose: true
)
req.on_body do |chunk|
@queue << chunk
end
req.on_complete do |response|
@queue << :done
end
req.run
}
end

attr_reader :complete

def get_streaming_events
while ! @queue.empty?
el = @queue.pop
if el == :done
@ep.feed("", true)
@complete = true
else
@ep.feed(el)
end
end
@evs += @ep.events_so_far
@evs
end

def close
@client.reset_all
end

end

def expect_start(e, command, run_timeout, quorum, node_count, username, job = nil)
e.name.should == :start
e.json['command'].should == command
Expand Down Expand Up @@ -356,7 +293,7 @@ def do_complete_job(job, options = {})

def start_event_stream(last_id = nil, receive_timeout = nil)
job_feed_url = api_url("#{job_feed_path}/#{@id}")
stream = EventStreamOld.new(job_feed_url, admin_user, last_id, receive_timeout)
stream = EventStream.new(job_feed_url, admin_user, last_id, receive_timeout)
# Give some time for the first events to come in
sleep 0.25
stream
Expand Down

0 comments on commit 49224e0

Please sign in to comment.