celluloid 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of celluloid might be problematic. Click here for more details.

Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +333 -0
  3. data/README.md +1 -1
  4. data/culture/CODE_OF_CONDUCT.md +28 -0
  5. data/culture/Gemfile +9 -0
  6. data/culture/README.md +22 -0
  7. data/culture/Rakefile +5 -0
  8. data/culture/SYNC.md +70 -0
  9. data/culture/celluloid-culture.gemspec +18 -0
  10. data/culture/gems/README.md +39 -0
  11. data/culture/gems/dependencies.yml +78 -0
  12. data/culture/gems/loader.rb +101 -0
  13. data/culture/rubocop/README.md +38 -0
  14. data/culture/rubocop/lint.yml +8 -0
  15. data/culture/rubocop/metrics.yml +15 -0
  16. data/culture/rubocop/rubocop.yml +4 -0
  17. data/culture/rubocop/style.yml +48 -0
  18. data/culture/spec/gems_spec.rb +2 -0
  19. data/culture/spec/spec_helper.rb +0 -0
  20. data/culture/spec/sync_spec.rb +2 -0
  21. data/culture/sync.rb +56 -0
  22. data/culture/tasks/rspec.rake +5 -0
  23. data/culture/tasks/rubocop.rake +2 -0
  24. data/examples/basic_usage.rb +49 -0
  25. data/examples/futures.rb +38 -0
  26. data/examples/ring.rb +61 -0
  27. data/examples/simple_pmap.rb +14 -0
  28. data/examples/timers.rb +72 -0
  29. data/lib/celluloid.rb +142 -127
  30. data/lib/celluloid/actor.rb +47 -41
  31. data/lib/celluloid/actor_system.rb +75 -22
  32. data/lib/celluloid/autostart.rb +1 -1
  33. data/lib/celluloid/backported.rb +2 -0
  34. data/lib/celluloid/call/async.rb +16 -0
  35. data/lib/celluloid/call/block.rb +22 -0
  36. data/lib/celluloid/call/sync.rb +70 -0
  37. data/lib/celluloid/calls.rb +25 -114
  38. data/lib/celluloid/cell.rb +32 -20
  39. data/lib/celluloid/condition.rb +3 -3
  40. data/lib/celluloid/core_ext.rb +1 -1
  41. data/lib/celluloid/current.rb +2 -0
  42. data/lib/celluloid/deprecate.rb +18 -0
  43. data/lib/celluloid/exceptions.rb +1 -1
  44. data/lib/celluloid/fiber.rb +3 -3
  45. data/lib/celluloid/future.rb +7 -6
  46. data/lib/celluloid/group.rb +65 -0
  47. data/lib/celluloid/group/manager.rb +27 -0
  48. data/lib/celluloid/group/pool.rb +125 -0
  49. data/lib/celluloid/group/spawner.rb +71 -0
  50. data/lib/celluloid/logging.rb +5 -5
  51. data/lib/celluloid/mailbox.rb +14 -13
  52. data/lib/celluloid/mailbox/evented.rb +76 -0
  53. data/lib/celluloid/notices.rb +15 -0
  54. data/lib/celluloid/proxies.rb +12 -0
  55. data/lib/celluloid/proxy/abstract.rb +24 -0
  56. data/lib/celluloid/proxy/actor.rb +46 -0
  57. data/lib/celluloid/proxy/async.rb +36 -0
  58. data/lib/celluloid/proxy/block.rb +31 -0
  59. data/lib/celluloid/proxy/cell.rb +76 -0
  60. data/lib/celluloid/proxy/future.rb +40 -0
  61. data/lib/celluloid/proxy/sync.rb +44 -0
  62. data/lib/celluloid/rspec.rb +9 -10
  63. data/lib/celluloid/system_events.rb +16 -15
  64. data/lib/celluloid/{tasks.rb → task.rb} +21 -21
  65. data/lib/celluloid/task/fibered.rb +45 -0
  66. data/lib/celluloid/task/threaded.rb +59 -0
  67. data/lib/celluloid/test.rb +1 -1
  68. data/lib/celluloid/thread.rb +6 -1
  69. data/lib/celluloid/version.rb +3 -0
  70. data/spec/celluloid/actor_spec.rb +2 -2
  71. data/spec/celluloid/actor_system_spec.rb +35 -21
  72. data/spec/celluloid/block_spec.rb +3 -5
  73. data/spec/celluloid/calls_spec.rb +33 -11
  74. data/spec/celluloid/condition_spec.rb +16 -13
  75. data/spec/celluloid/evented_mailbox_spec.rb +1 -31
  76. data/spec/celluloid/future_spec.rb +13 -10
  77. data/spec/celluloid/group/elastic_spec.rb +0 -0
  78. data/spec/celluloid/group/manager_spec.rb +0 -0
  79. data/spec/celluloid/group/pool_spec.rb +8 -0
  80. data/spec/celluloid/group/spawner_spec.rb +8 -0
  81. data/spec/celluloid/mailbox/evented_spec.rb +27 -0
  82. data/spec/celluloid/mailbox_spec.rb +1 -3
  83. data/spec/celluloid/misc/leak_spec.rb +73 -0
  84. data/spec/celluloid/task/fibered_spec.rb +5 -0
  85. data/spec/celluloid/task/threaded_spec.rb +5 -0
  86. data/spec/celluloid/timer_spec.rb +14 -16
  87. data/spec/deprecate/actor_system_spec.rb +72 -0
  88. data/spec/deprecate/block_spec.rb +52 -0
  89. data/spec/deprecate/calls_spec.rb +57 -0
  90. data/spec/deprecate/evented_mailbox_spec.rb +34 -0
  91. data/spec/deprecate/future_spec.rb +32 -0
  92. data/spec/deprecate/internal_pool_spec.rb +4 -0
  93. data/spec/shared/actor_examples.rb +1237 -0
  94. data/spec/shared/group_examples.rb +121 -0
  95. data/{lib/celluloid/rspec → spec/shared}/mailbox_examples.rb +20 -17
  96. data/{lib/celluloid/rspec → spec/shared}/task_examples.rb +9 -8
  97. data/spec/spec_helper.rb +72 -16
  98. data/spec/support/coverage.rb +4 -0
  99. data/spec/support/crash_checking.rb +68 -0
  100. data/spec/support/debugging.rb +31 -0
  101. data/spec/support/env.rb +16 -0
  102. data/{lib/celluloid/rspec/example_actor_class.rb → spec/support/examples/actor_class.rb} +21 -2
  103. data/spec/support/examples/evented_mailbox_class.rb +27 -0
  104. data/spec/support/includer.rb +9 -0
  105. data/spec/support/logging.rb +63 -0
  106. data/spec/support/loose_threads.rb +65 -0
  107. data/spec/support/reset_class_variables.rb +27 -0
  108. data/spec/support/sleep_and_wait.rb +14 -0
  109. data/spec/support/split_logs.rb +1 -0
  110. data/spec/support/stubbing.rb +14 -0
  111. metadata +255 -95
  112. data/lib/celluloid/call_chain.rb +0 -13
  113. data/lib/celluloid/cpu_counter.rb +0 -34
  114. data/lib/celluloid/evented_mailbox.rb +0 -73
  115. data/lib/celluloid/fsm.rb +0 -186
  116. data/lib/celluloid/handlers.rb +0 -41
  117. data/lib/celluloid/internal_pool.rb +0 -159
  118. data/lib/celluloid/legacy.rb +0 -9
  119. data/lib/celluloid/links.rb +0 -36
  120. data/lib/celluloid/logger.rb +0 -93
  121. data/lib/celluloid/logging/incident.rb +0 -21
  122. data/lib/celluloid/logging/incident_logger.rb +0 -129
  123. data/lib/celluloid/logging/incident_reporter.rb +0 -48
  124. data/lib/celluloid/logging/log_event.rb +0 -20
  125. data/lib/celluloid/logging/ring_buffer.rb +0 -65
  126. data/lib/celluloid/method.rb +0 -32
  127. data/lib/celluloid/notifications.rb +0 -83
  128. data/lib/celluloid/pool_manager.rb +0 -146
  129. data/lib/celluloid/probe.rb +0 -73
  130. data/lib/celluloid/properties.rb +0 -24
  131. data/lib/celluloid/proxies/abstract_proxy.rb +0 -20
  132. data/lib/celluloid/proxies/actor_proxy.rb +0 -38
  133. data/lib/celluloid/proxies/async_proxy.rb +0 -31
  134. data/lib/celluloid/proxies/block_proxy.rb +0 -29
  135. data/lib/celluloid/proxies/cell_proxy.rb +0 -68
  136. data/lib/celluloid/proxies/future_proxy.rb +0 -35
  137. data/lib/celluloid/proxies/sync_proxy.rb +0 -36
  138. data/lib/celluloid/receivers.rb +0 -63
  139. data/lib/celluloid/registry.rb +0 -57
  140. data/lib/celluloid/responses.rb +0 -44
  141. data/lib/celluloid/rspec/actor_examples.rb +0 -1054
  142. data/lib/celluloid/signals.rb +0 -23
  143. data/lib/celluloid/stack_dump.rb +0 -133
  144. data/lib/celluloid/supervision_group.rb +0 -169
  145. data/lib/celluloid/supervisor.rb +0 -22
  146. data/lib/celluloid/task_set.rb +0 -49
  147. data/lib/celluloid/tasks/task_fiber.rb +0 -43
  148. data/lib/celluloid/tasks/task_thread.rb +0 -53
  149. data/lib/celluloid/thread_handle.rb +0 -50
  150. data/lib/celluloid/uuid.rb +0 -38
  151. data/spec/celluloid/cpu_counter_spec.rb +0 -82
  152. data/spec/celluloid/fsm_spec.rb +0 -107
  153. data/spec/celluloid/internal_pool_spec.rb +0 -52
  154. data/spec/celluloid/links_spec.rb +0 -45
  155. data/spec/celluloid/logging/ring_buffer_spec.rb +0 -38
  156. data/spec/celluloid/notifications_spec.rb +0 -120
  157. data/spec/celluloid/pool_spec.rb +0 -92
  158. data/spec/celluloid/probe_spec.rb +0 -121
  159. data/spec/celluloid/properties_spec.rb +0 -42
  160. data/spec/celluloid/registry_spec.rb +0 -64
  161. data/spec/celluloid/stack_dump_spec.rb +0 -64
  162. data/spec/celluloid/supervision_group_spec.rb +0 -65
  163. data/spec/celluloid/supervisor_spec.rb +0 -103
  164. data/spec/celluloid/tasks/task_fiber_spec.rb +0 -5
  165. data/spec/celluloid/tasks/task_thread_spec.rb +0 -5
  166. data/spec/celluloid/thread_handle_spec.rb +0 -26
  167. data/spec/celluloid/uuid_spec.rb +0 -11
