spec/async/io/ssl_socket_spec.rb in async-io-1.4.0 vs spec/async/io/ssl_socket_spec.rb in async-io-1.5.0
- old
+ new
@@ -19,62 +19,66 @@
# THE SOFTWARE.
require 'async/io/ssl_socket'
require 'async/rspec/ssl'
+require_relative 'generic_examples'
-RSpec.describe Async::Reactor do
- include_context Async::RSpec::Leaks
+RSpec.describe Async::IO::SSLSocket do
+ include_context Async::RSpec::Reactor
include_context Async::RSpec::SSL::VerifiedContexts
+ it_should_behave_like Async::IO::Generic
+
# Shared port for localhost network tests.
let(:endpoint) {Async::IO::Endpoint.tcp("127.0.0.1", 6779, reuse_port: true)}
let(:server_endpoint) {Async::IO::SecureEndpoint.new(endpoint, ssl_context: server_context)}
let(:client_endpoint) {Async::IO::SecureEndpoint.new(endpoint, ssl_context: client_context)}
let(:data) {"The quick brown fox jumped over the lazy dog."}
- around(:each) do |example|
+ let(:server_task) do
# Accept a single incoming connection and then finish.
- subject.async do |task|
+ reactor.async do |task|
server_endpoint.bind do |server|
server.listen(10)
- server.accept do |peer, address|
- data = peer.read(512)
- peer.write(data)
- end rescue nil
+ begin
+ server.accept do |peer, address|
+ data = peer.read(512)
+ peer.write(data)
+ end
+ rescue OpenSSL::SSL::SSLError
+ # ignore.
+ end
end
end
-
- result = example.run
-
- if result.is_a? Exception
- result
- else
- subject.run
- end
end
describe "#connect" do
context "with a trusted certificate" do
include_context Async::RSpec::SSL::ValidCertificate
it "should start server and send data" do
- subject.async do
+ server_task
+
+ reactor.async do
client_endpoint.connect do |client|
client.write(data)
+
expect(client.read(512)).to be == data
end
end
end
end
context "with an untrusted certificate" do
include_context Async::RSpec::SSL::InvalidCertificate
it "should fail to connect" do
- subject.async do
+ server_task
+
+ reactor.async do
expect do
client_endpoint.connect
end.to raise_error(OpenSSL::SSL::SSLError)
end
end