Closed djberg96 closed 4 years ago
@bdunne Thoughts?
@Fryguy ok, updated readme.
Looks good @djberg96 ... I think we are just waiting on specs.
@Fryguy, @NickLaMuro suggestions for testing an external process?
suggestions for testing an external process?
🤔
This is the best I can come up with at the moment...
%x[#{Gem.ruby} -e "loop; ...; end"]
sleep
).alive?
.pause
the process and check how many lines were written.resume
the process@NickLaMuro I don't know if it's an option, but I did see this: https://github.com/jpastuszek/rspec-background-process
@NickLaMuro Ok, I've add some specs, please let me know what you think.
Note that while I did insert some code to make the Windows version cross-platform, the current specs do not currently pass on Windows. This is because getting process status information on Windows is more difficult.
There is a status
field in the Win32_Process
object, but unfortunately it's always null (as per the documentation). On Windows you can't get process status, you can only get thread status. While it's possible to get this information, it would require adding more code to sys-proctable, which I don't want to worry about right now, especially since Windows doesn't matter to us atm.
@miq-bot remove_label wip
@NickLaMuro, @Fryguy, @jrafanie I think it's ready to go. :)
spec/core_ext/process/pause_resume_spec.rb
This PR extends the
Process
module to includepause
,resume
andalive?
methods.The Unix implementation is fairly straightforward, simply using
SIGSTOP
andSIGCONT
. The Windows implementation was trickier, and required the use of an ffi wrapper (here I usedfiddle
from the standard library).WIP for now until I add some specs. But, I can tell you that in local examples it worked as expected.The only quirk I noticed was on Windows it would not immediately respond to an event, e.g. SIGINT, but would instead defer until the process was resumed, whereas on unixy systems it appeared to react immediately, e.g. you could ctrl-c out of a paused process. But, I couldn't tell you if one of these is more "correct" than the other.
The ultimate goal is to remove the custom MiqProcess module from gems-pending.