Skip to content

Remove dependency on win32ole #1051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -6,20 +6,24 @@ concurrency:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}-latest
timeout-minutes: 10

strategy:
fail-fast: false
matrix:
ruby: [2.3, 2.4, 2.5, 2.6, 2.7, '3.0', 3.1, 3.2, 3.3, jruby, truffleruby]
os: [ubuntu]
include:
- ruby: 3.3
os: windows

env:
JAVA_OPTS: '-Xmx1024m'
RUBYOPT: '-w'
JRUBY_OPTS: '--dev'

name: "Tests: Ruby ${{ matrix.ruby }}"
name: "Tests: Ruby ${{ matrix.ruby }} - ${{ matrix.os }}"
steps:
- name: Clone Repo
uses: actions/checkout@v4
23 changes: 19 additions & 4 deletions lib/concurrent-ruby/concurrent/utility/processor_counter.rb
Original file line number Diff line number Diff line change
@@ -68,10 +68,20 @@ def compute_physical_processor_count
end
cores.count
when /mswin|mingw/
require 'win32ole'
result_set = WIN32OLE.connect("winmgmts://").ExecQuery(
"select NumberOfCores from Win32_Processor")
result_set.to_enum.collect(&:NumberOfCores).reduce(:+)
# Get-CimInstance introduced in PowerShell 3 or earlier: https://learn.microsoft.com/en-us/previous-versions/powershell/module/cimcmdlets/get-ciminstance?view=powershell-3.0
result = run('powershell -command "Get-CimInstance -ClassName Win32_Processor | Select-Object -Property NumberOfCores"')
if !result || $?.exitstatus != 0
# fallback to deprecated wmic for older systems
result = run("wmic cpu get NumberOfCores")
end
if !result || $?.exitstatus != 0
# Bail out if both commands returned something unexpected
processor_count
else
# powershell: "\nNumberOfCores\n-------------\n 4\n\n\n"
# wmic: "NumberOfCores \n\n4 \n\n\n\n"
result.scan(/\d+/).map(&:to_i).reduce(:+)
end
else
processor_count
end
@@ -81,6 +91,11 @@ def compute_physical_processor_count
return 1
end

def run(command)
IO.popen(command, &:read)
rescue Errno::ENOENT
end

def compute_cpu_quota
if RbConfig::CONFIG["target_os"].include?("linux")
if File.exist?("/sys/fs/cgroup/cpu.max")
2 changes: 1 addition & 1 deletion spec/concurrent/channel/integration_spec.rb
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@
end

specify 'default-selection.rb' do
skip('flaky') if Concurrent.on_jruby? || Concurrent.on_truffleruby?
skip('flaky') if Concurrent.on_jruby? || Concurrent.on_truffleruby? || Concurrent.on_windows?
expected = <<-STDOUT
.
.
1 change: 1 addition & 0 deletions spec/concurrent/promises_spec.rb
Original file line number Diff line number Diff line change
@@ -758,6 +758,7 @@ def behaves_as_delay(delay, value)
describe 'value!' do
%w[with without].each do |timeout|
it "does not return spuriously #{timeout} timeout" do
skip "SIGHUP not supported" if Concurrent.on_windows?
# https://github.com/ruby-concurrency/concurrent-ruby/issues/1015
trapped = false
original_handler = Signal.trap(:SIGHUP) { trapped = true }