yahns.git  about / heads / tags
sleepy, multi-threaded, non-blocking application server for Ruby
blob e797d8eea0776a6437e9350662018c2149bae027 870 bytes (raw)
$ git show HEAD:test/test_stream_file.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
# Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
# License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
# frozen_string_literal: true
require_relative 'helper'
require 'timeout'

class TestStreamFile < Testcase
  ENV["N"].to_i > 1 and parallelize_me!
  DevFD = Struct.new(:to_path)

  def test_stream_file
    fp = File.open("COPYING")
    sf = Yahns::StreamFile.new(fp, true, 0, fp.size)
    refute sf.respond_to?(:close)
    sf.wbuf_close(nil)
    assert fp.closed?
  end

  def test_fd
    fp = File.open("COPYING")
    obj = DevFD.new("/dev/fd/#{fp.fileno}")
    sf = Yahns::StreamFile.new(obj, true, 0, fp.size)
    io = sf.instance_variable_get :@tmpio
    assert_instance_of IO, io.to_io
    assert_equal fp.fileno, io.fileno
    refute sf.respond_to?(:close)
    sf.wbuf_close(nil)
    refute fp.closed?
    refute io.closed?
  end
end

git clone git://yhbt.net/yahns.git
git clone https://yhbt.net/yahns.git