summaryrefslogtreecommitdiff
path: root/spec/gitlab_post_receive_spec.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2016-05-10 14:39:52 -0700
committerStan Hu <stanhu@gmail.com>2016-05-10 14:43:04 -0700
commit63b711f8206964350816cd312050a12db82950dd (patch)
treeca5dc54813bd11389731bbfb2e3b0b9dafb59bc4 /spec/gitlab_post_receive_spec.rb
parentf0f1bbec8ad5d5fade7c0efeee22ba9b9bc44f07 (diff)
downloadgitlab-shell-use-stdin.tar.gz
Pipe RPUSH command to Redis via stdin to avoid overrunning command-lineuse-stdin
Closes gitlab-org/gitlab-ce#17329
Diffstat (limited to 'spec/gitlab_post_receive_spec.rb')
-rw-r--r--spec/gitlab_post_receive_spec.rb19
1 files changed, 11 insertions, 8 deletions
diff --git a/spec/gitlab_post_receive_spec.rb b/spec/gitlab_post_receive_spec.rb
index 9d7696e..86d0526 100644
--- a/spec/gitlab_post_receive_spec.rb
+++ b/spec/gitlab_post_receive_spec.rb
@@ -1,3 +1,4 @@
+# coding: utf-8
require 'spec_helper'
require 'gitlab_post_receive'
@@ -21,7 +22,7 @@ describe GitlabPostReceive do
before do
GitlabConfig.any_instance.stub(redis_command: %w(env -i redis-cli))
- allow(gitlab_post_receive).to receive(:system).and_return(true)
+ allow(Open3).to receive(:popen2).and_return(0)
end
it "prints the broadcast message" do
@@ -47,13 +48,15 @@ describe GitlabPostReceive do
end
it "pushes a Sidekiq job onto the queue" do
- expect(gitlab_post_receive).to receive(:system).with(
+ stdin = double('stdin')
+
+ expect(stdin).to receive(:write).with(
+ %Q/RPUSH 'resque:gitlab:queue:post_receive' '{"class":"PostReceive","args":["#{repo_path}","#{actor}",#{base64_changes.inspect}],"jid":"#{gitlab_post_receive.jid}"}'/)
+ expect(stdin).to receive(:close)
+ expect(Open3).to receive(:popen2).with(
*[
- *%w(env -i redis-cli rpush resque:gitlab:queue:post_receive),
- %Q/{"class":"PostReceive","args":["#{repo_path}","#{actor}",#{base64_changes.inspect}],"jid":"#{gitlab_post_receive.jid}"}/,
- { err: "/dev/null", out: "/dev/null" }
- ]
- ).and_return(true)
+ *%w(env -i redis-cli --pipe)
+ ]).and_yield(stdin, double('stdout'), double('wait_thr', value: 0)).and_return(0)
gitlab_post_receive.exec
end
@@ -72,7 +75,7 @@ describe GitlabPostReceive do
context "when the redis command fails" do
before do
- allow(gitlab_post_receive).to receive(:system).and_return(false)
+ allow(Open3).to receive(:popen2).and_return(1)
allow($?).to receive(:exitstatus).and_return(nil)
end