Sha256: 02282cca2c7ae0f61e2de2051596b8036bbde9fa6d6f328606aa81498c6d843c

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

describe Net::EmptyPort do
  describe "VERSION" do
    subject { Net::EmptyPort::VERSION }
    it { should be_a String }
  end

  describe "empty_port TCP" do
    context "random" do
      let!(:port) { Net::EmptyPort.empty_port }
      it "is between 49152 and 65535" do
        expect(port).to be >= 49152
        expect(port).to be <= 65535
      end
    end
  end

  describe "empty_port UDP" do
    context "random" do
      let!(:port) { Net::EmptyPort.empty_port(0, :udp) }
      it "is between 49152 and 65535" do
        expect(port).to be >= 49152
        expect(port).to be <= 65535
      end
    end
  end

  describe "wait TCP" do
    let!(:port) { Net::EmptyPort.empty_port }
    it "wait until the empty_port is ready" do
      expect(Net::EmptyPort.used?(port)).to be(false)
      s = TCPServer.new('127.0.0.1', port)
      expect(Net::EmptyPort.wait(port, 2)).to be(true)
      s.close
    end

    it "fails because port is not read while the max_wait" do
      expect(Net::EmptyPort.wait(port, 0.1)).to be(false)
    end
  end

  describe "wait UDP" do
    let!(:port) { Net::EmptyPort.empty_port(0, :udp) }
    it "wait until the empty_port is ready" do
      expect(Net::EmptyPort.used?(port, :udp)).to be(false)
      s = UDPSocket.new
      s.bind('127.0.0.1', port)
      expect(Net::EmptyPort.wait(port, 2, :udp)).to be(true)
      s.close
    end

    it "fails because port is not read while the max_wait" do
      expect(Net::EmptyPort.wait(port, 0.1, :udp)).to be(false)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
net-empty_port-0.0.2 spec/net/empty_port_spec.rb