Sha256: 9a7a58be462d7d14913842ff6fc5371631787d3748488528a19efb9b8bd74801
Contents?: true
Size: 1.6 KB
Versions: 2
Compression:
Stored size: 1.6 KB
Contents
# frozen_string_literal: true require_relative 'helper' require 'fileutils' class SocketTest < MiniTest::Test def setup super end def test_tcp port = rand(1234..5678) server = TCPServer.new('127.0.0.1', port) server_fiber = spin do while (socket = server.accept) spin do while (data = socket.gets(8192)) socket << data end end end end snooze client = TCPSocket.new('127.0.0.1', port) client.write("1234\n") assert_equal "1234\n", client.recv(8192) client.close ensure server_fiber&.stop server_fiber&.await server&.close end def test_unix_socket path = '/tmp/test_unix_socket' FileUtils.rm(path) rescue nil server = UNIXServer.new(path) server_fiber = spin do server.accept_loop do |socket| spin do while (data = socket.gets(8192)) socket << data end end end end snooze client = UNIXSocket.new(path) client.write("1234\n") assert_equal "1234\n", client.recv(8192) client.close ensure server_fiber&.stop server_fiber&.await server&.close end end class HTTPClientTest < MiniTest::Test require 'httparty' require 'json' def test_http res = HTTParty.get('http://worldtimeapi.org/api/timezone/Europe/Paris') response = JSON.load(res.body) assert_equal "CET", response['abbreviation'] end def test_https res = HTTParty.get('https://worldtimeapi.org/api/timezone/Europe/Paris') response = JSON.load(res.body) assert_equal "CET", response['abbreviation'] end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
polyphony-0.47.5.1 | test/test_socket.rb |
polyphony-0.47.5 | test/test_socket.rb |