@@ -0,0 +1,121 @@
1
+ RSpec.shared_examples "a Celluloid Group" do
2
+ let!(:queue) { Queue.new }
3
+ let!(:busy_queue) { Queue.new }
4
+
5
+ let(:logger) { Specs::FakeLogger.current }
6
+
7
+ def wait_until_busy(busy_queue = nil)
8
+ return busy_queue.pop if busy_queue
9
+ Specs.sleep_and_wait_until { subject.busy? }
10
+ end
11
+
12
+ def wait_until_idle
13
+ Specs.sleep_and_wait_until { subject.idle? }
14
+ end
15
+
16
+ before { subject }
17
+
18
+ after do
19
+ subject.shutdown
20
+ end
21
+
22
+ it "gets threads" do
23
+ expect(subject.get { queue.pop }).to be_a Thread
24
+ queue << nil
25
+ wait_until_idle
26
+ end
27
+
28
+ [StandardError, Exception].each do |exception_class|
29
+ context "with an #{exception_class} in the thread" do
30
+ before do
31
+ @wait_queue = Queue.new # doesn't work if in a let()
32
+
33
+ allow(logger).to receive(:crash)
34
+
35
+ subject.get do
36
+ busy_queue << nil
37
+ @wait_queue.pop
38
+ fail exception_class, "Error"
39
+ end
40
+
41
+ wait_until_busy(busy_queue)
42
+ end
43
+
44
+ it "logs the crash" do
45
+ expect(logger).to receive(:crash).with("thread crashed", exception_class)
46
+ @wait_queue << nil # let the thread fail
47
+ wait_until_idle
48
+ end
49
+
50
+ it "puts error'd threads back" do
51
+ @wait_queue << nil # let the thread fail
52
+ wait_until_idle
53
+ expect(subject.idle?).to be_truthy
54
+ end
55
+ end
56
+ end
57
+
58
+ context "when a thread has local variables" do
59
+ before do
60
+ @thread = subject.get do
61
+ Thread.current[:foo] = :bar
62
+ queue.pop
63
+ end
64
+
65
+ wait_until_busy
66
+
67
+ queue << nil # let the thread finish
68
+ if Celluloid.group_class == Celluloid::Group::Pool
69
+ # Wait until we get the same thread for a different proc
70
+ Specs.sleep_and_wait_until { subject.get { sleep 0.1 } == @thread }
71
+ else
72
+ wait_until_idle
73
+ end
74
+ end
75
+
76
+ # Cleaning not necessary for Spawner
77
+ unless Celluloid.group_class == Celluloid::Group::Spawner
78
+ it "cleans thread locals from old threads" do
79
+ expect(@thread[:foo]).to be_nil
80
+ end
81
+ end
82
+ end
83
+
84
+ it "shuts down" do
85
+ subject
86
+ thread = Queue.new
87
+
88
+ expect(
89
+ subject.get do
90
+ thread << Thread.current
91
+ sleep
92
+ end,
93
+ ).to be_a(Celluloid::Thread)
94
+
95
+ thread.pop # wait for 3rd-party thread to get strated
96
+
97
+ expect(subject.active?).to eq true
98
+ subject.shutdown
99
+ expect(subject.active?).to eq false
100
+ expect(subject.group.length).to eq 0
101
+ end
102
+
103
+ context "with a dead thread" do
104
+ before do
105
+ if Celluloid.group_class == Celluloid::Group::Pool
106
+ subject.max_idle = 0 # Instruct the pool to immediately shut down the thread.
107
+ end
108
+
109
+ subject.get { queue.pop }
110
+ wait_until_busy
111
+ queue << nil
112
+ wait_until_idle
113
+
114
+ subject.shutdown if Celluloid.group_class == Celluloid::Group::Spawner
115
+ end
116
+
117
+ it "doesn't leak dead threads" do
118
+ expect(subject.to_a.size).to eq(0)
119
+ end
120
+ end
121
+ end
@@ -1,6 +1,6 @@
1
- shared_context "a Celluloid Mailbox" do
1
+ RSpec.shared_examples "a Celluloid Mailbox" do
2
2
  after do
