diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-11-12 12:37:02 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-11-12 12:37:02 +0000 |
commit | 9f53a532d4a0a565f591c62b5e62a2fb698a0fbe (patch) | |
tree | d760a386e9fb28301c8ce219b4cf3b333a98603f /spec/httpunix_spec.rb | |
parent | ae498b6cd4122d3d7f35e6b73b50c53615ca3488 (diff) | |
parent | 184385ac5b15ee8b7dc6fa5278f7e711de275921 (diff) | |
download | gitlab-shell-9f53a532d4a0a565f591c62b5e62a2fb698a0fbe.tar.gz |
Merge branch 'y/httpunix2' into 'master'
Add support to connect gitlab-shell to Unicorn via UNIX socket (v2)
Hello up there.
I'm doing SlapOS port of GitLab, and that means several different services could be running on the same machine, including several GitLabs.
So far all internal GitLab subservices could be glued together via UNIX sockets except gitlab-shell -> Unicorn link, which, when done via local TCP, requires firewall/network namespaces to protect services on one machine from each other.
On the other hand access to UNIX domain sockets is managed via regular UNIX permissions on filesystem, and thus is easier to manage. Besides UNIX domain sockets are well known to be faster compared to TCP over loopback - in particular to have ~ 2 times less latency and ~ 2 times more throughput.
From this point of view it makes sense to teach gitlab-shell to talk to Unicorn via UNIX socket and switch to that mode by default eventually.
I've just made a patch for this. Please apply.
Thanks beforehand,
Kirill
/cc @dzaporozhets, @jacobvosmaer, @rspeicher
See merge request !30
Diffstat (limited to 'spec/httpunix_spec.rb')
-rw-r--r-- | spec/httpunix_spec.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/httpunix_spec.rb b/spec/httpunix_spec.rb new file mode 100644 index 0000000..cd2ede9 --- /dev/null +++ b/spec/httpunix_spec.rb @@ -0,0 +1,55 @@ +require_relative 'spec_helper' +require_relative '../lib/httpunix' +require 'webrick' + +describe URI::HTTPUNIX do + describe :parse do + uri = URI::parse('http+unix://%2Fpath%2Fto%2Fsocket/img.jpg') + subject { uri } + + it { should be_an_instance_of(URI::HTTPUNIX) } + its(:scheme) { should eq('http+unix') } + its(:hostname) { should eq('/path/to/socket') } + its(:path) { should eq('/img.jpg') } + end +end + + +# like WEBrick::HTTPServer, but listens on UNIX socket +class HTTPUNIXServer < WEBrick::HTTPServer + def listen(address, port) + socket = Socket.unix_server_socket(address) + socket.autoclose = false + server = UNIXServer.for_fd(socket.fileno) + socket.close + @listeners << server + end +end + +def tmp_socket_path + File.join(ROOT_PATH, 'tmp', 'socket') +end + +describe Net::HTTPUNIX do + # "hello world" over unix socket server in background thread + FileUtils.mkdir_p(File.dirname(tmp_socket_path)) + server = HTTPUNIXServer.new(:BindAddress => tmp_socket_path) + server.mount_proc '/' do |req, resp| + resp.body = "Hello World (at #{req.path})" + end + Thread.start { server.start } + + it "talks via HTTP ok" do + VCR.turned_off do + begin + WebMock.allow_net_connect! + http = Net::HTTPUNIX.new(tmp_socket_path) + expect(http.get('/').body).to eq('Hello World (at /)') + expect(http.get('/path').body).to eq('Hello World (at /path)') + + ensure + WebMock.disable_net_connect! + end + end + end +end |