Skip to content

Commit

Permalink
Merge pull request #700 from ruby-concurrency/pitr-ch/ci
Browse files Browse the repository at this point in the history
Fixing CI
  • Loading branch information
pitr-ch committed May 23, 2018
2 parents 44ad0e5 + fcd5886 commit eca4cc0
Show file tree
Hide file tree
Showing 71 changed files with 958 additions and 957 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Expand Up @@ -6,13 +6,14 @@ gem 'concurrent-ruby-ext', path: '.', platform: :mri

group :development do
gem 'rake', '~> 11.0'
gem 'rake-compiler', '~> 0.9.5'
gem 'rake-compiler-dock', '~> 0.4.3'
gem 'rake-compiler', '~> 1.0.0'
gem 'rake-compiler-dock', '~> 0.6.0'
gem 'gem-compiler', '~> 0.3.0'
gem 'benchmark-ips', '~> 2.7'

# documentation
gem 'countloc', '~> 0.4.0', :platforms => :mri, :require => false
# TODO (pitr-ch 04-May-2018): update to remove: [DEPRECATION] `last_comment` is deprecated. Please use `last_description` instead.
gem 'yard', '~> 0.8.0', :require => false
gem 'redcarpet', '~> 3.3', platforms: :mri # understands github markdown
gem 'md-ruby-eval'
Expand Down
4 changes: 1 addition & 3 deletions Rakefile
Expand Up @@ -181,9 +181,7 @@ begin
--backtrace
--seed 1
--format documentation
--tag ~unfinished
--tag ~notravis
--tag ~buggy ]
--tag ~notravis ]

RSpec::Core::RakeTask.new(:travis) do |t|
t.rspec_opts = ['--color', *options].join(' ')
Expand Down
1 change: 0 additions & 1 deletion ext/ConcurrentRubyExtService.java
Expand Up @@ -2,7 +2,6 @@

import org.jruby.Ruby;
import org.jruby.runtime.load.BasicLibraryService;
import com.concurrent_ruby.ext.JRubyMapBackendLibrary;

