celluloid 0.18.0.pre → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGES.md +258 -39
- data/CONDUCT.md +13 -0
- data/CONTRIBUTING.md +39 -0
- data/README.md +54 -165
- data/REFACTOR.md +1 -0
- data/architecture.md +120 -0
- data/examples/basic_usage.rb +1 -1
- data/examples/configurations.rb +78 -0
- data/examples/futures.rb +1 -1
- data/examples/ring.rb +5 -4
- data/examples/simple_pmap.rb +1 -1
- data/examples/stack.rb +2 -2
- data/examples/supervisors_and_registry.rb +82 -0
- data/examples/timers.rb +2 -2
- data/lib/celluloid.rb +72 -47
- data/lib/celluloid/actor.rb +27 -17
- data/lib/celluloid/actor/system.rb +13 -29
- data/lib/celluloid/autostart.rb +5 -5
- data/lib/celluloid/call/async.rb +2 -0
- data/lib/celluloid/call/sync.rb +10 -3
- data/lib/celluloid/calls.rb +5 -12
- data/lib/celluloid/cell.rb +5 -9
- data/lib/celluloid/condition.rb +3 -3
- data/lib/celluloid/core_ext.rb +0 -2
- data/lib/celluloid/debug.rb +3 -0
- data/lib/celluloid/exceptions.rb +2 -2
- data/lib/celluloid/future.rb +7 -9
- data/lib/celluloid/group.rb +12 -8
- data/lib/celluloid/group/pool.rb +1 -3
- data/lib/celluloid/group/spawner.rb +2 -6
- data/lib/celluloid/internals/call_chain.rb +15 -0
- data/lib/celluloid/internals/cpu_counter.rb +62 -0
- data/lib/celluloid/internals/handlers.rb +42 -0
- data/lib/celluloid/internals/links.rb +38 -0
- data/lib/celluloid/internals/logger.rb +104 -0
- data/lib/celluloid/internals/method.rb +34 -0
- data/lib/celluloid/internals/properties.rb +32 -0
- data/lib/celluloid/internals/receivers.rb +64 -0
- data/lib/celluloid/internals/registry.rb +102 -0
- data/lib/celluloid/internals/responses.rb +46 -0
- data/lib/celluloid/internals/signals.rb +24 -0
- data/lib/celluloid/internals/stack.rb +74 -0
- data/lib/celluloid/internals/stack/dump.rb +12 -0
- data/lib/celluloid/internals/stack/states.rb +72 -0
- data/lib/celluloid/internals/stack/summary.rb +12 -0
- data/lib/celluloid/internals/task_set.rb +51 -0
- data/lib/celluloid/internals/thread_handle.rb +52 -0
- data/lib/celluloid/internals/uuid.rb +40 -0
- data/lib/celluloid/logging/incident.rb +21 -0
- data/lib/celluloid/logging/incident_logger.rb +147 -0
- data/lib/celluloid/logging/incident_reporter.rb +49 -0
- data/lib/celluloid/logging/log_event.rb +20 -0
- data/lib/celluloid/logging/ring_buffer.rb +64 -0
- data/lib/celluloid/mailbox.rb +22 -9
- data/lib/celluloid/mailbox/evented.rb +13 -5
- data/lib/celluloid/notifications.rb +95 -0
- data/lib/celluloid/pool.rb +6 -0
- data/lib/celluloid/probe.rb +81 -0
- data/lib/celluloid/proxy/abstract.rb +9 -9
- data/lib/celluloid/proxy/async.rb +1 -1
- data/lib/celluloid/proxy/block.rb +2 -2
- data/lib/celluloid/proxy/cell.rb +1 -1
- data/lib/celluloid/proxy/future.rb +2 -4
- data/lib/celluloid/proxy/sync.rb +1 -3
- data/lib/celluloid/rspec.rb +22 -33
- data/lib/celluloid/supervision.rb +17 -0
- data/lib/celluloid/supervision/configuration.rb +169 -0
- data/lib/celluloid/supervision/configuration/injections.rb +8 -0
- data/lib/celluloid/supervision/configuration/instance.rb +113 -0
- data/lib/celluloid/supervision/constants.rb +123 -0
- data/lib/celluloid/supervision/container.rb +144 -0
- data/lib/celluloid/supervision/container/behavior.rb +89 -0
- data/lib/celluloid/supervision/container/behavior/pool.rb +71 -0
- data/lib/celluloid/supervision/container/behavior/tree.rb +23 -0
- data/lib/celluloid/supervision/container/injections.rb +8 -0
- data/lib/celluloid/supervision/container/instance.rb +116 -0
- data/lib/celluloid/supervision/container/pool.rb +210 -0
- data/lib/celluloid/supervision/service.rb +27 -0
- data/lib/celluloid/supervision/supervise.rb +34 -0
- data/lib/celluloid/supervision/validation.rb +40 -0
- data/lib/celluloid/supervision/version.rb +5 -0
- data/lib/celluloid/system_events.rb +11 -6
- data/lib/celluloid/task.rb +25 -12
- data/lib/celluloid/task/fibered.rb +2 -0
- data/lib/celluloid/task/threaded.rb +3 -3
- data/lib/celluloid/test.rb +5 -2
- data/lib/celluloid/thread.rb +0 -2
- data/lib/celluloid/version.rb +1 -1
- data/spec/celluloid/block_spec.rb +29 -32
- data/spec/celluloid/calls_spec.rb +5 -15
- data/spec/celluloid/future_spec.rb +2 -2
- data/spec/celluloid/internals/cpu_counter_spec.rb +129 -0
- data/spec/celluloid/internals/links_spec.rb +43 -0
- data/spec/celluloid/internals/properties_spec.rb +40 -0
- data/spec/celluloid/internals/registry_spec.rb +62 -0
- data/spec/celluloid/internals/stack/dump_spec.rb +4 -0
- data/spec/celluloid/internals/stack/summary_spec.rb +4 -0
- data/spec/celluloid/internals/thread_handle_spec.rb +60 -0
- data/spec/celluloid/internals/uuid_spec.rb +9 -0
- data/spec/celluloid/logging/ring_buffer_spec.rb +36 -0
- data/spec/celluloid/mailbox/evented_spec.rb +11 -22
- data/spec/celluloid/misc/leak_spec.rb +3 -4
- data/spec/celluloid/notifications_spec.rb +140 -0
- data/spec/celluloid/probe_spec.rb +102 -0
- data/spec/celluloid/proxy_spec.rb +30 -30
- data/spec/celluloid/supervision/behavior_spec.rb +74 -0
- data/spec/celluloid/supervision/configuration_spec.rb +181 -0
- data/spec/celluloid/supervision/container_spec.rb +72 -0
- data/spec/celluloid/supervision/instance_spec.rb +13 -0
- data/spec/celluloid/supervision/root_spec.rb +28 -0
- data/spec/celluloid/supervision/supervisor_spec.rb +93 -0
- data/spec/celluloid/task/fibered_spec.rb +1 -3
- data/spec/celluloid/task/threaded_spec.rb +1 -3
- data/spec/shared/actor_examples.rb +58 -33
- data/spec/shared/group_examples.rb +2 -2
- data/spec/shared/mailbox_examples.rb +1 -1
- data/spec/shared/stack_examples.rb +87 -0
- data/spec/shared/task_examples.rb +2 -3
- data/spec/spec_helper.rb +2 -4
- data/spec/support/configure_rspec.rb +2 -3
- data/spec/support/coverage.rb +2 -4
- data/spec/support/crash_checking.rb +2 -2
- data/spec/support/examples/actor_class.rb +3 -8
- data/spec/support/examples/call_class.rb +2 -2
- data/spec/support/examples/container_class.rb +35 -0
- data/spec/support/examples/evented_mailbox_class.rb +1 -2
- data/spec/support/examples/stack_classes.rb +58 -0
- data/spec/support/examples/stack_methods.rb +23 -0
- data/spec/support/examples/subordinate_class.rb +19 -0
- data/spec/support/logging.rb +2 -34
- data/spec/support/loose_threads.rb +3 -16
- data/spec/support/reset_class_variables.rb +5 -1
- data/spec/support/stubbing.rb +1 -1
- metadata +91 -323
- data/culture/CONDUCT.md +0 -38
- data/culture/GSoC/1010-why_we_will_participate.md +0 -17
- data/culture/GSoC/1020-how_mentors_stay_engaged.md +0 -7
- data/culture/GSoC/1030-keeping_students_on_schedule.md +0 -9
- data/culture/GSoC/1040-getting_students_involved.md +0 -5
- data/culture/GSoC/1050-student_involvement_after.md +0 -5
- data/culture/GSoC/README.md +0 -16
- data/culture/Gemfile +0 -9
- data/culture/LICENSE.txt +0 -22
- data/culture/README.md +0 -22
- data/culture/Rakefile +0 -5
- data/culture/SYNC.md +0 -70
- data/culture/celluloid-culture.gemspec +0 -18
- data/culture/gems/README.md +0 -39
- data/culture/gems/dependencies.yml +0 -93
- data/culture/gems/loader.rb +0 -101
- data/culture/rubocop/README.md +0 -38
- data/culture/rubocop/lint.yml +0 -8
- data/culture/rubocop/metrics.yml +0 -15
- data/culture/rubocop/perf.yml +0 -0
- data/culture/rubocop/rubocop.yml +0 -5
- data/culture/rubocop/style.yml +0 -61
- data/culture/spec/gems_spec.rb +0 -2
- data/culture/spec/spec_helper.rb +0 -0
- data/culture/spec/sync_spec.rb +0 -2
- data/culture/sync.rb +0 -56
- data/culture/tasks/rspec.rake +0 -5
- data/culture/tasks/rubocop.rake +0 -2
- data/lib/celluloid/actor/manager.rb +0 -7
- data/lib/celluloid/backported.rb +0 -2
- data/lib/celluloid/current.rb +0 -2
- data/lib/celluloid/deprecate.rb +0 -34
- data/lib/celluloid/fiber.rb +0 -32
- data/lib/celluloid/managed.rb +0 -3
- data/lib/celluloid/notices.rb +0 -15
- data/spec/deprecate/actor_system_spec.rb +0 -72
- data/spec/deprecate/block_spec.rb +0 -52
- data/spec/deprecate/calls_spec.rb +0 -39
- data/spec/deprecate/evented_mailbox_spec.rb +0 -34
- data/spec/deprecate/future_spec.rb +0 -32
- data/spec/deprecate/internal_pool_spec.rb +0 -4
- data/spec/support/env.rb +0 -21
@@ -5,7 +5,10 @@ module Celluloid
|
|
5
5
|
if handler = SystemEvent.handle(event.class)
|
6
6
|
send(handler, event)
|
7
7
|
else
|
8
|
+
# !!! DO NOT INTRODUCE ADDITIONAL GLOBAL VARIABLES !!!
|
9
|
+
# rubocop:disable Style/GlobalVars
|
8
10
|
Internals::Logger.debug "Discarded message (unhandled): #{message}" if $CELLULOID_DEBUG
|
11
|
+
# rubocop:enable Style/GlobalVars
|
9
12
|
end
|
10
13
|
end
|
11
14
|
end
|
@@ -18,7 +21,7 @@ module Celluloid
|
|
18
21
|
end
|
19
22
|
|
20
23
|
def handler(&block)
|
21
|
-
|
24
|
+
raise ArgumentError, "SystemEvent handlers must be defined with a block." unless block
|
22
25
|
method = begin
|
23
26
|
handler = name
|
24
27
|
.split("::").last
|
@@ -38,7 +41,7 @@ module Celluloid
|
|
38
41
|
def initialize(actor, type)
|
39
42
|
@actor = actor
|
40
43
|
@type = type.to_sym
|
41
|
-
|
44
|
+
raise ArgumentError, "type must be link or unlink" unless %i[link unlink].include?(@type)
|
42
45
|
end
|
43
46
|
end
|
44
47
|
end
|
@@ -87,7 +90,11 @@ module Celluloid
|
|
87
90
|
|
88
91
|
handler do |event|
|
89
92
|
@name = event.name
|
93
|
+
|
94
|
+
# !!! DO NOT INTRODUCE ADDITIONAL GLOBAL VARIABLES !!!
|
95
|
+
# rubocop:disable Style/GlobalVars
|
90
96
|
Celluloid::Probe.actor_named(self) if $CELLULOID_MONITORING
|
97
|
+
# rubocop:enable Style/GlobalVars
|
91
98
|
end
|
92
99
|
|
93
100
|
def initialize(name)
|
@@ -97,7 +104,7 @@ module Celluloid
|
|
97
104
|
|
98
105
|
# Request for an actor to terminate
|
99
106
|
class TerminationRequest < SystemEvent
|
100
|
-
handler do |
|
107
|
+
handler do |_event|
|
101
108
|
terminate
|
102
109
|
end
|
103
110
|
end
|
@@ -110,9 +117,7 @@ module Celluloid
|
|
110
117
|
end
|
111
118
|
attr_reader :task, :value
|
112
119
|
|
113
|
-
handler
|
114
|
-
event.call
|
115
|
-
end
|
120
|
+
handler(&:call)
|
116
121
|
|
117
122
|
def call
|
118
123
|
@task.resume(@value)
|
data/lib/celluloid/task.rb
CHANGED
@@ -3,7 +3,7 @@ module Celluloid
|
|
3
3
|
class Task
|
4
4
|
# Obtain the current task
|
5
5
|
def self.current
|
6
|
-
Thread.current[:celluloid_task] ||
|
6
|
+
Thread.current[:celluloid_task] || raise(NotTaskError, "not within a task context")
|
7
7
|
end
|
8
8
|
|
9
9
|
# Suspend the running task, deferring to the scheduler
|
@@ -27,7 +27,7 @@ module Celluloid
|
|
27
27
|
actor = Thread.current[:celluloid_actor]
|
28
28
|
@chain_id = Internals::CallChain.current_id
|
29
29
|
|
30
|
-
|
30
|
+
raise NotActorError, "can't create tasks outside of actors" unless actor
|
31
31
|
guard "can't create tasks inside of tasks" if Thread.current[:celluloid_task]
|
32
32
|
|
33
33
|
create do
|
@@ -53,26 +53,29 @@ module Celluloid
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def create(&_block)
|
56
|
-
|
56
|
+
raise "Implement #{self.class}#create"
|
57
57
|
end
|
58
58
|
|
59
59
|
# Suspend the current task, changing the status to the given argument
|
60
60
|
def suspend(status)
|
61
|
-
|
62
|
-
|
61
|
+
raise "Cannot suspend while in exclusive mode" if exclusive?
|
62
|
+
raise "Cannot suspend a task from outside of itself" unless Task.current == self
|
63
63
|
|
64
64
|
@status = status
|
65
65
|
|
66
|
+
# !!! DO NOT INTRODUCE ADDITIONAL GLOBAL VARIABLES !!!
|
67
|
+
# rubocop:disable Style/GlobalVars
|
66
68
|
if $CELLULOID_DEBUG && @dangerous_suspend
|
67
69
|
Internals::Logger.with_backtrace(caller[2...8]) do |logger|
|
68
70
|
logger.warn "Dangerously suspending task: type=#{@type.inspect}, meta=#{@meta.inspect}, status=#{@status.inspect}"
|
69
71
|
end
|
70
72
|
end
|
73
|
+
# rubocop:enable Style/GlobalVars
|
71
74
|
|
72
75
|
value = signal
|
73
76
|
|
74
77
|
@status = :running
|
75
|
-
|
78
|
+
raise value if value.is_a?(Celluloid::Interruption)
|
76
79
|
value
|
77
80
|
end
|
78
81
|
|
@@ -82,7 +85,9 @@ module Celluloid
|
|
82
85
|
if running?
|
83
86
|
deliver(value)
|
84
87
|
else
|
88
|
+
# rubocop:disable Metrics/LineLength
|
85
89
|
Internals::Logger.warn "Attempted to resume a dead task: type=#{@type.inspect}, meta=#{@meta.inspect}, status=#{@status.inspect}"
|
90
|
+
# rubocop:enable Metrics/LineLength
|
86
91
|
end
|
87
92
|
nil
|
88
93
|
end
|
@@ -103,20 +108,24 @@ module Celluloid
|
|
103
108
|
|
104
109
|
# Terminate this task
|
105
110
|
def terminate
|
106
|
-
|
111
|
+
raise "Cannot terminate an exclusive task" if exclusive?
|
107
112
|
|
108
113
|
if running?
|
114
|
+
# !!! DO NOT INTRODUCE ADDITIONAL GLOBAL VARIABLES !!!
|
115
|
+
# rubocop:disable Style/GlobalVars
|
109
116
|
if $CELLULOID_DEBUG
|
110
117
|
Internals::Logger.with_backtrace(backtrace) do |logger|
|
111
118
|
type = @dangerous_suspend ? :warn : :debug
|
112
119
|
logger.send(type, "Terminating task: type=#{@type.inspect}, meta=#{@meta.inspect}, status=#{@status.inspect}")
|
113
120
|
end
|
114
121
|
end
|
122
|
+
# rubocop:enable Style/GlobalVars
|
123
|
+
|
115
124
|
exception = TaskTerminated.new("task was terminated")
|
116
125
|
exception.set_backtrace(caller)
|
117
126
|
resume exception
|
118
127
|
else
|
119
|
-
|
128
|
+
raise DeadTaskError, "task is already dead"
|
120
129
|
end
|
121
130
|
end
|
122
131
|
|
@@ -125,8 +134,7 @@ module Celluloid
|
|
125
134
|
@exclusive
|
126
135
|
end
|
127
136
|
|
128
|
-
def backtrace
|
129
|
-
end
|
137
|
+
def backtrace; end
|
130
138
|
|
131
139
|
# Is the current task still running?
|
132
140
|
def running?
|
@@ -139,11 +147,14 @@ module Celluloid
|
|
139
147
|
end
|
140
148
|
|
141
149
|
def guard(message)
|
150
|
+
# !!! DO NOT INTRODUCE ADDITIONAL GLOBAL VARIABLES !!!
|
151
|
+
# rubocop:disable Style/GlobalVars
|
142
152
|
if @guard_warnings
|
143
153
|
Internals::Logger.warn message if $CELLULOID_DEBUG
|
144
154
|
else
|
145
|
-
|
155
|
+
raise message if $CELLULOID_DEBUG
|
146
156
|
end
|
157
|
+
# rubocop:enable Style/GlobalVars
|
147
158
|
end
|
148
159
|
|
149
160
|
private
|
@@ -161,7 +172,9 @@ module Celluloid
|
|
161
172
|
|
162
173
|
def thread_metadata
|
163
174
|
method = @meta && @meta[:method_name] || "<no method>"
|
164
|
-
klass = Thread.current[:celluloid_actor] &&
|
175
|
+
klass = Thread.current[:celluloid_actor] &&
|
176
|
+
Thread.current[:celluloid_actor].behavior.subject.bare_object.class ||
|
177
|
+
"<no actor>"
|
165
178
|
format("[Celluloid] %s#%s", klass, method)
|
166
179
|
end
|
167
180
|
end
|
@@ -40,7 +40,9 @@ module Celluloid
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def backtrace
|
43
|
+
# rubocop:disable Metrics/LineLength
|
43
44
|
["#{self.class} backtrace unavailable. Please try `Celluloid.task_class = Celluloid::Task::Threaded` if you need backtraces here."]
|
45
|
+
# rubocop:enable Metrics/LineLength
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
@@ -18,7 +18,7 @@ module Celluloid
|
|
18
18
|
thread = Internals::ThreadHandle.new(Thread.current[:celluloid_actor_system], :task) do
|
19
19
|
begin
|
20
20
|
ex = @resume_queue.pop
|
21
|
-
|
21
|
+
raise ex if ex.is_a?(TaskTerminated)
|
22
22
|
|
23
23
|
yield
|
24
24
|
rescue ::Exception => ex
|
@@ -40,12 +40,12 @@ module Celluloid
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def deliver(value)
|
43
|
-
|
43
|
+
raise DeadTaskError, "cannot resume a dead task" unless @thread.alive?
|
44
44
|
|
45
45
|
@yield_mutex.synchronize do
|
46
46
|
@resume_queue.push(value)
|
47
47
|
@yield_cond.wait(@yield_mutex)
|
48
|
-
|
48
|
+
raise @exception_queue.pop until @exception_queue.empty?
|
49
49
|
end
|
50
50
|
rescue ThreadError
|
51
51
|
raise DeadTaskError, "cannot resume a dead task"
|
data/lib/celluloid/test.rb
CHANGED
data/lib/celluloid/thread.rb
CHANGED
data/lib/celluloid/version.rb
CHANGED
@@ -2,19 +2,20 @@ RSpec.describe "Blocks", actor_system: :global do
|
|
2
2
|
class MyBlockActor
|
3
3
|
include Celluloid
|
4
4
|
|
5
|
-
def initialize(name)
|
5
|
+
def initialize(name, data)
|
6
6
|
@name = name
|
7
|
+
@data = data
|
7
8
|
end
|
8
9
|
attr_reader :name
|
9
10
|
|
10
11
|
def ask_for_something(other)
|
11
12
|
sender_actor = current_actor
|
12
|
-
|
13
|
-
other.do_something_and_callback do |
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
@data << [:outside, @name, current_actor.name]
|
14
|
+
other.do_something_and_callback do |_value|
|
15
|
+
@data << [:yielded, @name, current_actor.name]
|
16
|
+
@data << receive_result(:self)
|
17
|
+
@data << current_actor.receive_result(:current_actor)
|
18
|
+
@data << sender_actor.receive_result(:sender)
|
18
19
|
:pete_the_polyglot_alien
|
19
20
|
end
|
20
21
|
end
|
@@ -34,20 +35,20 @@ RSpec.describe "Blocks", actor_system: :global do
|
|
34
35
|
def defer_for_something(other, &_block)
|
35
36
|
sender_actor = current_actor
|
36
37
|
defer do
|
37
|
-
|
38
|
-
other.do_something_and_callback do |
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
@data << [:outside, @name, current_actor.name]
|
39
|
+
other.do_something_and_callback do |_value|
|
40
|
+
@data << [:yielded, @name, current_actor.name]
|
41
|
+
@data << receive_result(:self)
|
42
|
+
@data << current_actor.receive_result(:current_actor)
|
43
|
+
@data << sender_actor.receive_result(:sender)
|
43
44
|
:pete_the_polyglot_alien
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
49
|
def do_something_and_callback
|
49
|
-
|
50
|
-
|
50
|
+
@data << [:something, @name, current_actor.name]
|
51
|
+
@data << yield(:foo)
|
51
52
|
end
|
52
53
|
|
53
54
|
def receive_result(result)
|
@@ -56,10 +57,10 @@ RSpec.describe "Blocks", actor_system: :global do
|
|
56
57
|
end
|
57
58
|
|
58
59
|
it "work between actors" do
|
59
|
-
|
60
|
+
data = []
|
60
61
|
|
61
|
-
a1 = MyBlockActor.new("one")
|
62
|
-
a2 = MyBlockActor.new("two")
|
62
|
+
a1 = MyBlockActor.new("one", data)
|
63
|
+
a2 = MyBlockActor.new("two", data)
|
63
64
|
|
64
65
|
a1.ask_for_something a2
|
65
66
|
|
@@ -70,33 +71,29 @@ RSpec.describe "Blocks", actor_system: :global do
|
|
70
71
|
[:self, "one", "one"],
|
71
72
|
[:current_actor, "one", "one"],
|
72
73
|
[:sender, "one", "one"],
|
73
|
-
:pete_the_polyglot_alien
|
74
|
+
:pete_the_polyglot_alien
|
74
75
|
]
|
75
76
|
|
76
|
-
expect(
|
77
|
+
expect(data).to eq(expected)
|
77
78
|
end
|
78
79
|
|
79
80
|
execute_deferred = proc do
|
80
|
-
a1 = MyBlockActor.new("one")
|
81
|
+
a1 = MyBlockActor.new("one", [])
|
81
82
|
expect(a1.deferred_excecution(:pete_the_polyglot_alien) { |v| v })
|
82
|
-
|
83
|
+
.to eq(:pete_the_polyglot_alien)
|
83
84
|
end
|
84
85
|
|
85
|
-
# unless RUBY_ENGINE == 'jruby'
|
86
86
|
xit("can be deferred", &execute_deferred)
|
87
|
-
# else
|
88
|
-
# it("can be deferred", &execute_deferred)
|
89
|
-
# end
|
90
87
|
|
91
88
|
xit "can execute deferred blocks referencing current_actor" do
|
92
|
-
a1 = MyBlockActor.new("one")
|
89
|
+
a1 = MyBlockActor.new("one", [])
|
93
90
|
expect(a1.deferred_current_actor { |v| v }).to be("one")
|
94
91
|
end
|
95
92
|
|
96
93
|
xit "can execute deferred blocks with another actor" do
|
97
|
-
|
98
|
-
a1 = MyBlockActor.new("one")
|
99
|
-
a2 = MyBlockActor.new("two")
|
94
|
+
data = []
|
95
|
+
a1 = MyBlockActor.new("one", data)
|
96
|
+
a2 = MyBlockActor.new("two", data)
|
100
97
|
a1.defer_for_something a2
|
101
98
|
expected = [
|
102
99
|
[:outside, "one", "one"],
|
@@ -105,9 +102,9 @@ RSpec.describe "Blocks", actor_system: :global do
|
|
105
102
|
[:self, "one", "one"],
|
106
103
|
[:current_actor, "one", "one"],
|
107
104
|
[:sender, "one", "one"],
|
108
|
-
:pete_the_polyglot_alien
|
105
|
+
:pete_the_polyglot_alien
|
109
106
|
]
|
110
107
|
|
111
|
-
expect(
|
108
|
+
expect(data).to eq(expected)
|
112
109
|
end
|
113
110
|
end
|
@@ -5,27 +5,17 @@ RSpec.describe Celluloid::Call::Sync, actor_system: :global do
|
|
5
5
|
let(:logger) { Specs::FakeLogger.current }
|
6
6
|
|
7
7
|
context "when obj does not respond to a method" do
|
8
|
-
|
9
|
-
|
10
|
-
unless RUBY_ENGINE == "rbx"
|
11
|
-
it "raises a NoMethodError" do
|
12
|
-
allow(logger).to receive(:crash).with("Actor crashed!", NoMethodError)
|
8
|
+
it "raises a NoMethodError" do
|
9
|
+
allow(logger).to receive(:crash).with("Actor crashed!", NoMethodError)
|
13
10
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
11
|
+
expect do
|
12
|
+
actor.the_method_that_was_not_there
|
13
|
+
end.to raise_exception(NoMethodError)
|
18
14
|
end
|
19
15
|
|
20
16
|
context "when obj raises during inspect" do
|
21
17
|
it "should emulate obj.inspect" do
|
22
18
|
allow(logger).to receive(:crash).with("Actor crashed!", NoMethodError)
|
23
|
-
|
24
|
-
if RUBY_ENGINE == "rbx"
|
25
|
-
expected = /undefined method `no_such_method' on an instance of CallExampleActor/
|
26
|
-
else
|
27
|
-
expected = /undefined method `no_such_method' for #\<CallExampleActor:0x[a-f0-9]+\>/
|
28
|
-
end
|
29
19
|
end
|
30
20
|
end
|
31
21
|
end
|
@@ -12,7 +12,7 @@ RSpec.describe Celluloid::Future, actor_system: :global do
|
|
12
12
|
it "reraises exceptions that occur when the value is retrieved" do
|
13
13
|
class ExampleError < StandardError; end
|
14
14
|
|
15
|
-
future = Celluloid::Future.new {
|
15
|
+
future = Celluloid::Future.new { raise ExampleError, "oh noes crash!" }
|
16
16
|
expect { future.value }.to raise_exception(ExampleError)
|
17
17
|
end
|
18
18
|
|
@@ -35,7 +35,7 @@ RSpec.describe Celluloid::Future, actor_system: :global do
|
|
35
35
|
|
36
36
|
it "cancels future" do
|
37
37
|
future = Celluloid::Future.new { sleep 3600 }
|
38
|
-
future.cancel(StandardError.new(
|
38
|
+
future.cancel(StandardError.new("cancelled"))
|
39
39
|
expect { future.value }.to raise_exception(StandardError, "cancelled")
|
40
40
|
end
|
41
41
|
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
RSpec.describe Celluloid::Internals::CPUCounter do
|
2
|
+
describe "#cores" do
|
3
|
+
subject { described_class.cores }
|
4
|
+
|
5
|
+
let(:num_cores) { 1024 }
|
6
|
+
|
7
|
+
before do
|
8
|
+
allow(described_class).to receive(:`) { raise "backtick stub called" }
|
9
|
+
allow(::IO).to receive(:open).and_raise("IO.open stub called!")
|
10
|
+
described_class.instance_variable_set(:@cores, nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
ENV["NUMBER_OF_PROCESSORS"] = nil
|
15
|
+
described_class.instance_variable_set(:@cores, nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with from_env" do
|
19
|
+
context "valid env value" do
|
20
|
+
before { ENV["NUMBER_OF_PROCESSORS"] = num_cores.to_s }
|
21
|
+
it { is_expected.to eq num_cores }
|
22
|
+
end
|
23
|
+
|
24
|
+
context "invalid env value" do
|
25
|
+
before { ENV["NUMBER_OF_PROCESSORS"] = "" }
|
26
|
+
subject { described_class.from_env }
|
27
|
+
it { is_expected.to be nil }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with from_sysdev" do
|
32
|
+
subject { described_class.from_sysdev }
|
33
|
+
|
34
|
+
context "when /sys/devices/system/cpu/present exists" do
|
35
|
+
before do
|
36
|
+
expect(::IO).to receive(:read).with("/sys/devices/system/cpu/present")
|
37
|
+
.and_return("dunno-whatever-#{num_cores - 1}")
|
38
|
+
end
|
39
|
+
it { is_expected.to eq num_cores }
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when /sys/devices/system/cpu/present does NOT exist" do
|
43
|
+
before do
|
44
|
+
expect(::IO).to receive(:read).with("/sys/devices/system/cpu/present")
|
45
|
+
.and_raise(Errno::ENOENT)
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when /sys/devices/system/cpu/cpu* files exist" do
|
49
|
+
before do
|
50
|
+
cpu_entries = (1..num_cores).map { |n| "cpu#{n}" }
|
51
|
+
cpu_entries << "non-cpu-entry-to-ignore"
|
52
|
+
expect(Dir).to receive(:[]).with("/sys/devices/system/cpu/cpu*")
|
53
|
+
.and_return(cpu_entries)
|
54
|
+
end
|
55
|
+
it { is_expected.to eq num_cores }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when /sys/devices/system/cpu/cpu* files DO NOT exist" do
|
60
|
+
before do
|
61
|
+
expect(Dir).to receive(:[]).with("/sys/devices/system/cpu/cpu*")
|
62
|
+
.and_return([])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "with from_java" do
|
68
|
+
subject { described_class.from_java }
|
69
|
+
|
70
|
+
xit "not yet tested" do
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "with from_proc" do
|
75
|
+
subject { described_class.from_proc }
|
76
|
+
|
77
|
+
xit "not yet tested" do
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "with from_win32ole" do
|
82
|
+
subject { described_class.from_win32ole }
|
83
|
+
|
84
|
+
xit "not yet tested" do
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "with from_sysctl" do
|
89
|
+
subject { described_class.from_sysctl }
|
90
|
+
|
91
|
+
context "when sysctl blows up" do
|
92
|
+
before { allow(described_class).to receive(:`).and_raise(Errno::EINTR) }
|
93
|
+
it { is_expected.to be nil }
|
94
|
+
end
|
95
|
+
|
96
|
+
context "when sysctl fails" do
|
97
|
+
before { allow(described_class).to receive(:`).and_return(`false`) }
|
98
|
+
it { is_expected.to be nil }
|
99
|
+
end
|
100
|
+
|
101
|
+
context "when sysctl succeeds" do
|
102
|
+
before do
|
103
|
+
expect(described_class).to receive(:`).with("sysctl -n hw.ncpu 2>/dev/null")
|
104
|
+
.and_return(num_cores.to_s)
|
105
|
+
`true`
|
106
|
+
end
|
107
|
+
it { is_expected.to eq num_cores }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
xit "when all guesses fail" do
|
112
|
+
end
|
113
|
+
|
114
|
+
context "with from_result" do
|
115
|
+
context "when passed a symbol" do
|
116
|
+
subject { described_class.from_result(:foo) }
|
117
|
+
it { is_expected.to be nil }
|
118
|
+
end
|
119
|
+
context "when passed 0" do
|
120
|
+
subject { described_class.from_result(:foo) }
|
121
|
+
it { is_expected.to be nil }
|
122
|
+
end
|
123
|
+
context "when passed valid integer" do
|
124
|
+
subject { described_class.from_result(num_cores) }
|
125
|
+
it { is_expected.to be num_cores }
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|