Sha256: 64db16bec109418801323cb55e7aa1f71ed79dcfc02c48cfbf9dcbf29a01bfb2
Contents?: true
Size: 1.95 KB
Versions: 2
Compression:
Stored size: 1.95 KB
Contents
# frozen_string_literal: true require 'spec_helper' require 'mnogootex/job/runner' require 'tmpdir' describe Mnogootex::Job::Runner do let(:test_dir) { Pathname.new(Dir.mktmpdir) } before { test_dir.mkpath } after { test_dir.rmtree } it 'executes commandline in given dir' do runner = described_class.new(cmd: 'pwd', chdir: test_dir) expect(runner).to be_successful expect(runner.log_lines.join.chomp).to eq(test_dir.realpath.to_s) end describe '#alive?' do it 'is true if thread is running' do runner = described_class.new(cmd: 'sleep 0.05', chdir: test_dir) expect(runner).to be_alive end it 'is false if thread is dead' do runner = described_class.new(cmd: ':', chdir: test_dir) sleep 0.05 expect(runner).to_not be_alive end end describe '#successful?' do it 'is true on zero exit status' do runner = described_class.new(cmd: 'exit 0', chdir: test_dir) expect(runner).to be_successful end it 'is false on nonzero exit status' do runner = described_class.new(cmd: 'exit 1', chdir: test_dir) expect(runner).to_not be_successful end end describe '#count_lines' do let!(:lns) { <<~SHELL } lns () { i=1; while [ "$i" -le $1 ]; do echo $i; i=$(( i + 1 )); done }; SHELL context 'dead process' do subject { described_class.new(cmd: "#{lns} lns 3", chdir: test_dir) } before do subject.successful? # waits on threads end it 'plateaus immediately at log lines count' do [3, 3].each { |n| expect(subject.count_lines).to eq(n) } end end context 'alive process' do subject { described_class.new(cmd: "#{lns} lns 3; sleep 0.20", chdir: test_dir) } before do subject sleep 0.02 end it 'unitarily increases from zero then plateaus at current line count' do [0, 1, 2, 3, 3, 3].each { |n| expect(subject.count_lines).to eq(n) } end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mnogootex-2.0.0 | spec/mnogootex/job/runner_spec.rb |
mnogootex-1.1.0 | spec/mnogootex/job/runner_spec.rb |