public class ConcurrentRubyExtService implements BasicLibraryService {
public boolean basicLoad(final Ruby runtime) throws IOException {
Expand Down
10 changes: 7 additions & 3 deletions lib/concurrent/actor.rb
Expand Up @@ -35,9 +35,13 @@ def self.current
end

@root = Concurrent::Promises.delay do
Core.new(parent: nil, name: '/', class: Root, initialized: future = Concurrent::Promises.resolvable_future).reference.tap do
future.wait!
end
Core.
new(parent: nil,
name: '/',
class: Root,
initialized: future = Concurrent::Promises.resolvable_future).
reference.
tap { future.wait! }
end

# A root actor, a default parent of all actors spawned outside an actor
Expand Down
2 changes: 1 addition & 1 deletion lib/concurrent/actor/behaviour.rb
Expand Up @@ -49,7 +49,7 @@ module Actor
# - {RestartingContext} uses
# {include:Actor::Behaviour.restarting_behaviour_definition}
module Behaviour
MESSAGE_PROCESSED = Object.new
MESSAGE_PROCESSED = ::Object.new

require 'concurrent/actor/behaviour/abstract'
require 'concurrent/actor/behaviour/awaits'
Expand Down
3 changes: 2 additions & 1 deletion lib/concurrent/actor/core.rb
Expand Up @@ -90,8 +90,9 @@ def remove_child(child)
# can be called from other alternative Reference implementations
# @param [Envelope] envelope
def on_envelope(envelope)
log(DEBUG) { "is #{envelope.future ? 'asked' : 'told'} #{envelope.message.inspect} by #{envelope.sender}" }
schedule_execution do
log(DEBUG) { "was #{envelope.future ? 'asked' : 'told'} #{envelope.message.inspect} by #{envelope.sender}" }
log(DEBUG) { "was #{envelope.future ? 'asked' : 'told'} #{envelope.message.inspect} by #{envelope.sender} - processing" }
process_envelope envelope
end
nil
Expand Down
2 changes: 1 addition & 1 deletion lib/concurrent/agent.rb
Expand Up @@ -147,7 +147,7 @@ class Agent < Synchronization::LockableObject
ERROR_MODES = [:continue, :fail].freeze
private_constant :ERROR_MODES

AWAIT_FLAG = Object.new
AWAIT_FLAG = ::Object.new
private_constant :AWAIT_FLAG

AWAIT_ACTION = ->(value, latch) { latch.count_down; AWAIT_FLAG }
Expand Down
2 changes: 1 addition & 1 deletion lib/concurrent/async.rb
Expand Up @@ -435,7 +435,7 @@ def await
#
# @!visibility private
def init_synchronization
return self if @__async_initialized__
return self if defined?(@__async_initialized__) && @__async_initialized__
@__async_initialized__ = true
@__async_delegator__ = AsyncDelegator.new(self)
@__await_delegator__ = AwaitDelegator.new(@__async_delegator__)
Expand Down
2 changes: 1 addition & 1 deletion lib/concurrent/atomic/count_down_latch.rb
Expand Up @@ -55,7 +55,7 @@ module Concurrent
# @!macro internal_implementation_note
CountDownLatchImplementation = case
when Concurrent.on_jruby?
JavaCountDownLatch
MutexCountDownLatch
else
MutexCountDownLatch
end
Expand Down
3 changes: 2 additions & 1 deletion lib/concurrent/atomic/read_write_lock.rb
Expand Up @@ -193,7 +193,8 @@ def acquire_write_lock
#
# @return [Boolean] true if the lock is successfully released
def release_write_lock
c = @Counter.update { |counter| counter-RUNNING_WRITER }
return true unless running_writer?
c = @Counter.update { |counter| counter - RUNNING_WRITER }
@ReadLock.broadcast
@WriteLock.signal if waiting_writers(c) > 0
true
Expand Down
7 changes: 6 additions & 1 deletion lib/concurrent/concern/logging.rb
Expand Up @@ -17,7 +17,12 @@ module Logging
def log(level, progname, message = nil, &block)
#NOTE: Cannot require 'concurrent/configuration' above due to circular references.
# Assume that the gem has been initialized if we've gotten this far.
(@logger || Concurrent.global_logger).call level, progname, message, &block
logger = if defined?(@logger) && @logger
@logger
else
Concurrent.global_logger
end
logger.call level, progname, message, &block
rescue => error
$stderr.puts "`Concurrent.configuration.logger` failed to log #{[level, progname, message, block]}\n" +
"#{error.message} (#{error.class})\n#{error.backtrace.join "\n"}"
Expand Down
2 changes: 1 addition & 1 deletion lib/concurrent/constants.rb
Expand Up @@ -3,6 +3,6 @@ module Concurrent
# Various classes within allows for +nil+ values to be stored,
# so a special +NULL+ token is required to indicate the "nil-ness".
# @!visibility private
NULL = Object.new
NULL = ::Object.new

end
2 changes: 1 addition & 1 deletion lib/concurrent/edge/promises.rb
Expand Up @@ -1987,7 +1987,7 @@ class Channel < Concurrent::Synchronization::Object
safe_initialization!

# Default size of the Channel, makes it accept unlimited number of messages.
UNLIMITED = Object.new
UNLIMITED = ::Object.new
UNLIMITED.singleton_class.class_eval do
include Comparable

Expand Down
4 changes: 2 additions & 2 deletions lib/concurrent/exchanger.rb
Expand Up @@ -41,7 +41,7 @@ module Concurrent
class AbstractExchanger < Synchronization::Object

# @!visibility private
CANCEL = Object.new
CANCEL = ::Object.new
private_constant :CANCEL

# @!macro [attach] exchanger_method_initialize
Expand Down Expand Up @@ -329,7 +329,7 @@ def do_exchange(value, timeout)
# @!macro internal_implementation_note
ExchangerImplementation = case
when Concurrent.on_jruby?
JavaExchanger
RubyExchanger
else
RubyExchanger
end
Expand Down
19 changes: 13 additions & 6 deletions lib/concurrent/executor/cached_thread_pool.rb
Expand Up @@ -46,17 +46,24 @@ def initialize(opts = {})

private

# @!macro cached_thread_pool_method_initialize
# @!visibility private
def ns_initialize(opts)
super(opts)
if Concurrent.on_jruby?
if defined?(JavaThreadPoolExecutor) && self < JavaThreadPoolExecutor
# @!macro cached_thread_pool_method_initialize
# @!visibility private
def ns_initialize(opts)
super(opts)
@max_queue = 0
@executor = java.util.concurrent.Executors.newCachedThreadPool
@executor = java.util.concurrent.Executors.newCachedThreadPool
@executor.setRejectedExecutionHandler(FALLBACK_POLICY_CLASSES[@fallback_policy].new)
@executor.setKeepAliveTime(opts.fetch(:idletime, DEFAULT_THREAD_IDLETIMEOUT), java.util.concurrent.TimeUnit::SECONDS)
self.auto_terminate = opts.fetch(:auto_terminate, true)
end
else
# @!macro cached_thread_pool_method_initialize
# @!visibility private
def ns_initialize(opts)
super(opts)
end
end

end
end
2 changes: 1 addition & 1 deletion lib/concurrent/executor/single_thread_executor.rb
Expand Up @@ -8,7 +8,7 @@ module Concurrent

SingleThreadExecutorImplementation = case
when Concurrent.on_jruby?
JavaSingleThreadExecutor
RubySingleThreadExecutor
else
RubySingleThreadExecutor
end
Expand Down
10 changes: 5 additions & 5 deletions lib/concurrent/executor/thread_pool_executor.rb
Expand Up @@ -9,7 +9,7 @@ module Concurrent

ThreadPoolExecutorImplementation = case
when Concurrent.on_jruby?
JavaThreadPoolExecutor
RubyThreadPoolExecutor
else
RubyThreadPoolExecutor
end
Expand Down Expand Up @@ -58,9 +58,9 @@ class ThreadPoolExecutor < ThreadPoolExecutorImplementation
# @!macro [new] thread_pool_executor_method_initialize
#
# Create a new thread pool.
#
#
# @param [Hash] opts the options which configure the thread pool.
#
#
# @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
# number of threads to be created
# @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
Expand All @@ -73,12 +73,12 @@ class ThreadPoolExecutor < ThreadPoolExecutorImplementation
# @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
# tasks that are received when the queue size has reached
# `max_queue` or the executor has shut down
#
#
# @raise [ArgumentError] if `:max_threads` is less than one
# @raise [ArgumentError] if `:min_threads` is less than zero
# @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
# in `FALLBACK_POLICIES`
#
#
# @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

# @!method initialize(opts = {})
Expand Down
5 changes: 2 additions & 3 deletions lib/concurrent/ivar.rb
Expand Up @@ -157,9 +157,8 @@ def ns_initialize(value, opts)
self.observers = Collection::CopyOnWriteObserverSet.new
set_deref_options(opts)

if value == NULL
@state = :pending
else
@state = :pending
if value != NULL
ns_complete_without_notification(true, value, nil)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/concurrent/maybe.rb
Expand Up @@ -108,7 +108,7 @@ class Maybe < Synchronization::Object
# Indicates that the given attribute has not been set.
# When `Just` the {#nothing} getter will return `NONE`.
# When `Nothing` the {#just} getter will return `NONE`.
NONE = Object.new.freeze
NONE = ::Object.new.freeze

# The value of a `Maybe` when `Just`. Will be `NONE` when `Nothing`.
attr_reader :just
Expand Down
1 change: 1 addition & 0 deletions lib/concurrent/mutable_struct.rb
Expand Up @@ -212,6 +212,7 @@ def define_struct(name, members, &block)
synchronize do
clazz = Synchronization::AbstractStruct.define_struct_class(MutableStruct, Synchronization::LockableObject, name, members, &block)
members.each_with_index do |member, index|
clazz.send :remove_method, member
clazz.send(:define_method, member) do
synchronize { @values[index] }
end
Expand Down
4 changes: 2 additions & 2 deletions lib/concurrent/mvar.rb
Expand Up @@ -40,11 +40,11 @@ class MVar < Synchronization::Object
safe_initialization!

# Unique value that represents that an `MVar` was empty
EMPTY = Object.new
EMPTY = ::Object.new

# Unique value that represents that an `MVar` timed out before it was able
# to produce a value.
TIMEOUT = Object.new
TIMEOUT = ::Object.new

# Create a new `MVar`, either empty or with an initial value.
#
Expand Down
1 change: 1 addition & 0 deletions lib/concurrent/settable_struct.rb
Expand Up @@ -107,6 +107,7 @@ def define_struct(name, members, &block)
synchronize do
clazz = Synchronization::AbstractStruct.define_struct_class(SettableStruct, Synchronization::LockableObject, name, members, &block)
members.each_with_index do |member, index|
clazz.send :remove_method, member if clazz.instance_methods.include? member
clazz.send(:define_method, member) do
synchronize { @values[index] }
end
Expand Down
4 changes: 3 additions & 1 deletion lib/concurrent/synchronization/abstract_struct.rb
Expand Up @@ -138,13 +138,15 @@ def ns_initialize(*values)
end
unless name.nil?
begin
parent.send :remove_const, name if parent.const_defined? name
parent.const_set(name, clazz)
parent.const_get(name)
clazz
rescue NameError
raise NameError.new("identifier #{name} needs to be constant")
end
end
members.each_with_index do |member, index|
clazz.send :remove_method, member if clazz.instance_methods.include? member
clazz.send(:define_method, member) do
@values[index]
end
Expand Down
3 changes: 3 additions & 0 deletions lib/concurrent/timer_task.rb
Expand Up @@ -126,6 +126,7 @@ module Concurrent
# task = Concurrent::TimerTask.new(execution_interval: 1, timeout_interval: 1){ 42 }
# task.add_observer(TaskObserver.new)
# task.execute
# sleep 4
#
# #=> (2013-10-13 19:08:58 -0400) Execution successfully returned 42
# #=> (2013-10-13 19:08:59 -0400) Execution successfully returned 42
Expand Down Expand Up @@ -189,6 +190,7 @@ class TimerTask < RubyExecutorService
def initialize(opts = {}, &task)
raise ArgumentError.new('no block given') unless block_given?
super
set_deref_options opts
end

# Is the executor running?
Expand Down Expand Up @@ -280,6 +282,7 @@ def ns_initialize(opts, &task)
@run_now = opts[:now] || opts[:run_now]
@executor = Concurrent::SafeTaskExecutor.new(task)
@running = Concurrent::AtomicBoolean.new(false)
@value = nil

self.observers = Collection::CopyOnNotifyObserverSet.new
end
Expand Down
2 changes: 1 addition & 1 deletion lib/concurrent/tvar.rb
Expand Up @@ -162,7 +162,7 @@ def leave_transaction

class Transaction

ABORTED = Object.new
ABORTED = ::Object.new

ReadLogEntry = Struct.new(:tvar, :version)

Expand Down
10 changes: 5 additions & 5 deletions spec/concurrent/actor_spec.rb
Expand Up @@ -6,7 +6,7 @@ module Actor

# FIXME better tests!

RSpec.describe 'Concurrent::Actor', edge: true, if: !defined?(JRUBY_VERSION) do
RSpec.describe 'Concurrent::Actor', edge: true do

def terminate_actors(*actors)
actors.each do |actor|
Expand Down Expand Up @@ -148,7 +148,7 @@ def on_message(message)
end
end

it 'terminates with all its children', buggy: true do
it 'terminates with all its children', notravis: true do
child = subject.ask! :child
expect(subject.ask!(:terminated?)).to be_falsey
subject.ask(:terminate!).wait
Expand All @@ -172,7 +172,7 @@ def on_message(message)
describe 'message redirecting' do
let(:parent) do
AdHoc.spawn!(:parent) do
child = AdHoc.spawn!(:child) { -> m { m+1 } }
child = AdHoc.spawn!(:child) { -> m { m + 1 } }
-> message do
if message == :child
child
Expand Down Expand Up @@ -287,7 +287,7 @@ def on_message(message)
test = AdHoc.spawn! name: :tester, behaviour_definition: resuming_behaviour do

actor = AdHoc.spawn! name: :pausing,
behaviour_definition: Behaviour.restarting_behaviour_definition do
behaviour_definition: Behaviour.restarting_behaviour_definition do
queue << :init
-> m { m == :add ? 1 : pass }
end
Expand All @@ -313,7 +313,7 @@ def on_message(message)
end

describe 'pool' do
it 'supports asks', buggy: true do
it 'supports asks', notravis: true do
children = Queue.new
pool = Concurrent::Actor::Utils::Pool.spawn! 'pool', 5 do |index|
worker = Concurrent::Actor::Utils::AdHoc.spawn! name: "worker-#{index}", supervised: true do
Expand Down

0 comments on commit eca4cc0

Please sign in to comment.