File: read_noblock_spec.rb

package info (click to toggle)
ruby-specinfra 2.94.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,448 kB
  • sloc: ruby: 10,538; sh: 4; makefile: 4
file content (54 lines) | stat: -rw-r--r-- 1,338 bytes parent folder | download | duplicates (6)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require 'spec_helper'

def command(cmd)
  Specinfra::Runner.run_command(cmd)
end

shared_examples "IO checks" do
    let (:generator) { "seq 1 #{max}" }
    let (:expected) { (1..max).map { |x| x.to_s }.join("\n") << "\n" }

    it "stdout only" do
        out = command(generator).stdout
        expect(out).to eq expected
    end

    it "stderr only" do
        out = command("#{generator} >&2" ).stderr
        expect(out).to eq expected
    end

    it "stdout then stderr" do
        cmd = command("#{generator}; #{generator} >&2" )
        expect(cmd.stdout).to eq expected
        expect(cmd.stderr).to eq expected
    end

    it "stderr then stdout" do
        cmd = command("#{generator} >&2; #{generator}" )
        expect(cmd.stdout).to eq expected
        expect(cmd.stderr).to eq expected
    end

    it "stdout and stderr" do
        cmd = command("(#{generator} &); #{generator} >&2; sleep 2" )
        expect(cmd.stdout).to eq expected
        expect(cmd.stderr).to eq expected
    end
end

describe "buffer overflow problem" do
    before :all do
        set :backend, :exec
    end

    context "with small output amount" do
        let (:max) { 10 }
        include_examples "IO checks"
    end

    context "with huge output amount" do
        let (:max) { 999999 }
        include_examples "IO checks"
    end
end