3
- Celluloid.logger.stub(:debug)
3
+ allow(Celluloid.logger).to receive(:debug)
4
4
  subject.shutdown if subject.alive?
5
5
  end
6
6
 
@@ -8,7 +8,7 @@ shared_context "a Celluloid Mailbox" do
8
8
  message = :ohai
9
9
 
10
10
  subject << message
11
- subject.receive.should == message
11
+ expect(subject.receive).to eq(message)
12
12
  end
13
13
 
14
14
  it "prioritizes system events over other messages" do
@@ -16,7 +16,7 @@ shared_context "a Celluloid Mailbox" do
16
16
  subject << :dummy2
17
17
 
18
18
  subject << Celluloid::SystemEvent.new
19
- subject.receive.should be_a(Celluloid::SystemEvent)
19
+ expect(subject.receive).to be_a(Celluloid::SystemEvent)
20
20
  end
21
21
 
22
22
  it "selectively receives messages with a block" do
@@ -24,15 +24,17 @@ shared_context "a Celluloid Mailbox" do
24
24
  class Bar; end
25
25
  class Baz; end
26
26
 
27
- foo, bar, baz = Foo.new, Bar.new, Baz.new
27
+ foo = Foo.new
28
+ bar = Bar.new
29
+ baz = Baz.new
28
30
 
