summaryrefslogtreecommitdiff
path: root/spec/gitlab_keys_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/gitlab_keys_spec.rb')
-rw-r--r--spec/gitlab_keys_spec.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/gitlab_keys_spec.rb b/spec/gitlab_keys_spec.rb
index 5bf4c04..2ef7241 100644
--- a/spec/gitlab_keys_spec.rb
+++ b/spec/gitlab_keys_spec.rb
@@ -145,6 +145,42 @@ describe GitlabKeys do
end
end
+ describe :lock do
+ it "should raise exception if operation lasts more then timeout" do
+ key = GitlabKeys.new
+ expect do
+ key.send :lock, 1 do
+ sleep 2
+ end
+ end.to raise_error
+ end
+
+ it "should actually lock file" do
+ $global = ""
+ key = GitlabKeys.new
+
+ thr1 = Thread.new do
+ key.send :lock do
+ # Put bigger sleep here to test if main thread will
+ # wait for lock file released before executing code
+ sleep 1
+ $global << "foo"
+ end
+ end
+
+ # make sure main thread start lock command after
+ # thread above
+ sleep 0.5
+
+ key.send :lock do
+ $global << "bar"
+ end
+
+ thr1.join
+ $global.should == "foobar"
+ end
+ end
+
def build_gitlab_keys(*args)
argv(*args)
GitlabKeys.new