This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Thread-safety is enabled by calling `VCAP::Component.varz.threadsafe!`. This requires threads to synchronize access to the hash. Change-Id: I72e9b2e634d0337f995b05b04237605aac22203b
- Loading branch information
Showing
2 changed files
with
121 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright (c) 2009-2012 VMware, Inc. | ||
|
||
require "spec_helper" | ||
|
||
require "vcap/component" | ||
|
||
describe VCAP::Component do | ||
def cleanup | ||
VCAP::Component.instance_eval do | ||
if instance_variables.include?(:@varz) | ||
remove_instance_variable(:@varz) | ||
end | ||
|
||
if instance_variables.include?(:@healthz) | ||
remove_instance_variable(:@healthz) | ||
end | ||
end | ||
end | ||
|
||
before do | ||
cleanup | ||
end | ||
|
||
after do | ||
cleanup | ||
end | ||
|
||
describe "regular #varz" do | ||
it "should not raise on get" do | ||
expect do | ||
VCAP::Component.varz[:foo] | ||
end.to_not raise_error | ||
end | ||
end | ||
|
||
describe "thread-safe #varz" do | ||
before do | ||
VCAP::Component.varz.threadsafe! | ||
end | ||
|
||
it "should raise on get when the lock is not held" do | ||
expect do | ||
VCAP::Component.varz[:foo] | ||
end.to raise_error(/lock/i) | ||
end | ||
|
||
it "should not raise on get when the lock is held" do | ||
VCAP::Component.varz.synchronize do | ||
expect do | ||
VCAP::Component.varz[:foo] | ||
end.to_not raise_error | ||
end | ||
end | ||
end | ||
end |