diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb118f400..ab1d23db8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/lib/concurrent-ruby/concurrent/utility/processor_counter.rb b/lib/concurrent-ruby/concurrent/utility/processor_counter.rb index e31808722..d5274620e 100644 --- a/lib/concurrent-ruby/concurrent/utility/processor_counter.rb +++ b/lib/concurrent-ruby/concurrent/utility/processor_counter.rb @@ -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") diff --git a/spec/concurrent/channel/integration_spec.rb b/spec/concurrent/channel/integration_spec.rb index 01f490dc9..4d4c073ee 100644 --- a/spec/concurrent/channel/integration_spec.rb +++ b/spec/concurrent/channel/integration_spec.rb @@ -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 . . diff --git a/spec/concurrent/promises_spec.rb b/spec/concurrent/promises_spec.rb index d89ce309f..2aa88fdfa 100644 --- a/spec/concurrent/promises_spec.rb +++ b/spec/concurrent/promises_spec.rb @@ -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 }