Skip to content

Commit

Permalink
Catch EBADF when watch_stream fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Ari Zellner committed Jan 4, 2018
1 parent 8933375 commit 44caffd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/kubeclient/watch_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def each
yield(@format == :json ? WatchNotice.new(JSON.parse(line)) : line.chomp)
end
end
rescue IOError
rescue IOError, Errno::EBADF
raise unless @finished
end

Expand Down
21 changes: 21 additions & 0 deletions test/test_watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,25 @@ def test_watch_with_field_selector
"#{api_host}/v1/watch/events?fieldSelector=#{selector}",
times: 1)
end

def test_watch_with_finish_and_ebadf
api_host = 'http://localhost:8080/api'

stub_request(:get, %r{/api/v1$})
.to_return(body: open_test_file('core_api_resource_list.json'),
status: 200)
stub_request(:get, %r{.*\/watch/events})
.to_return(body: open_test_file('watch_stream.json'), status: 200)

client = Kubeclient::Client.new(api_host, 'v1')
watcher = client.watch_events

# explodes when Errno::EBADF is not caught
watcher.each do
watcher.finish
raise Errno::EBADF
end

assert_requested(:get, "#{api_host}/v1/watch/events", times: 1)
end
end

0 comments on commit 44caffd

Please sign in to comment.