Skip to content

Commit 9b7cda5

Browse files
committed
increase coverage for process coordinator
1 parent 620d354 commit 9b7cda5

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ pkg
99
log
1010
*.swp
1111
coverage
12+
.idea

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ group :test do
2020
gem "rack-test", "~> 0.5"
2121
gem "json"
2222
gem "minitest", '4.7.0'
23+
gem "minitest-stub-const"
2324
gem "sinatra"
2425
gem 'mock_redis', :git => "https://github.com/causes/mock_redis.git"
2526
end
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
require 'test_helper'
2+
3+
describe Resque::ProcessCoordinator do
4+
SOLARIS_RESPONSE = <<CMD
5+
" PID ARGS\n 1 /sbin/launchd\n 11111 /ruby/resque\n 11 /usr/libexec/UserEventAgent (System)\n 12 /usr/libexec/kextd\n 14 /usr/sbin/notifyd\n 15 /usr/sbin/securityd -i\n 16 /usr/sbin/diskarbitrationd\n 17 /usr/libexec/configd\n 18 /System/Library/CoreServices/powerd.bundle/powerd\n 19 /usr/sbin/distnoted daemon\n 20 /usr/sbin/syslogd\n 21 /usr/sbin/cfprefsd daemon\n 22 /usr/libexec/opendirectoryd\n 31 /System/Library/CoreServices/coreservicesd\n 35 /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/Support/fseventsd\n 38 /usr/libexec/wdhelper\n 39 /usr/libexec/warmd\n 40 /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/Resources/usbmuxd -launchd\n 43 /usr/libexec/stackshot -t\n 44 /System/Library/CoreServices/SleepServicesD\n 46 /System/Library/PrivateFrameworks/GenerationalStorage.framework/Versions/A/Support/revisiond\n 51 /usr/sbin/netbiosd\n 52 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Support/mds\n 53 /usr/sbin/mDNSResponder -launchd\n 56 /System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow console\n 58 /usr/sbin/KernelEventAgent\n 60 /usr/libexec/hidd\n 62 /sbin/dynamic_pager -F /private/var/vm/swapfile\n 65 /System/Library/CoreServices/appleeventsd --server\n 70 autofsd\n 71 /System/Library/PrivateFrameworks/ApplePushService.framework/apsd\n 76 /usr/sbin/ntpd -c /private/etc/ntp-restrict.conf -n -g -p /var/run/ntpd.pid -f /var/db/ntp.drift\n 78 /System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/Resources/WindowServer -daemon\n 79 /sbin/nfsd\n 92 /usr/sbin/rpc.lockd\n 93 /usr/sbin/rpc.statd\n 94 /usr/sbin/rpcbind\n 96 /usr/libexec/networkd\n 98 /usr/sbin/rpc.lockd\n 99 /usr/libexec/rpc.rquotad\n 100 /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/CVMServer\n 102 /sbin/launchd\n 105 /usr/sbin/cfprefsd agent\n 115 /System/Library/CoreServices/logind\n 116 /usr/sbin/coreaudiod\n 131 /sbin/launchd\n 134 /usr/libexec/UserEventAgent (Aqua)\n 135 /usr/sbin/distnoted agent\n 137 /usr/sbin/cfprefsd agent\n 143 /System/Library/CoreServices/Dock.app/Contents/MacOS/Dock\n 144 /System/Library/CoreServices/talagent\n 145 /System/Library/CoreServices/SystemUIServer.app/Contents/MacOS/SystemUIServer\n 146 /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder\n 149 /usr/sbin/pboard\n 150 /usr/sbin/usernoted\n 154 /System/Library/CoreServices/NotificationCenter.app/Contents/MacOS/NotificationCenter\n 158 /System/Library/PrivateFrameworks/IMCore.framework/imagent.app/Contents/MacOS/imagent\n 170 /System/Library/CoreServices/Menu Extras/TextInput.menu/Contents/SharedSupport/TISwitcher.app/Contents/MacOS/TISwitcher\n 181 /Applications/iTunes.app/Contents/MacOS/iTunesHelper.app/Contents/MacOS/iTunesHelper -psn_0_65552\n 182 /Applications/Dropbox.app/Contents/MacOS/Dropbox -psn_0_73746\n 183 /System/Library/Frameworks/ApplicationServices.framework/Frameworks/ATS.framework/Support/fontd\n 184 /usr/sbin/filecoordinationd\n 185 /System/Library/CoreServices/NetworkBrowserAgent\n 210 com.apple.dock.extra\n 228 /Library/DropboxHelperTools/Dropbox_u501/dbfseventsd\n 229 /Library/DropboxHelperTools/Dropbox_u501/dbfseventsd\n 230 /Library/DropboxHelperTools/Dropbox_u501/dbfseventsd\n 231 /System/Library/Image Capture/Support/Image Capture Extension.app/Contents/MacOS/Image Capture Extension -psn_0_106522\n 237 /System/Library/Services/AppleSpell.service/Contents/MacOS/AppleSpell -psn_0_114716\n 310 /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal -psn_0_172074\n 874 /System/Library/CoreServices/Dock.app/Contents/Resources/DashboardClient.app/Contents/MacOS/DashboardClient\n 2649 /System/Library/Frameworks/InputMethodKit.framework/Resources/imklaunchagent\n 2652 /usr/libexec/lsboxd\n 2782 /usr/libexec/syspolicyd\n 3414 /sbin/SystemStarter\n 3591 /System/Library/CoreServices/pbs\n 3592 /System/Library/PrivateFrameworks/CalendarAgent.framework/Executables/CalendarAgent\n 3593 /System/Library/PrivateFrameworks/TCC.framework/Resources/tccd\n 3596 /usr/libexec/xpcd\n 3645 /sbin/launchd\n 3648 /usr/sbin/distnoted agent\n 3649 /usr/sbin/cfprefsd agent\n 3799 /sbin/launchd\n 3801 /usr/sbin/cfprefsd agent\n 3953 com.apple.cmio.registerassistantservice\n 3954 /usr/libexec/xpcd\n 3959 /System/Library/CoreServices/ScopedBookmarkAgent\n 3962 /System/Library/CoreServices/AppleIDAuthAgent\n 5352 com.apple.ShareKitHelper\n 5354 /System/Library/Frameworks/Accounts.framework/Versions/A/Support/accountsd\n 5386 /System/Library/PrivateFrameworks/CoreSymbolication.framework/coresymbolicationd\n 5488 /Applications/Preview.app/Contents/MacOS/Preview -psn_0_2675341\n 5543 com.apple.hiservices-xpcservice\n 5553 com.apple.Preview.TrustedBookmarksService\n 6837 /System/Library/Frameworks/CoreMediaIO.framework/Resources/VDC.plugin/Contents/Resources/VDCAssistant\n 6869 /Applications/Skype.app/Contents/MacOS/Skype -psn_0_4559961\n 6927 /Applications/Kindle.app/Contents/MacOS/Kindle -psn_0_4629610\n 7416 /System/Library/CoreServices/Apple80211Agent.app/Contents/MacOS/Apple80211Agent -psn_0_5162220\n 7642 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Versions/A/Support/mdworker -s mdworker -c MDSImporterWorker -m com.apple.mdworker.shared\n 7660 /usr/sbin/blued\n 7668 /System/Library/CoreServices/BluetoothAudioAgent.app/Contents/MacOS/BluetoothAudioAgent\n 7671 /System/Library/CoreServices/AVRCPAgent.app/Contents/MacOS/AVRCPAgent -BTAutoLaunch -BTType L2CAP -BTObjectID 1111477248\n 7672 /Applications/iTunes.app/Contents/MacOS/iTunes -psn_0_5416234\n 7680 /Applications/Firefox.app/Contents/MacOS/firefox -psn_0_5424428\n 7685 /Applications/Firefox.app/Contents/MacOS/plugin-container.app/Contents/MacOS/plugin-container /Library/Internet Plug-Ins/googletalkbrowserplugin.plugin -greomni /Applications/Firefox.app/Contents/MacOS/omni.ja -appomni /Applications/Firefox.app/Contents/MacOS/browser/omni.ja -appdir /Applications/Firefox.app/Contents/MacOS/browser 7680 gecko-crash-server-pipe.7680 org.mozilla.machname.1774841989 plugin\n 7686 /usr/libexec/taskgated -s\n 7687 /Library/Application Support/Google/GoogleTalkPlugin.app/Contents/MacOS/GoogleTalkPlugin -psn_0_5432622\n 7690 /Applications/Firefox.app/Contents/MacOS/plugin-container.app/Contents/MacOS/plugin-container /Library/Internet Plug-Ins/Flash Player.plugin -greomni /Applications/Firefox.app/Contents/MacOS/omni.ja -appomni /Applications/Firefox.app/Contents/MacOS/browser/omni.ja -appdir /Applications/Firefox.app/Contents/MacOS/browser 7680 gecko-crash-server-pipe.7680 org.mozilla.machname.7023238 plugin\n 7777 /Applications/RubyMine.app/Contents/MacOS/rubymine -psn_0_5449010\n 7780 /Applications/RubyMine.app/bin/fsnotifier\n 7693 login -pf fillman\n 7694 -bash\n 7925 redis-server\n 7963 login -pfl fillman /bin/bash -c exec -la bash /bin/bash\n 7964 -bash\n 8004 irb \n 8008 ps -A -o pid,args\n"
6+
CMD
7+
8+
WINDOWS_RESPONSE = <<CMD.encode('utf-8', 'binary', :invalid => :replace, :undef => :replace)
9+
"\n\x88\xAC\xEF \xAE\xA1\xE0\xA0\xA7\xA0: ruby.exe\nPID: 5244\n\x88\xAC\xEF \xE1\xA5\xE1\xE1\xA8\xA8: Console\n\xFC \xE1\xA5\xA0\xAD\xE1\xA0: 0\n\x8F\xA0\xAC\xEF\xE2\xEC: 9\xFF840 \x8A\x81\n"
10+
CMD
11+
12+
LINUX_RESPONSE = <<CMD
13+
" PID COMMAND\n 1 /sbin/init\n 22222 /ruby/resque\n 2 [kthreadd]\n 3 [ksoftirqd/0]\n 5 [kworker/u:0]\n 6 [migration/0]\n 7 [watchdog/0]\n 8 [cpuset]\n 9 [khelper]\n 10 [kdevtmpfs]\n 11 [netns]\n 12 [sync_supers]\n 13 [bdi-default]\n 14 [kintegrityd]\n 15 [kblockd]\n 16 [ata_sff]\n 17 [khubd]\n 18 [md]\n 21 [khungtaskd]\n 22 [kswapd0]\n 23 [ksmd]\n 24 [fsnotify_mark]\n 25 [ecryptfs-kthrea]\n 26 [crypto]\n 34 [kthrotld]\n 36 [kworker/u:2]\n 37 [scsi_eh_0]\n 38 [scsi_eh_1]\n 40 [kworker/0:2]\n 59 [devfreq_wq]\n 248 [jbd2/vda-8]\n 249 [ext4-dio-unwrit]\n 313 upstart-udev-bridge --daemon\n 315 /sbin/udevd --daemon\n 411 /sbin/udevd --daemon\n 412 /sbin/udevd --daemon\n 426 [kpsmoused]\n 428 [kworker/0:3]\n 534 upstart-socket-bridge --daemon\n 592 dbus-daemon --system --fork --activation=upstart\n 622 rsyslogd -c5\n 632 /sbin/getty -8 38400 tty4\n 635 /sbin/getty -8 38400 tty5\n 646 /sbin/getty -8 38400 tty2\n 647 /sbin/getty -8 38400 tty3\n 651 /sbin/getty -8 38400 tty6\n 658 anacron -s\n 659 acpid -c /etc/acpi/events -s /var/run/acpid.socket\n 660 cron\n 662 atd\n 741 /usr/sbin/sshd -D\n 747 /sbin/getty -8 38400 tty1\n 749 [flush-253:0]\n 5395 [kworker/0:0]\n 5898 sshd: fillman [priv]\n 5910 sshd: fillman@pts/0 \n 5911 -bash\n 6097 irb \n 6102 ps -A -o pid,command\n"
14+
CMD
15+
16+
describe "#worker_pids" do
17+
let(:process_coordinator) { Resque::ProcessCoordinator.new }
18+
19+
it "should return worker pids for each OS" do
20+
Resque::ProcessCoordinator.stub_const(:RUBY_PLATFORM, "solaris") do
21+
process_coordinator.stub :`, SOLARIS_RESPONSE do
22+
assert_equal process_coordinator.worker_pids, ["11111"]
23+
end
24+
end
25+
26+
Resque::ProcessCoordinator.stub_const(:RUBY_PLATFORM, "mingw32") do
27+
process_coordinator.stub :`, WINDOWS_RESPONSE do
28+
assert_equal process_coordinator.worker_pids, ["5244"]
29+
end
30+
end
31+
32+
Resque::ProcessCoordinator.stub_const(:RUBY_PLATFORM, "linux") do
33+
process_coordinator.stub :`, LINUX_RESPONSE do
34+
assert_equal process_coordinator.worker_pids, ["22222"]
35+
end
36+
end
37+
end
38+
39+
it "should raise error if fail to execute cmd" do
40+
def process_coordinator.`(cmd)
41+
raise RuntimeError
42+
end
43+
44+
assert_raises(RuntimeError) {
45+
process_coordinator.worker_pids
46+
}
47+
end
48+
end
49+
end

test/resque/test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Coveralls.wear!
1010

1111
require 'minitest/autorun'
12+
require 'minitest/stub_const'
1213

1314
##
1415
# Add helper methods to Kernel

0 commit comments

Comments
 (0)