29
31
  subject << baz
30
32
  subject << foo
31
33
  subject << bar
32
34
 
33
- subject.receive { |msg| msg.is_a? Foo }.should eq(foo)
34
- subject.receive { |msg| msg.is_a? Bar }.should eq(bar)
35
- subject.receive.should eq(baz)
35
+ expect(subject.receive { |msg| msg.is_a? Foo }).to eq(foo)
36
+ expect(subject.receive { |msg| msg.is_a? Bar }).to eq(bar)
37
+ expect(subject.receive).to eq(baz)
36
38
  end
37
39
 
38
40
  it "waits for a given timeout interval" do
@@ -43,15 +45,16 @@ shared_context "a Celluloid Mailbox" do
43
45
  subject.receive(interval) { false }
44
46
  end.to raise_exception(Celluloid::TimeoutError)
45
47
 
46
- (Time.now - started_at).should be_within(Celluloid::TIMER_QUANTUM).of interval
48
+ # Just check to make sure it didn't return earlier
49
+ expect(Time.now - started_at).to be >= interval
47
50
  end
48
51
 
49
52
  it "has a size" do
50
- subject.should respond_to(:size)
51
- subject.size.should be_zero
53
+ expect(subject).to respond_to(:size)
54
+ expect(subject.size).to be_zero
52
55
  subject << :foo
