Skip to content

Commit

Permalink
Merge pull request #85 from djberg96/process_pause_update
Browse files Browse the repository at this point in the history
Update pause/resume specs to use ps command
  • Loading branch information
Fryguy authored Jul 7, 2020
2 parents e5b4501 + 03110e2 commit 079d3c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
1 change: 0 additions & 1 deletion more_core_extensions.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", ">= 3.0"
spec.add_development_dependency "simplecov"
spec.add_development_dependency "sys-proctable", "~> 1.2.2"
spec.add_development_dependency "timecop"

spec.add_runtime_dependency "activesupport"
Expand Down
29 changes: 9 additions & 20 deletions spec/core_ext/process/pause_resume_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
require 'sys-proctable'

RSpec.describe Process do
let(:linux) { Gem::Platform.local.os == 'linux' }

def get_process_status(pid)
process = Sys::ProcTable.ps(:pid => pid, :smaps => false, :cgroup => false)
linux ? process.state : process.status
end

def paused_status
linux ? 'T' : 4
`ps -p #{pid} -o stat=`[0]
end

context ".alive?" do
Expand All @@ -28,16 +19,15 @@ def paused_status
end

it "can pause a running process" do
expect(get_process_status(@pid)).not_to eql(paused_status)
expect(get_process_status(@pid)).not_to eq('T')
expect(Process.pause(@pid)).to eql(1)
sleep 0.5 # Give the kernel a chance to update the status
expect(get_process_status(@pid)).to eql(paused_status)
expect(get_process_status(@pid)).to eq('T')
end

it "is a no-op if the process is already paused" do
expect(Process.pause(@pid)).to eql(1)
expect(Process.pause(@pid)).to eq(1)
expect { Process.pause(@pid) }.not_to raise_error
expect(Process.pause(@pid)).to eql(1)
expect(Process.pause(@pid)).to eq(1)
end

it "returns nil if the process is not running" do
Expand All @@ -56,16 +46,15 @@ def paused_status
end

it "can resume a paused process" do
expect(get_process_status(@pid)).to eql(paused_status)
expect(get_process_status(@pid)).to eq('T')
Process.resume(@pid)
sleep 0.5 # Give the kernel a chance to update the status
expect(get_process_status(@pid)).not_to eql(paused_status)
expect(get_process_status(@pid)).not_to eq('T')
end

it "is a no-op if the process is already running" do
expect(Process.resume(@pid)).to eql(1)
expect(Process.resume(@pid)).to eq(1)
expect { Process.resume(@pid) }.not_to raise_error
expect(Process.resume(@pid)).to eql(1)
expect(Process.resume(@pid)).to eq(1)
end

it "returns nil if the process is not running" do
Expand Down

0 comments on commit 079d3c9

Please sign in to comment.