Skip to content

Commit 5267793

Browse files
committed
[test] Remove manual synchronzation for mocks
This _should_ be better after rspec/rspec#286 so let's give it a go (cherry picked from commit 5a2df2d)
1 parent f14c809 commit 5267793

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

src/spec/ruby/rack/application_spec.rb

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -572,20 +572,8 @@ def createRackServletWrapper(runtime, rackup, filename)
572572

573573
describe org.jruby.rack.PoolingRackApplicationFactory do
574574

575-
# Workaround rspec mocks/proxies not being thread-safe which causes occasional failures
576-
class Synchronized
577-
def initialize(obj)
578-
@delegate = obj
579-
@lock = Mutex.new
580-
end
581-
582-
def method_missing(name, *args, &block)
583-
@lock.synchronize { @delegate.send(name, *args, &block) }
584-
end
585-
end
586-
587575
before :each do
588-
@factory = Synchronized.new(double("factory").as_null_object)
576+
@factory = double("factory").as_null_object
589577
@pooling_factory = org.jruby.rack.PoolingRackApplicationFactory.new @factory
590578
@pooling_factory.context = @rack_context
591579
end
@@ -635,7 +623,7 @@ def method_missing(name, *args, &block)
635623
it "creates applications during initialization according to the jruby.min.runtimes context parameter" do
636624
allow(@factory).to receive(:init)
637625
allow(@factory).to receive(:newApplication) do
638-
app = Synchronized.new(double("app").as_null_object)
626+
app = double("app").as_null_object
639627
expect(app).to receive(:init)
640628
app
641629
end
@@ -668,7 +656,7 @@ def method_missing(name, *args, &block)
668656
it "forces the maximum size to be greater or equal to the initial size" do
669657
allow(@factory).to receive(:init)
670658
allow(@factory).to receive(:newApplication) do
671-
app = Synchronized.new(double("app").as_null_object)
659+
app = double("app").as_null_object
672660
expect(app).to receive(:init)
673661
app
674662
end
@@ -690,7 +678,7 @@ def method_missing(name, *args, &block)
690678
it "waits till initial runtimes get initialized (with wait set to true)" do
691679
allow(@factory).to receive(:init)
692680
allow(@factory).to receive(:newApplication) do
693-
app = Synchronized.new(double("app").as_null_object)
681+
app = double("app").as_null_object
694682
allow(app).to receive(:init) do
695683
sleep(0.05)
696684
end
@@ -710,7 +698,7 @@ def method_missing(name, *args, &block)
710698
allow(@factory).to receive(:init)
711699
app_count = java.util.concurrent.atomic.AtomicInteger.new(0)
712700
allow(@factory).to receive(:newApplication) do
713-
app = Synchronized.new(double("app").as_null_object)
701+
app = double("app").as_null_object
714702
allow(app).to receive(:init) do
715703
if app_count.addAndGet(1) == 2
716704
raise org.jruby.rack.RackInitializationException.new('failed app init')
@@ -748,7 +736,7 @@ def method_missing(name, *args, &block)
748736
app_init_secs = 0.2
749737
allow(@factory).to receive(:init)
750738
allow(@factory).to receive(:newApplication) do
751-
app = Synchronized.new(double("app").as_null_object)
739+
app = double("app").as_null_object
752740
allow(app).to receive(:init) { sleep(app_init_secs) }
753741
app
754742
end
@@ -766,7 +754,7 @@ def method_missing(name, *args, &block)
766754
app_init_secs = 0.2
767755
allow(@factory).to receive(:init)
768756
expect(@factory).to receive(:newApplication).twice do
769-
app = Synchronized.new(double("app").as_null_object)
757+
app = double("app").as_null_object
770758
expect(app).to receive(:init) { sleep(app_init_secs) }
771759
app
772760
end
@@ -795,7 +783,7 @@ def method_missing(name, *args, &block)
795783
app_init_secs = 0.1
796784
allow(@factory).to receive(:init)
797785
expect(@factory).to receive(:newApplication).twice do
798-
app = Synchronized.new(double("app (new)").as_null_object)
786+
app = double("app (new)").as_null_object
799787
expect(app).to receive(:init) { sleep(app_init_secs) }
800788
app
801789
end
@@ -811,7 +799,7 @@ def method_missing(name, *args, &block)
811799

812800
app_get_secs = 0.15
813801
expect(@factory).to receive(:getApplication).twice do
814-
app = Synchronized.new(double("app (get)").as_null_object)
802+
app = double("app (get)").as_null_object
815803
sleep(app_get_secs)
816804
app
817805
end
@@ -831,7 +819,7 @@ def method_missing(name, *args, &block)
831819
app_init_secs = 0.15
832820
allow(@factory).to receive(:init)
833821
allow(@factory).to receive(:newApplication) do
834-
app = Synchronized.new(double("app").as_null_object)
822+
app = double("app").as_null_object
835823
allow(app).to receive(:init) { sleep(app_init_secs) }
836824
app
837825
end
@@ -858,7 +846,7 @@ def method_missing(name, *args, &block)
858846
app_init_secs = 0.05
859847
allow(@factory).to receive(:init)
860848
allow(@factory).to receive(:newApplication) do
861-
app = Synchronized.new(double("app").as_null_object)
849+
app = double("app").as_null_object
862850
allow(app).to receive(:init) { sleep(app_init_secs); raise "app.init raising" }
863851
app
864852
end

0 commit comments

Comments
 (0)