53
56
  subject << :foo
54
- subject.should have(2).entries
57
+ expect(subject.entries.size).to eq(2)
55
58
  end
56
59
 
57
60
  it "discards messages received when when full" do
@@ -59,11 +62,11 @@ shared_context "a Celluloid Mailbox" do
59
62
  subject << :first
60
63
  subject << :second
61
64
  subject << :third
62
- subject.to_a.should =~ [:first, :second]
65
+ expect(subject.to_a).to match_array([:first, :second])
63
66
  end
64
67
 
65
68
  it "logs discarded messages" do
66
- Celluloid.logger.should_receive(:debug).with("Discarded message (mailbox is dead): third")
69
+ expect(Celluloid.logger).to receive(:debug).with("Discarded message (mailbox is dead): third")
67
70
 
68
71
  subject.max_size = 2
69
72
  subject << :first
@@ -72,9 +75,9 @@ shared_context "a Celluloid Mailbox" do
72
75
  end
73
76
 
74
77
  it "discard messages when dead" do
75
- Celluloid.logger.should_receive(:debug).with("Discarded message (mailbox is dead): first")
76
- Celluloid.logger.should_receive(:debug).with("Discarded message (mailbox is dead): second")
77
- Celluloid.logger.should_receive(:debug).with("Discarded message (mailbox is dead): third")
78
+ expect(Celluloid.logger).to receive(:debug).with("Discarded message (mailbox is dead): first")
79
+ expect(Celluloid.logger).to receive(:debug).with("Discarded message (mailbox is dead): second")
80
+ expect(Celluloid.logger).to receive(:debug).with("Discarded message (mailbox is dead): third")
78
81
 
79
82
  subject << :first
80
83
  subject << :second
@@ -9,12 +9,12 @@ class MockActor
9
9
  end
10
10
  end
11
11
 
12
- shared_context "a Celluloid Task" do |task_class|
12
+ RSpec.shared_examples "a Celluloid Task" do
13
13
  let(:task_type) { :foobar }
14
14
  let(:suspend_state) { :doing_something }
15
15
  let(:actor) { MockActor.new }
16
16
 
17
- subject { task_class.new(task_type, {}) { Celluloid::Task.suspend(suspend_state) } }
17
+ subject { Celluloid.task_class.new(task_type, {}) { Celluloid::Task.suspend(suspend_state) } }
18
18
 
19
19
  before :each do
20
20
  Thread.current[:celluloid_actor_system] = Celluloid.actor_system
