summaryrefslogtreecommitdiff
path: root/spec/gitlab_keys_spec.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-04-18 14:25:21 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-04-18 14:25:21 +0300
commitacc1d88374e8e555b6a94d878f569f51e692bfe3 (patch)
tree5be7aec5823b6f456b4911778b3e83eb339b2fff /spec/gitlab_keys_spec.rb
parentd8600696dc14fed6aae2614ac886cac8e12b743e (diff)
downloadgitlab-shell-acc1d88374e8e555b6a94d878f569f51e692bfe3.tar.gz
Use lock file when add or remove keys from authorized_keys file
This prevents concurrent modification of authorized_keys file Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
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