diff --git a/.rubocop.yml b/.rubocop.yml index 41fa181e..c1b73c8d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,21 +2,133 @@ AllCops: DisplayCopNames: true # -# Style +# Lint # -LineLength: - Max: 128 +Lint/AssignmentInCondition: + Enabled: false # TODO: enable -Style/StringLiterals: - EnforcedStyle: double_quotes +Lint/EmptyWhen: + Enabled: false + +Lint/Loop: + Enabled: false # TODO: enable + +Lint/HandleExceptions: + Enabled: false # TODO: enable + +Lint/NonLocalExitFromIterator: + Enabled: false # TODO: enable + +Lint/RescueException: + Enabled: false # TODO: explicitly mark cases where we want to rescue Exception + +Lint/ShadowedException: + Enabled: false # TODO; enable + +Lint/UselessAssignment: + Enabled: false # TODO: enable # # Metrics # +Metrics/AbcSize: + Enabled: false # TODO: enable + +Metrics/BlockNesting: + Enabled: false # TODO: enable + Metrics/ClassLength: - Max: 200 + Max: 250 + +Metrics/CyclomaticComplexity: + Enabled: false # TODO: enable + +Metrics/LineLength: + Max: 200 # TODO: decrease Metrics/MethodLength: - Max: 50 + Max: 100 + +Metrics/ModuleLength: + Max: 250 + +Metrics/ParameterLists: + Enabled: false # TODO: enable + +Metrics/PerceivedComplexity: + Enabled: false # TODO: enable + +# +# Style +# + +Style/AccessorMethodName: + Enabled: false # TODO: enable + +Style/CaseEquality: + Enabled: false + +Style/ClassAndModuleChildren: + Enabled: false + +Style/ClassVars: + Enabled: false # TODO: enable + +Style/Documentation: + Enabled: false # TODO: enable + +Style/DoubleNegation: + Enabled: false # TODO: enable(?) + +Style/For: + Enabled: false # TODO: enable + +Style/FrozenStringLiteralComment: + Enabled: false # TODO: enable + +Style/GlobalVars: + Enabled: false # TODO: enable + +Style/GuardClause: + Enabled: false # TODO: enable + +Style/IfInsideElse: + Enabled: false # TODO: enable + +Style/MethodMissing: + Enabled: false # TODO: enable + +Style/ModuleFunction: + Enabled: false + +Style/NumericPredicate: + Enabled: false + +Style/RegexpLiteral: + Enabled: false # TODO: enable + +Style/RescueModifier: + Enabled: false # TODO: enable + +Style/SafeNavigation: + Enabled: false + +Style/Semicolon: + Enabled: false + +Style/SingleLineBlockParams: + Enabled: false + +Style/SpecialGlobalVars: + Enabled: false # TODO: enable + +Style/StringLiterals: + EnforcedStyle: double_quotes + +Style/StructInheritance: + Enabled: false # TODO: enable + +Style/TernaryParentheses: + Enabled: false diff --git a/Gemfile b/Gemfile index a5d87a61..065fb9b5 100644 --- a/Gemfile +++ b/Gemfile @@ -6,10 +6,14 @@ group :development do gem "pry" end -group :development, :test do - gem "rake", "~> 11", require: false +group :test do gem "rspec", "~> 3", require: false gem "rspec-retry", "~> 0.5", require: false gem "rubocop", "= 0.45.0", require: false gem "coveralls", ">= 0.8", require: false + gem "benchmark-ips", require: false +end + +group :development, :test do + gem "rake" end diff --git a/Guardfile b/Guardfile index 908926d6..38f69966 100644 --- a/Guardfile +++ b/Guardfile @@ -6,7 +6,7 @@ guard "rspec", cmd: "bundle exec rspec" do "actor_examples" => "actor", "example_actor_class" => "actor", "mailbox_examples" => %w(mailbox evented_mailbox), - "task_examples" => ["tasks/task_fiber", "tasks/task_thread"], + "task_examples" => ["tasks/task_fiber", "tasks/task_thread"] }.each do |examples, spec| watch("spec/support/#{examples}.rb") do Array(spec).map { |file| "spec/celluloid/#{file}_spec.rb" } diff --git a/Rakefile b/Rakefile index ed6fc5c2..48e8e2c1 100644 --- a/Rakefile +++ b/Rakefile @@ -2,8 +2,5 @@ require "bundler/gem_tasks" Dir["tasks/**/*.rake"].each { |task| load task } -default_tasks = ["spec"] -default_tasks << "rubocop" unless ENV["CI"] - -task default: default_tasks -task ci: %w(spec benchmark) +task default: %w(spec rubocop) +task ci: %w(default benchmark) diff --git a/benchmarks/parallel_hash.rb b/benchmarks/parallel_hash.rb deleted file mode 100644 index add71c38..00000000 --- a/benchmarks/parallel_hash.rb +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env ruby - -require "rubygems" -require "bundler/setup" -require "celluloid" -require "celluloid/pool" -require "celluloid/extras/rehasher" -require "benchmark/ips" - -pool = Celluloid::Extras::Rehasher.new - -Benchmark.ips do |ips| - ips.report("parallel hash") do - 64.times.map { pool.future(:rehash, "w3rd", 10_000) }.map(&:value) - end -end diff --git a/celluloid.gemspec b/celluloid.gemspec index ca705f47..8456c206 100644 --- a/celluloid.gemspec +++ b/celluloid.gemspec @@ -25,5 +25,6 @@ Gem::Specification.new do |spec| spec.required_rubygems_version = ">= 2.0.0" spec.add_runtime_dependency "timers", "~> 4" + spec.add_runtime_dependency "celluloid-pool", "~> 0.20" spec.add_runtime_dependency "celluloid-supervision", "~> 0.20" end diff --git a/examples/ring.rb b/examples/ring.rb index a335b06e..1e2d5e9b 100755 --- a/examples/ring.rb +++ b/examples/ring.rb @@ -28,7 +28,7 @@ def initialize(size) # Go around the ring the given number of times def run(n) - fail ArgumentError, "I can't go around a negative number of times" if n < 0 + raise ArgumentError, "I can't go around a negative number of times" if n < 0 async.around n wait :done diff --git a/examples/stack.rb b/examples/stack.rb index 6a98ccf4..0aa405a9 100644 --- a/examples/stack.rb +++ b/examples/stack.rb @@ -17,7 +17,7 @@ def initialize def push(x) @ary.push x end - alias_method :<<, :push + alias << push def pop @ary.pop diff --git a/lib/celluloid.rb b/lib/celluloid.rb index ef5dd624..91220ebe 100644 --- a/lib/celluloid.rb +++ b/lib/celluloid.rb @@ -19,7 +19,7 @@ module Celluloid LINKING_TIMEOUT = 5 # Warning message added to Celluloid objects accessed outside their actors - BARE_OBJECT_WARNING_MESSAGE = "WARNING: BARE CELLULOID OBJECT " + BARE_OBJECT_WARNING_MESSAGE = "WARNING: BARE CELLULOID OBJECT ".freeze class << self attr_writer :actor_system # Default Actor System @@ -31,9 +31,9 @@ class << self def actor_system if Thread.current.celluloid? - Thread.current[:celluloid_actor_system] || fail(Error, "actor system not running") + Thread.current[:celluloid_actor_system] || raise(Error, "actor system not running") else - Thread.current[:celluloid_actor_system] || @actor_system || fail(Error, "Celluloid is not yet started; use Celluloid.boot") + Thread.current[:celluloid_actor_system] || @actor_system || raise(Error, "Celluloid is not yet started; use Celluloid.boot") end end @@ -59,8 +59,16 @@ def included(klass) klass.property :exit_handler_name singleton = class << klass; self; end - singleton.send(:remove_method, :trap_exit) rescue nil - singleton.send(:remove_method, :exclusive) rescue nil + begin + singleton.send(:remove_method, :trap_exit) + rescue + nil + end + begin + singleton.send(:remove_method, :exclusive) + rescue + nil + end singleton.send(:define_method, :trap_exit) do |*args| exit_handler_name(*args) @@ -94,20 +102,20 @@ def uuid def cores Internals::CPUCounter.cores end - alias_method :cpus, :cores - alias_method :ncpus, :cores + alias cpus cores + alias ncpus cores # Perform a stack dump of all actors to the given output object def stack_dump(output = STDERR) actor_system.stack_dump.print(output) end - alias_method :dump, :stack_dump + alias dump stack_dump # Perform a stack summary of all actors to the given output object def stack_summary(output = STDERR) actor_system.stack_summary.print(output) end - alias_method :summarize, :stack_summary + alias summarize stack_summary def public_registry actor_system.public_registry @@ -157,7 +165,7 @@ def running? actor_system && actor_system.running? end - #de TODO Anticipate outside process finalizer that would by-pass this. + # de TODO Anticipate outside process finalizer that would by-pass this. def register_shutdown return if defined?(@shutdown_registered) && @shutdown_registered # Terminate all actors at exit, unless the exit is abnormal. @@ -184,18 +192,18 @@ def new(*args, &block) proxy._send_(:initialize, *args, &block) proxy end - alias_method :spawn, :new + alias spawn new # Create a new actor and link to the current one def new_link(*args, &block) - fail NotActorError, "can't link outside actor context" unless Celluloid.actor? + raise NotActorError, "can't link outside actor context" unless Celluloid.actor? proxy = Cell.new(allocate, behavior_options, actor_options).proxy Actor.link(proxy) proxy._send_(:initialize, *args, &block) proxy end - alias_method :spawn_link, :new_link + alias spawn_link new_link # Run an actor in the foreground def run(*args, &block) @@ -213,7 +221,7 @@ def actor_options mailbox_class: mailbox_class, mailbox_size: mailbox_size, task_class: task_class, - exclusive: exclusive_actor, + exclusive: exclusive_actor } end @@ -223,7 +231,7 @@ def behavior_options exclusive_methods: exclusive_methods, exit_handler_name: exit_handler_name, finalizer: finalizer, - receiver_block_executions: execute_block_on_receiver, + receiver_block_executions: execute_block_on_receiver } end @@ -251,7 +259,7 @@ module InstanceMethods def bare_object self end - alias_method :wrapped_object, :bare_object + alias wrapped_object bare_object # Are we being invoked in a different thread from our owner? def leaked? @@ -267,18 +275,18 @@ def tap def registered_name Actor.registered_name end - alias_method :name, :registered_name + alias name registered_name def inspect return "..." if Celluloid.detect_recursion str = "#<" - if leaked? - str << Celluloid::BARE_OBJECT_WARNING_MESSAGE - else - str << "Celluloid::Proxy::Cell" - end + str << if leaked? + Celluloid::BARE_OBJECT_WARNING_MESSAGE + else + "Celluloid::Proxy::Cell" + end str << "(#{self.class}:0x#{object_id.to_s(16)})" str << " " unless instance_variables.empty? @@ -306,9 +314,10 @@ def abort(cause) cause = case cause when String then RuntimeError.new(cause) when Exception then cause - else fail TypeError, "Exception object/String expected, but #{cause.class} received" - end - fail AbortError.new(cause) + else raise TypeError, "Exception object/String expected, but #{cause.class} received" + end + + raise AbortError, cause end # Terminate this actor @@ -446,7 +455,7 @@ def future(meth = nil, *args, &block) end if defined?(JRUBY_VERSION) && JRUBY_VERSION == "1.7.3" - fail "Celluloid is broken on JRuby 1.7.3. Please upgrade to 1.7.4+" + raise "Celluloid is broken on JRuby 1.7.3. Please upgrade to 1.7.4+" end require "celluloid/exceptions" diff --git a/lib/celluloid/actor.rb b/lib/celluloid/actor.rb index 10ea5aca..92675cdc 100644 --- a/lib/celluloid/actor.rb +++ b/lib/celluloid/actor.rb @@ -16,14 +16,14 @@ class << self # Obtain the current actor def current actor = Thread.current[:celluloid_actor] - fail NotActorError, "not in actor scope" unless actor + raise NotActorError, "not in actor scope" unless actor actor.behavior_proxy end # Obtain the name of the current actor def registered_name actor = Thread.current[:celluloid_actor] - fail NotActorError, "not in actor scope" unless actor + raise NotActorError, "not in actor scope" unless actor actor.name end @@ -52,13 +52,13 @@ def all # Watch for exit events from another actor def monitor(actor) - fail NotActorError, "can't link outside actor context" unless Celluloid.actor? + raise NotActorError, "can't link outside actor context" unless Celluloid.actor? Thread.current[:celluloid_actor].linking_request(actor, :link) end # Stop waiting for exit events from another actor def unmonitor(actor) - fail NotActorError, "can't link outside actor context" unless Celluloid.actor? + raise NotActorError, "can't link outside actor context" unless Celluloid.actor? Thread.current[:celluloid_actor].linking_request(actor, :unlink) end @@ -186,8 +186,8 @@ def linking_request(receiver, type) begin message = @mailbox.receive(remaining) do |msg| msg.is_a?(LinkingResponse) && - msg.actor.mailbox.address == receiver.mailbox.address && - msg.type == type + msg.actor.mailbox.address == receiver.mailbox.address && + msg.type == type end rescue TaskTimeout next # IO reactor did something, no message in queue yet. @@ -200,11 +200,11 @@ def linking_request(receiver, type) elsif message.is_a? SystemEvent # Queue up pending system events to be processed after we've successfully linked system_events << message - else fail "Unexpected message type: #{message.class}. Expected LinkingResponse, NilClass, SystemEvent." + else raise "Unexpected message type: #{message.class}. Expected LinkingResponse, NilClass, SystemEvent." end end - fail TaskTimeout, "linking timeout of #{LINKING_TIMEOUT} seconds exceeded with receiver: #{receiver}" + raise TaskTimeout, "linking timeout of #{LINKING_TIMEOUT} seconds exceeded with receiver: #{receiver}" end end @@ -217,7 +217,7 @@ def signal(name, value = nil) def wait(name) @signals.wait name end - + # Register a new handler for a given pattern def handle(*patterns, &block) @handlers.handle(*patterns, &block) @@ -225,7 +225,7 @@ def handle(*patterns, &block) # Receive an asynchronous message def receive(timeout = nil, &block) - while true + loop do message = @receivers.receive(timeout, &block) return message unless message.is_a?(SystemEvent) @@ -288,7 +288,7 @@ def handle_message(message) end def default_exit_handler(event) - fail event.reason if event.reason + raise event.reason if event.reason end # Handle any exceptions that occur within a running actor diff --git a/lib/celluloid/actor/system.rb b/lib/celluloid/actor/system.rb index 07f2a64e..f012f9e3 100644 --- a/lib/celluloid/actor/system.rb +++ b/lib/celluloid/actor/system.rb @@ -10,15 +10,15 @@ class System ROOT_SERVICES = [ { as: :notifications_fanout, - type: Celluloid::Notifications::Fanout, + type: Celluloid::Notifications::Fanout }, { as: :public_services, type: Celluloid::Supervision::Service::Public, accessors: [:services], - supervise: [], - }, - ] + supervise: [] + } + ].freeze attr_reader :registry, :group @@ -103,7 +103,7 @@ def running? def shutdown actors = running Timeout.timeout(shutdown_timeout) do - Internals::Logger.debug "Terminating #{actors.size} #{(actors.size > 1) ? 'actors' : 'actor'}..." if actors.size > 0 + Internals::Logger.debug "Terminating #{actors.size} #{actors.size > 1 ? 'actors' : 'actor'}..." unless actors.empty? # Actors cannot self-terminate, you must do it for them actors.each do |actor| diff --git a/lib/celluloid/call/sync.rb b/lib/celluloid/call/sync.rb index 7efba766..a38b39a4 100644 --- a/lib/celluloid/call/sync.rb +++ b/lib/celluloid/call/sync.rb @@ -29,7 +29,7 @@ def dispatch(obj) end def cleanup - exception = DeadActorError.new("attempted to call a dead actor: #{self.method}") + exception = DeadActorError.new("attempted to call a dead actor: #{method}") respond Internals::Response::Error.new(self, exception) end @@ -46,7 +46,7 @@ def value end def wait - while true + loop do message = Celluloid.mailbox.receive do |msg| msg.respond_to?(:call) && msg.call == self end diff --git a/lib/celluloid/calls.rb b/lib/celluloid/calls.rb index 4eee1e43..aced7261 100644 --- a/lib/celluloid/calls.rb +++ b/lib/celluloid/calls.rb @@ -10,7 +10,7 @@ def initialize(method, arguments = [], block = nil) if block if Celluloid.exclusive? # FIXME: nicer exception - fail "Cannot execute blocks on sender in exclusive mode" + raise "Cannot execute blocks on sender in exclusive mode" end @block = Proxy::Block.new(Celluloid.mailbox, self, block) else @@ -41,18 +41,18 @@ def check(obj) if @arguments.size != arity e = ArgumentError.new("wrong number of arguments (#{@arguments.size} for #{arity})") e.set_backtrace(caller << "#{meth.source_location.join(':')}: in `#{meth.name}`") - fail e + raise e end elsif arity < -1 mandatory_args = -arity - 1 if arguments.size < mandatory_args e = ArgumentError.new("wrong number of arguments (#{@arguments.size} for #{mandatory_args}+)") e.set_backtrace(caller << "#{meth.source_location.join(':')}: in `#{meth.name}`") - fail e + raise e end end rescue => ex - raise AbortError.new(ex) + raise AbortError, ex end end end diff --git a/lib/celluloid/cell.rb b/lib/celluloid/cell.rb index fae5ab0f..4cb1f018 100644 --- a/lib/celluloid/cell.rb +++ b/lib/celluloid/cell.rb @@ -36,9 +36,7 @@ def initialize(subject, options, actor_options) @actor.handle(Call::Block) do |message| task(:invoke_block) { message.dispatch } end - @actor.handle(Internals::Response::Block, Internals::Response) do |message| - message.dispatch - end + @actor.handle(Internals::Response::Block, Internals::Response, &:dispatch) @actor.start @proxy = (options[:proxy_class] || Proxy::Cell).new(@actor.mailbox, @actor.proxy, @subject.class.to_s) @@ -62,13 +60,13 @@ def invoke(call) end end - task(:call, meth, {call: call, subject: @subject}, + task(:call, meth, { call: call, subject: @subject }, dangerous_suspend: meth == :initialize, &Cell.dispatch) end def task(task_type, method_name = nil, subject = nil, meta = nil, &_block) meta ||= {} - meta.merge!(method_name: method_name) + meta[:method_name] = method_name @actor.task(task_type, meta) do if @exclusive_methods && method_name && @exclusive_methods.include?(method_name.to_sym) Celluloid.exclusive { yield subject } @@ -94,7 +92,7 @@ def self.shutdown def shutdown return unless @finalizer && @subject.respond_to?(@finalizer, true) - task(:finalizer, @finalizer, {call: @finalizer, subject: @subject}, + task(:finalizer, @finalizer, { call: @finalizer, subject: @subject }, dangerous_suspend: true, &Cell.shutdown) end end diff --git a/lib/celluloid/condition.rb b/lib/celluloid/condition.rb index 5c363d62..593ae259 100644 --- a/lib/celluloid/condition.rb +++ b/lib/celluloid/condition.rb @@ -34,7 +34,7 @@ def initialize # Wait for the given signal and return the associated value def wait(timeout = nil) - fail ConditionError, "cannot wait for signals while exclusive" if Celluloid.exclusive? + raise ConditionError, "cannot wait for signals while exclusive" if Celluloid.exclusive? if actor = Thread.current[:celluloid_actor] task = Task.current @@ -57,7 +57,7 @@ def wait(timeout = nil) result = Celluloid.suspend :condwait, waiter timer.cancel if timer - fail result if result.is_a?(ConditionError) + raise result if result.is_a?(ConditionError) return yield(result) if block_given? result end @@ -83,6 +83,6 @@ def broadcast(value = nil) end end - alias_method :inspect, :to_s + alias inspect to_s end end diff --git a/lib/celluloid/exceptions.rb b/lib/celluloid/exceptions.rb index 0034c6da..168fb037 100644 --- a/lib/celluloid/exceptions.rb +++ b/lib/celluloid/exceptions.rb @@ -1,6 +1,6 @@ module Celluloid class Error < StandardError; end - class Interruption < Exception; end + class Interruption < RuntimeError; end class TimedOut < Celluloid::Interruption; end # Distinguished from `Timeout` class StillActive < Celluloid::Error; end class NotActive < Celluloid::Error; end diff --git a/lib/celluloid/future.rb b/lib/celluloid/future.rb index cd1354a3..2e65ff6c 100644 --- a/lib/celluloid/future.rb +++ b/lib/celluloid/future.rb @@ -50,7 +50,7 @@ def initialize(&block) # Execute the given method in future context def execute(receiver, method, args, block) @mutex.synchronize do - fail "already calling" if @call + raise "already calling" if @call @call = Call::Sync.new(self, method, args, block) end @@ -93,12 +93,12 @@ def value(timeout = nil) end if result - (result.respond_to?(:value)) ? result.value : result + result.respond_to?(:value) ? result.value : result else - fail TimedOut, "Timed out" + raise TimedOut, "Timed out" end end - alias_method :call, :value + alias call value # Signal this future with the given result value def signal(value) @@ -106,7 +106,7 @@ def signal(value) result = Result.new(value, self) @mutex.synchronize do - fail "the future has already happened!" if @ready + raise "the future has already happened!" if @ready if @forwards @forwards.is_a?(Array) ? @forwards.each { |f| f << result } : @forwards << result @@ -116,7 +116,7 @@ def signal(value) @ready = true end end - alias_method :<<, :signal + alias << signal def cancel(error) response = Internals::Response::Error.new(@call, error) @@ -127,7 +127,7 @@ def cancel(error) end # Inspect this Celluloid::Future - alias_method :inspect, :to_s + alias inspect to_s # Wrapper for result values to distinguish them in mailboxes class Result diff --git a/lib/celluloid/group.rb b/lib/celluloid/group.rb index 49e4f8f7..7001354d 100644 --- a/lib/celluloid/group.rb +++ b/lib/celluloid/group.rb @@ -10,7 +10,7 @@ def initialize end def assert_active - fail Celluloid::NotActive unless active? + raise Celluloid::NotActive unless active? end def assert_inactive @@ -18,7 +18,7 @@ def assert_inactive if RUBY_PLATFORM == "java" Celluloid.logger.warn "Group is still active" else - fail Celluloid::StillActive + raise Celluloid::StillActive end end @@ -40,7 +40,11 @@ def to_a def purge(thread) @mutex.synchronize do @group.delete(thread) - thread.kill rescue nil + begin + thread.kill + rescue + nil + end end end @@ -53,15 +57,15 @@ def active? end def get - fail NotImplementedError + raise NotImplementedError end def create - fail NotImplementedError + raise NotImplementedError end def shutdown - fail NotImplementedError + raise NotImplementedError end end end diff --git a/lib/celluloid/group/pool.rb b/lib/celluloid/group/pool.rb index 1aa18ea5..a89538e3 100644 --- a/lib/celluloid/group/pool.rb +++ b/lib/celluloid/group/pool.rb @@ -12,7 +12,7 @@ def initialize super @mutex = Mutex.new @idle_threads = [] - @group = [] + @group = [] @busy_size = 0 @idle_size = 0 diff --git a/lib/celluloid/group/spawner.rb b/lib/celluloid/group/spawner.rb index 8327d5aa..d54e0ee8 100644 --- a/lib/celluloid/group/spawner.rb +++ b/lib/celluloid/group/spawner.rb @@ -11,7 +11,7 @@ def initialize def get(&block) assert_active - fail ArgumentError.new("No block sent to Spawner.get()") unless block_given? + raise ArgumentError, "No block sent to Spawner.get()" unless block_given? instantiate block end diff --git a/lib/celluloid/internals/handlers.rb b/lib/celluloid/internals/handlers.rb index 92948a39..a0e04281 100644 --- a/lib/celluloid/internals/handlers.rb +++ b/lib/celluloid/internals/handlers.rb @@ -17,7 +17,7 @@ def handle(*patterns, &block) # Handle incoming messages def handle_message(message) handler = @handlers.find { |h| h.match(message) } - handler.call message if handler + handler.call(message) if handler handler end end diff --git a/lib/celluloid/internals/logger.rb b/lib/celluloid/internals/logger.rb index 887e8bd8..b26927d9 100644 --- a/lib/celluloid/internals/logger.rb +++ b/lib/celluloid/internals/logger.rb @@ -87,11 +87,11 @@ def exception_handler(&block) # Format an exception message def format_exception(exception) str = "#{exception.class}: #{exception}\n\t" - if exception.backtrace - str << exception.backtrace.join("\n\t") - else - str << "EMPTY BACKTRACE\n\t" - end + str << if exception.backtrace + exception.backtrace.join("\n\t") + else + "EMPTY BACKTRACE\n\t" + end end end end diff --git a/lib/celluloid/internals/method.rb b/lib/celluloid/internals/method.rb index 84d3d664..42043697 100644 --- a/lib/celluloid/internals/method.rb +++ b/lib/celluloid/internals/method.rb @@ -3,9 +3,10 @@ module Internals # Method handles that route through an actor proxy class Method def initialize(proxy, name) - fail NoMethodError, "undefined method `#{name}'" unless proxy.respond_to? name + raise NoMethodError, "undefined method `#{name}'" unless proxy.respond_to? name - @proxy, @name = proxy, name + @proxy = proxy + @name = name @klass = @proxy.class end diff --git a/lib/celluloid/internals/properties.rb b/lib/celluloid/internals/properties.rb index f4d2006f..1f56ef69 100644 --- a/lib/celluloid/internals/properties.rb +++ b/lib/celluloid/internals/properties.rb @@ -9,7 +9,11 @@ def property(name, opts = {}) ivar_name = "@#{name}".to_sym singleton = class << ancestors.first; self; end - singleton.send(:remove_method, name) rescue nil + begin + singleton.send(:remove_method, name) + rescue + nil + end singleton.send(:define_method, name) do |value = nil, *extra| if value value = value ? [value, *send(name), *extra].uniq : [] if multi diff --git a/lib/celluloid/internals/registry.rb b/lib/celluloid/internals/registry.rb index 42fc1731..40cf402a 100644 --- a/lib/celluloid/internals/registry.rb +++ b/lib/celluloid/internals/registry.rb @@ -21,7 +21,7 @@ def []=(name, actor) else actor_singleton = class << actor; self; end unless actor_singleton.ancestors.include? Proxy::Abstract - fail TypeError, "not an actor" + raise TypeError, "not an actor" end # if actor.class.ancestors.include? Supervision::Container @@ -34,13 +34,17 @@ def []=(name, actor) end end - def add(name, actor, branch=:services) + def add(name, actor, branch = :services) set(name, actor) @registry.synchronize do unless @branches.key? branch @branches[branch] = [] self.class.instance_eval do - remove_method(branch) rescue nil + begin + remove_method(branch) + rescue + nil + end define_method(branch) { @branches[branch] } end @branches[branch] << name @@ -59,12 +63,12 @@ def [](name) def branch(name) @registry.synchronize do - @index.select { |a, b| b == name } + @index.select { |_a, b| b == name } end end - alias_method :get, :[] - alias_method :set, :[]= + alias get [] + alias set []= def delete(name) @registry.synchronize do diff --git a/lib/celluloid/internals/responses.rb b/lib/celluloid/internals/responses.rb index 011d36c6..d668e6bb 100644 --- a/lib/celluloid/internals/responses.rb +++ b/lib/celluloid/internals/responses.rb @@ -5,7 +5,8 @@ class Response attr_reader :call, :value def initialize(call, value) - @call, @value = call, value + @call = call + @value = value end def dispatch @@ -26,7 +27,7 @@ def value ex.backtrace.concat(caller) end - fail ex + raise ex end end diff --git a/lib/celluloid/internals/signals.rb b/lib/celluloid/internals/signals.rb index 1739aa47..c6a1e974 100644 --- a/lib/celluloid/internals/signals.rb +++ b/lib/celluloid/internals/signals.rb @@ -8,7 +8,7 @@ def initialize # Wait for the given signal and return the associated value def wait(name) - fail "cannot wait for signals while exclusive" if Celluloid.exclusive? + raise "cannot wait for signals while exclusive" if Celluloid.exclusive? @conditions[name] ||= Condition.new @conditions[name].wait diff --git a/lib/celluloid/internals/stack.rb b/lib/celluloid/internals/stack.rb index 6e0f5891..e4766eaf 100644 --- a/lib/celluloid/internals/stack.rb +++ b/lib/celluloid/internals/stack.rb @@ -9,7 +9,7 @@ def initialize(threads) @threads = [] end - def snapshot(backtrace=nil) + def snapshot(backtrace = nil) @group.each do |thread| if thread.role == :actor @actors << snapshot_actor(thread.actor, backtrace) if thread.actor @@ -19,7 +19,7 @@ def snapshot(backtrace=nil) end end - def snapshot_actor(actor, backtrace=nil) + def snapshot_actor(actor, backtrace = nil) state = ActorState.new state.id = actor.object_id @@ -45,12 +45,14 @@ def snapshot_cell(behavior) state end - def snapshot_thread(thread, backtrace=nil) - backtrace = begin - thread.backtrace - rescue NoMethodError # for Rubinius < 2.5.2.c145 - [] - end if backtrace + def snapshot_thread(thread, backtrace = nil) + if backtrace + backtrace = begin + thread.backtrace + rescue NoMethodError # for Rubinius < 2.5.2.c145 + [] + end + end ThreadState.new(thread.object_id, backtrace, thread.role) end diff --git a/lib/celluloid/internals/thread_handle.rb b/lib/celluloid/internals/thread_handle.rb index 9a893128..6a902c8b 100644 --- a/lib/celluloid/internals/thread_handle.rb +++ b/lib/celluloid/internals/thread_handle.rb @@ -23,18 +23,18 @@ def initialize(actor_system, role = nil) # Is the thread running? def alive? - @mutex.synchronize { @thread.alive? if @thread } + @mutex.synchronize { @thread && @thread.alive? } end # Forcibly kill the thread def kill - !!@mutex.synchronize { @thread.kill if @thread } + !!@mutex.synchronize { @thread && @thread.kill } self end # Join to a running thread, blocking until it terminates def join(limit = nil) - fail ThreadError, "Target thread must not be current thread" if @thread == Thread.current + raise ThreadError, "Target thread must not be current thread" if @thread == Thread.current @mutex.synchronize { @join.wait(@mutex, limit) if @thread } self end diff --git a/lib/celluloid/internals/uuid.rb b/lib/celluloid/internals/uuid.rb index 35d31f5e..106ff6ce 100644 --- a/lib/celluloid/internals/uuid.rb +++ b/lib/celluloid/internals/uuid.rb @@ -33,7 +33,7 @@ def self.generate thread.uuid_counter += 1 end - "#{PREFIX}-#{sprintf('%012x', counter)}".freeze + "#{PREFIX}-#{format('%012x', counter)}".freeze end end end diff --git a/lib/celluloid/logging/incident.rb b/lib/celluloid/logging/incident.rb index 53afd4b4..cd36193e 100644 --- a/lib/celluloid/logging/incident.rb +++ b/lib/celluloid/logging/incident.rb @@ -4,7 +4,7 @@ class Incident attr_accessor :pid attr_accessor :events, :triggering_event - def initialize(events, triggering_event=nil) + def initialize(events, triggering_event = nil) @events = events @triggering_event = triggering_event @pid = $PROCESS_ID diff --git a/lib/celluloid/logging/incident_logger.rb b/lib/celluloid/logging/incident_logger.rb index 4bde7e31..ffc13e88 100644 --- a/lib/celluloid/logging/incident_logger.rb +++ b/lib/celluloid/logging/incident_logger.rb @@ -1,4 +1,5 @@ require "logger" + module Celluloid # A logger that holds all messages in circular buffers, then flushes the buffers # when an event occurs at a configurable severity threshold. @@ -41,16 +42,16 @@ def severity_to_string(severity) attr_accessor :buffers # Create a new IncidentLogger. - def initialize(progname=nil, options={}) + def initialize(progname = nil, options = {}) @progname = progname || "default" @level = options[:level] || DEBUG @threshold = options[:threshold] || ERROR @sizelimit = options[:sizelimit] || 100 @buffer_mutex = Mutex.new - @buffers = Hash.new do |progname_hash, _progname| + @buffers = Hash.new do |progname_hash, pn| @buffer_mutex.synchronize do - progname_hash[_progname] = Hash.new do |severity_hash, severity| + progname_hash[pn] = Hash.new do |severity_hash, severity| severity_hash[severity] = RingBuffer.new(@sizelimit) end end @@ -62,7 +63,7 @@ def initialize(progname=nil, options={}) end # add an event. - def add(severity, message=nil, progname=nil, &block) + def add(severity, message = nil, progname = nil, &block) progname ||= @progname severity ||= UNKNOWN @@ -86,42 +87,42 @@ def add(severity, message=nil, progname=nil, &block) end event.id end - alias_method :log, :add + alias log add # See docs for Logger#info - def trace(progname=nil, &block) + def trace(progname = nil, &block) add(TRACE, nil, progname, &block) end - def debug(progname=nil, &block) + def debug(progname = nil, &block) add(DEBUG, nil, progname, &block) end - def info(progname=nil, &block) + def info(progname = nil, &block) add(INFO, nil, progname, &block) end - def warn(progname=nil, &block) + def warn(progname = nil, &block) add(WARN, nil, progname, &block) end - def error(progname=nil, &block) + def error(progname = nil, &block) add(ERROR, nil, progname, &block) end - def fatal(progname=nil, &block) + def fatal(progname = nil, &block) add(FATAL, nil, progname, &block) end - def unknown(progname=nil, &block) + def unknown(progname = nil, &block) add(UNKNOWN, nil, progname, &block) end def flush messages = [] @buffer_mutex.synchronize do - @buffers.each do |progname, severities| - severities.each do |severity, buffer| + @buffers.each do |_progname, severities| + severities.each do |_severity, buffer| messages += buffer.flush end end @@ -135,7 +136,7 @@ def clear end end - def create_incident(event=nil) + def create_incident(event = nil) Incident.new(flush, event) end diff --git a/lib/celluloid/logging/log_event.rb b/lib/celluloid/logging/log_event.rb index b104728e..79ec9749 100644 --- a/lib/celluloid/logging/log_event.rb +++ b/lib/celluloid/logging/log_event.rb @@ -3,7 +3,7 @@ module Celluloid class LogEvent attr_accessor :id, :severity, :message, :progname, :time - def initialize(severity, message, progname, time=Time.now, &_block) + def initialize(severity, message, progname, time = Time.now, &_block) # This id should be ordered. For now relies on Celluloid::UUID to be ordered. # May want to use a generation/counter strategy for independence of uuid. @id = Internals::UUID.generate diff --git a/lib/celluloid/logging/ring_buffer.rb b/lib/celluloid/logging/ring_buffer.rb index 08db78bb..f64fac9d 100644 --- a/lib/celluloid/logging/ring_buffer.rb +++ b/lib/celluloid/logging/ring_buffer.rb @@ -28,7 +28,7 @@ def push(value) value end end - alias_method :<<, :push + alias << push def shift @mutex.synchronize do @@ -54,7 +54,8 @@ def clear def remove_element return nil if empty? - value, @buffer[@start] = @buffer[@start], nil + value = @buffer[@start] + @buffer[@start] = nil @start = (@start + 1) % @size @count -= 1 value diff --git a/lib/celluloid/mailbox.rb b/lib/celluloid/mailbox.rb index d68f7d88..0533b9a9 100644 --- a/lib/celluloid/mailbox.rb +++ b/lib/celluloid/mailbox.rb @@ -41,7 +41,11 @@ def <<(message) @condition.signal nil ensure - @mutex.unlock rescue nil + begin + @mutex.unlock + rescue + nil + end end end @@ -52,7 +56,7 @@ def check(timeout = nil, &block) @mutex.lock begin - fail MailboxDead, "attempted to receive from a dead mailbox" if @dead + raise MailboxDead, "attempted to receive from a dead mailbox" if @dead message = nil Timers::Wait.for(timeout) do |remaining| @@ -63,7 +67,11 @@ def check(timeout = nil, &block) @condition.wait(@mutex, remaining) end ensure - @mutex.unlock rescue nil + begin + @mutex.unlock + rescue + nil + end end message @@ -73,17 +81,17 @@ def check(timeout = nil, &block) # timeout is exceeded, raise a TaskTimeout. def receive(timeout = nil, &block) message = nil - Timers::Wait.for(timeout) do |remaining| + Timers::Wait.for(timeout) do |_remaining| message = check(timeout, &block) break if message end return message if message - fail TaskTimeout.new("receive timeout exceeded") + raise TaskTimeout, "receive timeout exceeded" end # Shut down this mailbox and clean up its contents def shutdown - fail MailboxDead, "mailbox already shutdown" if @dead + raise MailboxDead, "mailbox already shutdown" if @dead @mutex.lock begin @@ -92,7 +100,11 @@ def shutdown @messages = [] @dead = true ensure - @mutex.unlock rescue nil + begin + @mutex.unlock + rescue + nil + end end messages.each do |msg| diff --git a/lib/celluloid/mailbox/evented.rb b/lib/celluloid/mailbox/evented.rb index d158ae05..bc12422f 100644 --- a/lib/celluloid/mailbox/evented.rb +++ b/lib/celluloid/mailbox/evented.rb @@ -26,7 +26,11 @@ def <<(message) @messages << message end ensure - @mutex.unlock rescue nil + begin + @mutex.unlock + rescue + nil + end end begin current_actor = Thread.current[:celluloid_actor] @@ -50,7 +54,7 @@ def check(timeout = nil, &block) @reactor.run_once(timeout) # No message was received: - return nil + nil end # Obtain the next message from the mailbox that matches the given block @@ -59,7 +63,11 @@ def next_message(block) begin super(&block) ensure - @mutex.unlock rescue nil + begin + @mutex.unlock + rescue + nil + end end end diff --git a/lib/celluloid/notifications.rb b/lib/celluloid/notifications.rb index 914ce1b2..3aa084b0 100644 --- a/lib/celluloid/notifications.rb +++ b/lib/celluloid/notifications.rb @@ -1,7 +1,7 @@ module Celluloid module Notifications def self.notifier - Actor[:notifications_fanout] || fail(DeadActorError, "notifications fanout actor not running") + Actor[:notifications_fanout] || raise(DeadActorError, "notifications fanout actor not running") end def publish(pattern, *args) @@ -56,7 +56,7 @@ def listening?(pattern) listeners_for(pattern).any? end - def prune(actor, _reason=nil) + def prune(actor, _reason = nil) @subscribers.reject! { |s| s.actor == actor } @listeners_for.clear end diff --git a/lib/celluloid/probe.rb b/lib/celluloid/probe.rb index 70177d76..2baa926f 100644 --- a/lib/celluloid/probe.rb +++ b/lib/celluloid/probe.rb @@ -7,7 +7,7 @@ class Probe include Celluloid include Celluloid::Notifications - NOTIFICATIONS_TOPIC_BASE = "celluloid.events.%s" + NOTIFICATIONS_TOPIC_BASE = "celluloid.events.%s".freeze EVENTS_BUFFER = Queue.new class << self diff --git a/lib/celluloid/proxy/abstract.rb b/lib/celluloid/proxy/abstract.rb index e3af1955..86fb42be 100644 --- a/lib/celluloid/proxy/abstract.rb +++ b/lib/celluloid/proxy/abstract.rb @@ -16,9 +16,9 @@ class Celluloid::Proxy::Abstract < BasicObject } # rubinius bug? These methods disappear when we include hacked kernel define_method :==, ::BasicObject.instance_method(:==) unless instance_methods.include?(:==) - alias_method(:equal?, :==) unless instance_methods.include?(:equal?) + alias equal? == unless instance_methods.include?(:equal?) end - + def __class__ @class ||= ::Celluloid::Proxy.class_of(self) end @@ -26,25 +26,25 @@ def __class__ class Celluloid::Proxy::AbstractCall < Celluloid::Proxy::Abstract attr_reader :mailbox - + def initialize(mailbox, klass) @mailbox = mailbox @klass = klass end - + def eql?(other) - self.__class__.eql?(::Celluloid::Proxy.class_of(other)) and @mailbox.eql?(other.mailbox) + __class__.eql?(::Celluloid::Proxy.class_of(other)) && @mailbox.eql?(other.mailbox) end def hash @mailbox.hash end - + def __klass__ @klass end - + def inspect - "#<#{self.__class__}(#{@klass})>" + "#<#{__class__}(#{@klass})>" end end diff --git a/lib/celluloid/proxy/async.rb b/lib/celluloid/proxy/async.rb index 1119d33a..583f0bd0 100644 --- a/lib/celluloid/proxy/async.rb +++ b/lib/celluloid/proxy/async.rb @@ -7,7 +7,7 @@ def method_missing(meth, *args, &block) end if block_given? # FIXME: nicer exception - fail "Cannot use blocks with async yet" + raise "Cannot use blocks with async yet" end @mailbox << ::Celluloid::Call::Async.new(meth, args, block) self diff --git a/lib/celluloid/proxy/block.rb b/lib/celluloid/proxy/block.rb index b481b42f..7da37b84 100644 --- a/lib/celluloid/proxy/block.rb +++ b/lib/celluloid/proxy/block.rb @@ -1,7 +1,7 @@ class Celluloid::Proxy::Block attr_writer :execution attr_reader :call, :block - + def initialize(mailbox, call, block) @mailbox = mailbox @call = call @@ -18,7 +18,7 @@ def to_proc task.suspend(:invokeblock) else # FIXME: better exception - fail "No task to suspend" + raise "No task to suspend" end end else diff --git a/lib/celluloid/proxy/cell.rb b/lib/celluloid/proxy/cell.rb index 834a3e08..fac1c4e0 100644 --- a/lib/celluloid/proxy/cell.rb +++ b/lib/celluloid/proxy/cell.rb @@ -22,7 +22,7 @@ def method(name) ::Celluloid::Internals::Method.new(self, name) end - alias_method :sync, :method_missing + alias sync method_missing # Obtain an async proxy or explicitly invoke a named async method def async(method_name = nil, *args, &block) diff --git a/lib/celluloid/proxy/future.rb b/lib/celluloid/proxy/future.rb index b04c170d..a410054d 100644 --- a/lib/celluloid/proxy/future.rb +++ b/lib/celluloid/proxy/future.rb @@ -2,12 +2,12 @@ class Celluloid::Proxy::Future < Celluloid::Proxy::AbstractCall def method_missing(meth, *args, &block) unless @mailbox.alive? - fail ::Celluloid::DeadActorError, "attempted to call a dead actor: #{meth}" + raise ::Celluloid::DeadActorError, "attempted to call a dead actor: #{meth}" end if block_given? # FIXME: nicer exception - fail "Cannot use blocks with futures yet" + raise "Cannot use blocks with futures yet" end future = ::Celluloid::Future.new diff --git a/lib/celluloid/proxy/sync.rb b/lib/celluloid/proxy/sync.rb index 4b2aa51f..e8030f5c 100644 --- a/lib/celluloid/proxy/sync.rb +++ b/lib/celluloid/proxy/sync.rb @@ -6,7 +6,7 @@ def respond_to?(meth, include_private = false) def method_missing(meth, *args, &block) unless @mailbox.alive? - fail ::Celluloid::DeadActorError, "attempted to call a dead actor: #{meth}" + raise ::Celluloid::DeadActorError, "attempted to call a dead actor: #{meth}" end if @mailbox == ::Thread.current[:celluloid_mailbox] diff --git a/lib/celluloid/rspec.rb b/lib/celluloid/rspec.rb index d1fd3bf0..0d78670c 100644 --- a/lib/celluloid/rspec.rb +++ b/lib/celluloid/rspec.rb @@ -4,23 +4,23 @@ module Specs CHECK_LOOSE_THREADS = false ALLOW_RETRIES = 3 unless defined? ALLOW_RETRIES - INCLUDE_SUPPORT = [ - "logging", - "sleep_and_wait", - "reset_class_variables", - "crash_checking", - "loose_threads", - "stubbing", - "coverage", - "includer", - "configure_rspec" - ] + INCLUDE_SUPPORT = %w( + logging + sleep_and_wait + reset_class_variables + crash_checking + loose_threads + stubbing + coverage + includer + configure_rspec + ).freeze INCLUDE_PATHS = [ "./spec/support/*.rb", "./spec/support/examples/*.rb", "./spec/shared/*.rb" - ] + ].freeze MAX_EXECUTION = 13 MAX_ATTEMPTS = 20 @@ -34,7 +34,7 @@ module Specs "rspec-retry", "rubysl-thread", "rubysl-timeout" - ] + ].freeze end $CELLULOID_DEBUG = true @@ -47,9 +47,9 @@ module Specs # Load shared examples and test support code for other gems to use. -Specs::INCLUDE_SUPPORT.each { |f| +Specs::INCLUDE_SUPPORT.each do |f| require "#{File.expand_path('../../../spec/support', __FILE__)}/#{f}.rb" -} +end Specs.reset_probe(nil) diff --git a/lib/celluloid/system_events.rb b/lib/celluloid/system_events.rb index a74c1d17..ef6d18b3 100644 --- a/lib/celluloid/system_events.rb +++ b/lib/celluloid/system_events.rb @@ -18,7 +18,7 @@ def handle(type) end def handler(&block) - fail ArgumentError, "SystemEvent handlers must be defined with a block." unless block + raise ArgumentError, "SystemEvent handlers must be defined with a block." unless block method = begin handler = name .split("::").last @@ -38,7 +38,7 @@ class LinkingEvent < SystemEvent def initialize(actor, type) @actor = actor @type = type.to_sym - fail ArgumentError, "type must be link or unlink" unless [:link, :unlink].include?(@type) + raise ArgumentError, "type must be link or unlink" unless [:link, :unlink].include?(@type) end end end @@ -97,7 +97,7 @@ def initialize(name) # Request for an actor to terminate class TerminationRequest < SystemEvent - handler do |event| + handler do |_event| terminate end end @@ -110,9 +110,7 @@ def initialize(task, value) end attr_reader :task, :value - handler do |event| - event.call - end + handler(&:call) def call @task.resume(@value) diff --git a/lib/celluloid/task.rb b/lib/celluloid/task.rb index 95877b83..86c9ce47 100644 --- a/lib/celluloid/task.rb +++ b/lib/celluloid/task.rb @@ -3,7 +3,7 @@ module Celluloid class Task # Obtain the current task def self.current - Thread.current[:celluloid_task] || fail(NotTaskError, "not within a task context") + Thread.current[:celluloid_task] || raise(NotTaskError, "not within a task context") end # Suspend the running task, deferring to the scheduler @@ -27,7 +27,7 @@ def initialize(type, meta) actor = Thread.current[:celluloid_actor] @chain_id = Internals::CallChain.current_id - fail NotActorError, "can't create tasks outside of actors" unless actor + raise NotActorError, "can't create tasks outside of actors" unless actor guard "can't create tasks inside of tasks" if Thread.current[:celluloid_task] create do @@ -53,13 +53,13 @@ def initialize(type, meta) end def create(&_block) - fail "Implement #{self.class}#create" + raise "Implement #{self.class}#create" end # Suspend the current task, changing the status to the given argument def suspend(status) - fail "Cannot suspend while in exclusive mode" if exclusive? - fail "Cannot suspend a task from outside of itself" unless Task.current == self + raise "Cannot suspend while in exclusive mode" if exclusive? + raise "Cannot suspend a task from outside of itself" unless Task.current == self @status = status @@ -72,7 +72,7 @@ def suspend(status) value = signal @status = :running - fail value if value.is_a?(Celluloid::Interruption) + raise value if value.is_a?(Celluloid::Interruption) value end @@ -103,7 +103,7 @@ def exclusive # Terminate this task def terminate - fail "Cannot terminate an exclusive task" if exclusive? + raise "Cannot terminate an exclusive task" if exclusive? if running? if $CELLULOID_DEBUG @@ -116,7 +116,7 @@ def terminate exception.set_backtrace(caller) resume exception else - fail DeadTaskError, "task is already dead" + raise DeadTaskError, "task is already dead" end end @@ -142,7 +142,7 @@ def guard(message) if @guard_warnings Internals::Logger.warn message if $CELLULOID_DEBUG else - fail message if $CELLULOID_DEBUG + raise message if $CELLULOID_DEBUG end end diff --git a/lib/celluloid/task/threaded.rb b/lib/celluloid/task/threaded.rb index 80433244..d3b80899 100644 --- a/lib/celluloid/task/threaded.rb +++ b/lib/celluloid/task/threaded.rb @@ -18,7 +18,7 @@ def create thread = Internals::ThreadHandle.new(Thread.current[:celluloid_actor_system], :task) do begin ex = @resume_queue.pop - fail ex if ex.is_a?(TaskTerminated) + raise ex if ex.is_a?(TaskTerminated) yield rescue ::Exception => ex @@ -40,12 +40,12 @@ def signal end def deliver(value) - fail DeadTaskError, "cannot resume a dead task" unless @thread.alive? + raise DeadTaskError, "cannot resume a dead task" unless @thread.alive? @yield_mutex.synchronize do @resume_queue.push(value) @yield_cond.wait(@yield_mutex) - fail @exception_queue.pop while @exception_queue.size > 0 + raise @exception_queue.pop until @exception_queue.empty? end rescue ThreadError raise DeadTaskError, "cannot resume a dead task" diff --git a/lib/celluloid/version.rb b/lib/celluloid/version.rb index 09b422c4..61b9c4b9 100644 --- a/lib/celluloid/version.rb +++ b/lib/celluloid/version.rb @@ -1,3 +1,3 @@ module Celluloid - VERSION = "0.18.0.pre" + VERSION = "0.18.0.pre".freeze end diff --git a/spec/celluloid/block_spec.rb b/spec/celluloid/block_spec.rb index 76d19ef6..bc4bb097 100644 --- a/spec/celluloid/block_spec.rb +++ b/spec/celluloid/block_spec.rb @@ -10,7 +10,7 @@ def initialize(name) def ask_for_something(other) sender_actor = current_actor $data << [:outside, @name, current_actor.name] - other.do_something_and_callback do |value| + other.do_something_and_callback do |_value| $data << [:yielded, @name, current_actor.name] $data << receive_result(:self) $data << current_actor.receive_result(:current_actor) @@ -35,7 +35,7 @@ def defer_for_something(other, &_block) sender_actor = current_actor defer do $data << [:outside, @name, current_actor.name] - other.do_something_and_callback do |value| + other.do_something_and_callback do |_value| $data << [:yielded, @name, current_actor.name] $data << receive_result(:self) $data << current_actor.receive_result(:current_actor) @@ -70,7 +70,7 @@ def receive_result(result) [:self, "one", "one"], [:current_actor, "one", "one"], [:sender, "one", "one"], - :pete_the_polyglot_alien, + :pete_the_polyglot_alien ] expect($data).to eq(expected) @@ -79,7 +79,7 @@ def receive_result(result) execute_deferred = proc do a1 = MyBlockActor.new("one") expect(a1.deferred_excecution(:pete_the_polyglot_alien) { |v| v }) - .to eq(:pete_the_polyglot_alien) + .to eq(:pete_the_polyglot_alien) end # unless RUBY_ENGINE == 'jruby' @@ -105,7 +105,7 @@ def receive_result(result) [:self, "one", "one"], [:current_actor, "one", "one"], [:sender, "one", "one"], - :pete_the_polyglot_alien, + :pete_the_polyglot_alien ] expect($data).to eq(expected) diff --git a/spec/celluloid/calls_spec.rb b/spec/celluloid/calls_spec.rb index 21ec207b..91d79afa 100644 --- a/spec/celluloid/calls_spec.rb +++ b/spec/celluloid/calls_spec.rb @@ -5,27 +5,17 @@ let(:logger) { Specs::FakeLogger.current } context "when obj does not respond to a method" do - # bypass this until rubinius/rubinius#3373 is resolved - # under Rubinius, `method` calls `inspect` on an object when a method is not found - unless RUBY_ENGINE == "rbx" - it "raises a NoMethodError" do - allow(logger).to receive(:crash).with("Actor crashed!", NoMethodError) + it "raises a NoMethodError" do + allow(logger).to receive(:crash).with("Actor crashed!", NoMethodError) - expect do - actor.the_method_that_wasnt_there - end.to raise_exception(NoMethodError) - end + expect do + actor.the_method_that_wasnt_there + end.to raise_exception(NoMethodError) end context "when obj raises during inspect" do it "should emulate obj.inspect" do allow(logger).to receive(:crash).with("Actor crashed!", NoMethodError) - - if RUBY_ENGINE == "rbx" - expected = /undefined method `no_such_method' on an instance of CallExampleActor/ - else - expected = /undefined method `no_such_method' for #\/ - end end end end diff --git a/spec/celluloid/future_spec.rb b/spec/celluloid/future_spec.rb index 3021b8b2..89fa6d9f 100644 --- a/spec/celluloid/future_spec.rb +++ b/spec/celluloid/future_spec.rb @@ -12,7 +12,7 @@ it "reraises exceptions that occur when the value is retrieved" do class ExampleError < StandardError; end - future = Celluloid::Future.new { fail ExampleError, "oh noes crash!" } + future = Celluloid::Future.new { raise ExampleError, "oh noes crash!" } expect { future.value }.to raise_exception(ExampleError) end @@ -35,7 +35,7 @@ class ExampleError < StandardError; end it "cancels future" do future = Celluloid::Future.new { sleep 3600 } - future.cancel(StandardError.new('cancelled')) + future.cancel(StandardError.new("cancelled")) expect { future.value }.to raise_exception(StandardError, "cancelled") end end diff --git a/spec/celluloid/internals/cpu_counter_spec.rb b/spec/celluloid/internals/cpu_counter_spec.rb index 5a52ae61..abcbe7db 100644 --- a/spec/celluloid/internals/cpu_counter_spec.rb +++ b/spec/celluloid/internals/cpu_counter_spec.rb @@ -5,7 +5,7 @@ let(:num_cores) { 1024 } before do - allow(described_class).to receive(:`) { fail "backtick stub called" } + allow(described_class).to receive(:`) { raise "backtick stub called" } allow(::IO).to receive(:open).and_raise("IO.open stub called!") described_class.instance_variable_set(:@cores, nil) end diff --git a/spec/celluloid/mailbox/evented_spec.rb b/spec/celluloid/mailbox/evented_spec.rb index 85eabe65..68cc570a 100644 --- a/spec/celluloid/mailbox/evented_spec.rb +++ b/spec/celluloid/mailbox/evented_spec.rb @@ -16,7 +16,7 @@ timeout_interval = Specs::TIMER_QUANTUM + 0.1 started_at = Time.now expect do - Kernel.send(:timeout, timeout_interval) do + ::Timeout.timeout(timeout_interval) do subject.receive { false } end end.to raise_exception(Timeout::Error) @@ -26,12 +26,12 @@ end it "discard messages when reactor wakeup fails" do - expect(Celluloid::Internals::Logger).to receive(:crash).with('reactor crashed', RuntimeError) + expect(Celluloid::Internals::Logger).to receive(:crash).with("reactor crashed", RuntimeError) expect(Celluloid.logger).to receive(:debug).with("Discarded message (mailbox is dead): first") bad_reactor = Class.new do def wakeup - fail + raise end end mailbox = Celluloid::Mailbox::Evented.new(bad_reactor) diff --git a/spec/celluloid/misc/leak_spec.rb b/spec/celluloid/misc/leak_spec.rb index 3a722ecb..a0c887cd 100644 --- a/spec/celluloid/misc/leak_spec.rb +++ b/spec/celluloid/misc/leak_spec.rb @@ -17,7 +17,7 @@ def terminate end end - def wait_for_release(weak, _what, count=1000) + def wait_for_release(weak, _what, count = 1000) trash = [] count.times do |step| GC.start diff --git a/spec/celluloid/probe_spec.rb b/spec/celluloid/probe_spec.rb index dc842725..8d9e0410 100644 --- a/spec/celluloid/probe_spec.rb +++ b/spec/celluloid/probe_spec.rb @@ -99,70 +99,4 @@ def flush_probe_queue describe ".run" do pending "cannot unsupervise the Probe yet (#573)" end - - describe "after boot" do - it "should send a notification when an actor is spawned" do - Specs.sleep_and_wait_until { Celluloid::Actor[:notifications_fanout].alive? } - - TestProbeClient.new(queue) - a = DummyActor.new - - Celluloid::Probe.run_without_supervision - Specs.sleep_and_wait_until { Celluloid::Actor[:probe_actor].alive? } - - flush_probe_queue - - expect(wait_for_match(queue, "celluloid.events.actor_created", a)).to be - end - - it "should send a notification when an actor is named" do - Specs.sleep_and_wait_until { Celluloid::Actor[:notifications_fanout].alive? } - - TestProbeClient.new(queue) - a = DummyActor.new - Celluloid::Actor["a name"] = a - Specs.sleep_and_wait_until { Celluloid::Actor["a name"] == a } - - Celluloid::Probe.run_without_supervision - Specs.sleep_and_wait_until { Celluloid::Actor[:probe_actor].alive? } - - flush_probe_queue - - expect(wait_for_match(queue, "celluloid.events.actor_named", a)).to be - end - - it "should send a notification when actor dies" do - Specs.sleep_and_wait_until { Celluloid::Actor[:notifications_fanout].alive? } - - TestProbeClient.new(queue) - a = DummyActor.new - a.terminate - Specs.sleep_and_wait_until { !a.alive? } - - Celluloid::Probe.run_without_supervision - Specs.sleep_and_wait_until { Celluloid::Actor[:probe_actor].alive? } - - flush_probe_queue - - expect(wait_for_match(queue, "celluloid.events.actor_died", a)).to be - end - - it "should send a notification when actors are linked" do - Specs.sleep_and_wait_until { Celluloid::Actor[:notifications_fanout].alive? } - - TestProbeClient.new(queue) - a = DummyActor.new - b = DummyActor.new - a.link(b) - - Specs.sleep_and_wait_until { a.linked_to?(b) } - - Celluloid::Probe.run_without_supervision - Specs.sleep_and_wait_until { Celluloid::Actor[:probe_actor].alive? } - - flush_probe_queue - - expect(wait_for_match(queue, "celluloid.events.actors_linked", a, b)).to be - end - end end diff --git a/spec/celluloid/proxy_spec.rb b/spec/celluloid/proxy_spec.rb index b05c42a0..33ab1bd7 100644 --- a/spec/celluloid/proxy_spec.rb +++ b/spec/celluloid/proxy_spec.rb @@ -1,33 +1,33 @@ RSpec.describe Celluloid::Proxy::Abstract do - around do |ex| - Celluloid.boot - ex.run - Celluloid.shutdown - end + around do |ex| + Celluloid.boot + ex.run + Celluloid.shutdown + end - let(:task_klass) { Celluloid.task_class } - let(:actor_class) { ExampleActorClass.create(CelluloidSpecs.included_module, task_klass) } - let(:actor) { actor_class.new "Troy McClure" } + let(:task_klass) { Celluloid.task_class } + let(:actor_class) { ExampleActorClass.create(CelluloidSpecs.included_module, task_klass) } + let(:actor) { actor_class.new "Troy McClure" } - let(:logger) { Specs::FakeLogger.current } - - it "should be eql? to self" do - expect(actor.eql? actor).to be_truthy - end - - it "should be eql? to self even if dead" do - actor.terminate - expect(actor.eql? actor).to be_truthy - end - - it "should not be eql? to other proxy objects" do - other_future = Celluloid::Proxy::Future.new(actor.mailbox, actor.__klass__) - - expect(actor.future.eql? other_future).to be_truthy - end - - it "should be possible to compare with non-proxy objects" do - expect(actor.eql? "string").to be_falsey - expect("string".eql? actor).to be_falsey - end -end \ No newline at end of file + let(:logger) { Specs::FakeLogger.current } + + it "should be eql? to self" do + expect(actor.eql?(actor)).to be_truthy + end + + it "should be eql? to self even if dead" do + actor.terminate + expect(actor.eql?(actor)).to be_truthy + end + + it "should not be eql? to other proxy objects" do + other_future = Celluloid::Proxy::Future.new(actor.mailbox, actor.__klass__) + + expect(actor.future.eql?(other_future)).to be_truthy + end + + it "should be possible to compare with non-proxy objects" do + expect(actor.eql?("string")).to be_falsey + expect("string".eql?(actor)).to be_falsey + end +end diff --git a/spec/shared/actor_examples.rb b/spec/shared/actor_examples.rb index ace7ab58..31e4b8bb 100644 --- a/spec/shared/actor_examples.rb +++ b/spec/shared/actor_examples.rb @@ -22,24 +22,24 @@ true else false - end, + end ).to be_truthy end it "can be stored in hashes" do expect(actor.hash).not_to eq(Kernel.hash) expect(actor.object_id).not_to eq(Kernel.object_id) - expect(actor.eql? actor).to be_truthy + expect(actor.eql?(actor)).to be_truthy end it "can be stored in hashes even when dead" do actor.terminate - + expect(actor.dead?).to be_truthy - + expect(actor.hash).not_to eq(Kernel.hash) expect(actor.object_id).not_to eq(Kernel.object_id) - expect(actor.eql? actor).to be_truthy + expect(actor.eql?(actor)).to be_truthy end it "implements respond_to? correctly" do @@ -418,7 +418,7 @@ def name_inside_task include CelluloidSpecs.included_module define_method(:receiver_method) do - fail ExampleCrash, "the spec purposely crashed me :(" + raise ExampleCrash, "the spec purposely crashed me :(" end end.new @@ -435,7 +435,11 @@ def name_inside_task it "raises DeadActorError if methods are synchronously called on a dead actor" do allow(logger).to receive(:crash).with("Actor crashed!", ExampleCrash) - actor.crash rescue ExampleCrash + begin + actor.crash + rescue + ExampleCrash + end # TODO: avoid this somehow sleep 0.1 # hax to prevent a race between exit handling and the next call @@ -588,9 +592,9 @@ def subordinate_lambasted? @subordinate_lambasted end - def lambaste_subordinate(_actor, _reason) + def lambaste_subordinate(_actor, reason) @subordinate_lambasted = true - @exception = _reason + @exception = reason end end end @@ -698,7 +702,7 @@ def initialize end def wait_for_signal - fail "already signaled" if @signaled + raise "already signaled" if @signaled @waiting = true value = wait :ponycopter @@ -1096,7 +1100,7 @@ def subclass_proxy? klass = Class.new(Celluloid::Proxy::Cell) do def dividing_3_by(number) - fail ArgumentError, "" if number.zero? + raise ArgumentError, "" if number.zero? super end end @@ -1115,7 +1119,11 @@ def dividing_3_by(number) end it "does not crash the actor" do - subject.dividing_3_by(0) rescue ArgumentError + begin + subject.dividing_3_by(0) + rescue + ArgumentError + end expect(subject.dividing_3_by(3)).to eq(1) end end @@ -1135,7 +1143,7 @@ def method_missing(meth, *args) mandatory_args = -arity - 1 unmet_requirement = "#{mandatory_args}+" if args.size < mandatory_args end - fail ArgumentError, "wrong number of arguments (#{args.size} for #{unmet_requirement})" if unmet_requirement + raise ArgumentError, "wrong number of arguments (#{args.size} for #{unmet_requirement})" if unmet_requirement super end @@ -1154,7 +1162,7 @@ def madness end def this_is_not_madness(word1, word2, word3, *_args) - fail "This is madness!" unless [word1, word2, word3] == [:this, :is, :Sparta] + raise "This is madness!" unless [word1, word2, word3] == [:this, :is, :Sparta] end proxy_class klass @@ -1167,7 +1175,11 @@ def this_is_not_madness(word1, word2, word3, *_args) end it "does not crash the actor" do - subject.method_to_madness rescue NoMethodError + begin + subject.method_to_madness + rescue + NoMethodError + end expect(subject.madness).to eq("This is madness!") end end @@ -1179,7 +1191,11 @@ def this_is_not_madness(word1, word2, word3, *_args) end it "does not crash the actor" do - subject.madness(:Sparta) rescue ArgumentError + begin + subject.madness(:Sparta) + rescue + ArgumentError + end expect(subject.madness).to eq("This is madness!") end end diff --git a/spec/shared/group_examples.rb b/spec/shared/group_examples.rb index d2451cb3..fdcfe6c7 100644 --- a/spec/shared/group_examples.rb +++ b/spec/shared/group_examples.rb @@ -35,7 +35,7 @@ def wait_until_idle subject.get do busy_queue << nil @wait_queue.pop - fail exception_class, "Error" + raise exception_class, "Error" end wait_until_busy(busy_queue) @@ -89,7 +89,7 @@ def wait_until_idle subject.get do thread << Thread.current sleep - end, + end ).to be_a(Celluloid::Thread) thread.pop # wait for 3rd-party thread to get strated diff --git a/spec/shared/stack_examples.rb b/spec/shared/stack_examples.rb index 0dfb9c22..27472b3a 100644 --- a/spec/shared/stack_examples.rb +++ b/spec/shared/stack_examples.rb @@ -68,7 +68,7 @@ # Pool somehow doesn't create extra tasks # 5 is on JRuby-head - expected = (Celluloid.group_class == Celluloid::Group::Pool) ? [3, 4] : [3, 4, 5, 6] + expected = Celluloid.group_class == Celluloid::Group::Pool ? [3, 4] : [3, 4, 5, 6] expect(expected).to include(subject.threads.size) end diff --git a/spec/shared/task_examples.rb b/spec/shared/task_examples.rb index 0c737a10..7db291f5 100644 --- a/spec/shared/task_examples.rb +++ b/spec/shared/task_examples.rb @@ -41,7 +41,7 @@ def setup_thread it "raises exceptions outside" do task = Celluloid.task_class.new(task_type, {}) do - fail "failure" + raise "failure" end expect do task.resume diff --git a/spec/support/configure_rspec.rb b/spec/support/configure_rspec.rb index f1f4c382..215c98e1 100644 --- a/spec/support/configure_rspec.rb +++ b/spec/support/configure_rspec.rb @@ -18,7 +18,7 @@ config.before(:suite) do Specs.stub_out_class_method(Celluloid::Internals::Logger, :crash) do |*args| _name, ex = *args - fail "Unstubbed Logger.crash() was called:\n crash(\n #{args.map(&:inspect).join(",\n ")})"\ + raise "Unstubbed Logger.crash() was called:\n crash(\n #{args.map(&:inspect).join(",\n ")})"\ "\nException backtrace: \n (#{ex.class}) #{ex.backtrace * "\n (#{ex.class}) "}" end end @@ -41,7 +41,7 @@ "\n** Crash: #{msg.inspect}(#{ex.inspect})\n Backtrace:\n (crash) #{call_stack * "\n (crash) "}"\ "\n Exception Backtrace (#{ex.inspect}):\n (ex) #{ex.backtrace * "\n (ex) "}" end.join("\n") - fail "Actor crashes occured (please stub/mock if these are expected): #{crashes}" + raise "Actor crashes occured (please stub/mock if these are expected): #{crashes}" end @fake_logger = nil Specs.assert_no_loose_threads!("after example: #{ex.description}") if Specs::CHECK_LOOSE_THREADS diff --git a/spec/support/crash_checking.rb b/spec/support/crash_checking.rb index 9a28bfc9..cde0d1fe 100644 --- a/spec/support/crash_checking.rb +++ b/spec/support/crash_checking.rb @@ -19,7 +19,7 @@ def initialize(real_logger, example) def crash(*args) check - fail "Testing block has already ended!" if @details + raise "Testing block has already ended!" if @details @crashes << [args, caller.dup] end @@ -59,7 +59,7 @@ def crashes? def check return if self.class.allowed_logger.first == self - fail "Incorrect logger used:"\ + raise "Incorrect logger used:"\ " active/allowed: \n#{clas.allowed_logger.inspect},\n"\ " actual/self: \n#{[self, @example].inspect}\n"\ " (maybe an actor from another test is still running?)" diff --git a/spec/support/examples/actor_class.rb b/spec/support/examples/actor_class.rb index 0987db3f..801369f7 100644 --- a/spec/support/examples/actor_class.rb +++ b/spec/support/examples/actor_class.rb @@ -45,7 +45,7 @@ def run_on_receiver(*args) end def crash - fail ExampleCrash, "the spec purposely crashed me :(" + raise ExampleCrash, "the spec purposely crashed me :(" end def crash_with_abort(reason, foo = nil) diff --git a/spec/support/examples/call_class.rb b/spec/support/examples/call_class.rb index d837940c..e9980262 100644 --- a/spec/support/examples/call_class.rb +++ b/spec/support/examples/call_class.rb @@ -8,7 +8,7 @@ def initialize(next_actor = nil) def actual_method; end def inspect - fail "Don't call!" + raise "Don't call!" end def chained_call_ids @@ -28,7 +28,7 @@ def initialize(next_actor = nil) def actual_method; end def inspect - fail "Please don't call me! I'm not ready yet!" + raise "Please don't call me! I'm not ready yet!" end def chained_call_ids diff --git a/spec/support/loose_threads.rb b/spec/support/loose_threads.rb index e38920e1..a047930c 100644 --- a/spec/support/loose_threads.rb +++ b/spec/support/loose_threads.rb @@ -39,7 +39,7 @@ def loose_threads end def thread_name(thread) - (RUBY_PLATFORM == "java") ? thread.to_java.getNativeThread.get_name : "" + RUBY_PLATFORM == "java" ? thread.to_java.getNativeThread.get_name : "" end def assert_no_loose_threads!(location) @@ -61,7 +61,7 @@ def assert_no_loose_threads!(location) sleep end - fail Celluloid::ThreadLeak, "Aborted due to runaway threads (#{location})\n"\ + raise Celluloid::ThreadLeak, "Aborted due to runaway threads (#{location})\n"\ "List: (#{loose.map(&:inspect)})\n:#{backtraces.join("\n")}" end end diff --git a/spec/support/reset_class_variables.rb b/spec/support/reset_class_variables.rb index f2fbdb4b..bc149795 100644 --- a/spec/support/reset_class_variables.rb +++ b/spec/support/reset_class_variables.rb @@ -2,7 +2,7 @@ module Specs class << self def reset_class_variables(description) # build uuid from example ending (most unique) - uuid_prefix = description[-([description.size, 20].min)..-1] + uuid_prefix = description[-[description.size, 20].min..-1] reset_uuid(uuid_prefix) reset_probe(Queue.new) diff --git a/spec/support/stubbing.rb b/spec/support/stubbing.rb index a5d2408b..b4a7db92 100644 --- a/spec/support/stubbing.rb +++ b/spec/support/stubbing.rb @@ -3,7 +3,7 @@ def self.stub_out_class_method(mod, meth) meta = (class << mod; self; end) original_meth = "original_#{meth}".to_sym - fail "ALREADY TRACED: #{mod}.#{meth}" if mod.respond_to?(original_meth) + raise "ALREADY TRACED: #{mod}.#{meth}" if mod.respond_to?(original_meth) meta.send(:alias_method, original_meth, meth) meta.send(:define_method, meth) do |*args, &block| diff --git a/tasks/benchmarks.rake b/tasks/benchmarks.rake index e2680f24..5155c903 100644 --- a/tasks/benchmarks.rake +++ b/tasks/benchmarks.rake @@ -1,4 +1,5 @@ require "timeout" +require "celluloid/autostart" desc "Run Celluloid benchmarks" task :benchmark do diff --git a/tasks/rubocop.rake b/tasks/rubocop.rake index 135522b1..e94541b6 100644 --- a/tasks/rubocop.rake +++ b/tasks/rubocop.rake @@ -1,4 +1,2 @@ -unless ENV["CI"] - require "rubocop/rake_task" - RuboCop::RakeTask.new -end +require "rubocop/rake_task" +RuboCop::RakeTask.new