@@ -22,25 +22,26 @@ shared_context "a Celluloid Task" do |task_class|
22
22
  end
23
23
 
24
24
  after :each do
25
+ Thread.current[:celluloid_actor_system].shutdown
25
26
  Thread.current[:celluloid_actor] = nil
26
27
  Thread.current[:celluloid_actor_system] = nil
27
28
  end
28
29
 
29
30
  it "begins with status :new" do
30
- subject.status.should be :new
31
+ expect(subject.status).to be :new
31
32
  end
32
33
 
33
34
  it "resumes" do
34
- subject.should be_running
35
+ expect(subject).to be_running
35
36
  subject.resume
36
- subject.status.should eq(suspend_state)
37
+ expect(subject.status).to eq(suspend_state)
37
38
  subject.resume
38
- subject.should_not be_running
39
+ expect(subject).not_to be_running
39
40
  end
40
41
 
41
42
  it "raises exceptions outside" do
42
- task = task_class.new(task_type, {}) do
43
- raise "failure"
43
+ task = Celluloid.task_class.new(task_type, {}) do
44
+ fail "failure"
44
45
  end
45
46
  expect do
46
47
  task.resume
@@ -1,35 +1,79 @@
1
- require 'coveralls'
2
- Coveralls.wear!
1
+ require "rubygems"
2
+ require "bundler/setup"
3
3
 
4
- require 'rubygems'
5
- require 'bundler/setup'
6
- require 'celluloid/rspec'
7
- require 'celluloid/probe'
4
+ # To help produce better bug reports in Rubinius
5
+ if RUBY_ENGINE == "rbx"
6
+ # $DEBUG = true # would be nice if this didn't fail ... :(
7
+ require "rspec/matchers"
8
+ require "rspec/matchers/built_in/be"
9
+ end
10
+
11
+ # Require in order, so both CELLULOID_TEST and CELLULOID_DEBUG are true
12
+ require "celluloid/rspec"
13
+ require "celluloid/essentials"
8
14
 
9
- logfile = File.open(File.expand_path("../../log/test.log", __FILE__), 'a')
10
- logfile.sync = true
15
+ $CELLULOID_DEBUG = true
11
16
 
12
- Celluloid.logger = Logger.new(logfile)
17
+ # Require but disable, so it has to be explicitly enabled in tests
18
+ require "celluloid/probe"
19
+ $CELLULOID_MONITORING = false
20
+ Specs.reset_probe(nil)
13
21
 
14
22
  Celluloid.shutdown_timeout = 1
15
23
 
16
- Dir['./spec/support/*.rb'].map {|f| require f }
24
+ Dir["./spec/support/*.rb", "./spec/shared/*.rb"].map { |f| require f }
17
25
 
18
26
  RSpec.configure do |config|
19
- config.filter_run :focus => true
27
+ config.filter_run focus: true unless Nenv.ci?
28
+
20
29
  config.run_all_when_everything_filtered = true
30
+ config.disable_monkey_patching!
31
+ config.profile_examples = 3
21
32
 
22
- config.around do |ex|
23
- Celluloid.actor_system = nil
24
- Thread.list.each do |thread|
25
- next if thread == Thread.current
26
- thread.kill
33
+ Specs.configure(config)
34
+
35
+ config.before(:suite) do
36
+ Specs.stub_out_class_method(Celluloid::Internals::Logger, :crash) do |*args|
37
+ _name, ex = *args
38
+ fail "Unstubbed Logger.crash() was called:\n crash(\n #{args.map(&:inspect).join(",\n ")})"\
39
+ "\nException backtrace: \n (#{ex.class}) #{ex.backtrace * "\n (#{ex.class}) "}"
27
40
  end
41
+ end
42
+
43
+ config.before(:each) do |example|
44
+ @fake_logger = Specs::FakeLogger.new(Celluloid.logger, example.description)
45
+ stub_const("Celluloid::Internals::Logger", @fake_logger)
46
+ end
28
47
 
48
+ config.around do |ex|
29
49
  ex.run
50
+ if @fake_logger.crashes?
51
+ crashes = @fake_logger.crashes.map do |args, call_stack|
52
+ msg, ex = *args
53
+ "\n** Crash: #{msg.inspect}(#{ex.inspect})\n Backtrace:\n (crash) #{call_stack * "\n (crash) " }"\
54
+ "\n** Crash: \"Actor crashed!\"(#{ex.inspect})\n Backtrace:\n (crash) #{call_stack * "\n (crash) " }"\
55
+ "\n Exception Backtrace (#{ex.inspect}):\n (ex) #{ex.backtrace * "\n (ex) "}"
56
+ end.join("\n")
57
+
58
+ fail "Actor crashes occurred (please stub/mock if these are expected): #{crashes}"
59
+ end
60
+ @fake_logger = nil
61
+ end
62
+
63
+ config.around do |ex|
64
+ Celluloid.actor_system = nil
65
+
66
+ Specs.assert_no_loose_threads(ex.description) do
67
+ Specs.reset_class_variables(ex.description) do
68
+ ex.run
69
+ end
70
+ end
30
71
  end
31
72
 
32
73
  config.around actor_system: :global do |ex|
74
+ # Needed because some specs mock/stub/expect on the logger
75
+ Celluloid.logger = Specs.logger
76
+
33
77
  Celluloid.boot
34
78
  ex.run
35
79
  Celluloid.shutdown
@@ -41,4 +85,16 @@ RSpec.configure do |config|
41
85
  end
42
86
  end
43
87
 
88
+ config.filter_gems_from_backtrace(*%w(rspec-expectations rspec-core rspec-mocks rspec-logsplit rubysl-thread rubysl-timeout))
89
+
90
+ config.mock_with :rspec do |mocks|
91
+ mocks.verify_doubled_constant_names = true
92
+ mocks.verify_partial_doubles = true
93
+ end
94
+
95
+ config.around(:each) do |example|
96
+ # Needed because some specs mock/stub/expect on the logger
97
+ Celluloid.logger = Specs.logger
98
+ example.run
99
+ end
44
100
  end
@@ -0,0 +1,4 @@
1
+ if Nenv.ci?
2
+ require "coveralls"
3
+ Coveralls.wear!
4
+ end
@@ -0,0 +1,68 @@
1
+ module Specs
2
+ class FakeLogger
3
+ class << self
4
+ def current
5
+ allowed_logger.first
6
+ end
7
+
8
+ attr_accessor :allowed_logger
9
+ end
10
+
11
+ def initialize(real_logger, example)
12
+ @mutex = Mutex.new
13
+ @real_logger = real_logger
14
+ @crashes = Queue.new
15
+ @details = nil
16
+ @example = example
17
+ self.class.allowed_logger = [self, example]
18
+ end
19
+
20
+ def crash(*args)
21
+ check
22
+ fail "Testing block has already ended!" if @details
23
+ @crashes << [args, caller.dup]
24
+ end
25
+
26
+ def debug(*args)
27
+ check
28
+ @real_logger.debug(*args)
29
+ end
30
+
31
+ def warn(*args)
32
+ check
33
+ @real_logger.warn(*args)
34
+ end
35
+
36
+ def with_backtrace(_backtrace)
37
+ check
38
+ yield self
39
+ end
40
+
41
+ def crashes
42
+ check
43
+ @mutex.synchronize do
44
+ return @details if @details
45
+ @details = []
46
+ @details << @crashes.pop until @crashes.empty?
47
+ @crashes = nil
48
+ @details
49
+ end
50
+ end
51
+
52
+ def crashes?
53
+ check
54
+ !crashes.empty?
55
+ end
56
+
57
+ private
58
+
59
+ def check
60
+ return if self.class.allowed_logger.first == self
61
+
62
+ fail "Incorrect logger used:"\
63
+ " active/allowed: \n#{clas.allowed_logger.inspect},\n"\
64
+ " actual/self: \n#{[self, @example].inspect}\n"\
65
+ " (maybe an actor from another test is still running?)"
66
+ end
67
+ end
68
+ end