rsense-server 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/Gemfile +14 -0
  4. data/Guardfile +5 -0
  5. data/LICENSE.txt +1 -0
  6. data/README.md +51 -0
  7. data/Rakefile +9 -0
  8. data/bin/_rsense.rb +115 -0
  9. data/config/puma.rb +2 -0
  10. data/lib/rsense/server/code.rb +38 -0
  11. data/lib/rsense/server/command/completion_result.rb +11 -0
  12. data/lib/rsense/server/command/special_meth.rb +18 -0
  13. data/lib/rsense/server/command/type_inference_method.rb +24 -0
  14. data/lib/rsense/server/command.rb +239 -0
  15. data/lib/rsense/server/config.rb +70 -0
  16. data/lib/rsense/server/gem_path.rb +18 -0
  17. data/lib/rsense/server/listeners/find_definition_event_listener.rb +91 -0
  18. data/lib/rsense/server/listeners/where_event_listener.rb +39 -0
  19. data/lib/rsense/server/load_path.rb +62 -0
  20. data/lib/rsense/server/options.rb +85 -0
  21. data/lib/rsense/server/parser.rb +17 -0
  22. data/lib/rsense/server/path_info.rb +17 -0
  23. data/lib/rsense/server/project.rb +24 -0
  24. data/lib/rsense/server/version.rb +5 -0
  25. data/lib/rsense/server.rb +18 -0
  26. data/rsense-server.gemspec +35 -0
  27. data/spec/fixtures/config_fixture/.rsense +4 -0
  28. data/spec/fixtures/deeply/nested/thing.rb +0 -0
  29. data/spec/fixtures/find_def_sample.json +10 -0
  30. data/spec/fixtures/sample.json +10 -0
  31. data/spec/fixtures/test_gem/.gitignore +22 -0
  32. data/spec/fixtures/test_gem/Gemfile +4 -0
  33. data/spec/fixtures/test_gem/LICENSE.txt +22 -0
  34. data/spec/fixtures/test_gem/README.md +29 -0
  35. data/spec/fixtures/test_gem/Rakefile +2 -0
  36. data/spec/fixtures/test_gem/lib/sample/version.rb +3 -0
  37. data/spec/fixtures/test_gem/lib/sample.rb +16 -0
  38. data/spec/fixtures/test_gem/sample.gemspec +23 -0
  39. data/spec/fixtures/test_gem/test.json +10 -0
  40. data/spec/rsense/server/code_spec.rb +44 -0
  41. data/spec/rsense/server/command/special_meth_spec.rb +23 -0
  42. data/spec/rsense/server/command_spec.rb +108 -0
  43. data/spec/rsense/server/config_spec.rb +27 -0
  44. data/spec/rsense/server/gem_path_spec.rb +16 -0
  45. data/spec/rsense/server/load_path_spec.rb +63 -0
  46. data/spec/rsense/server/options_spec.rb +33 -0
  47. data/spec/rsense/server/path_info_spec.rb +11 -0
  48. data/spec/rsense/server/project_spec.rb +18 -0
  49. data/spec/rsense/server_spec.rb +7 -0
  50. data/spec/spec_helper.rb +16 -0
  51. data/vendor/gems/puma-2.8.2-java/COPYING +55 -0
  52. data/vendor/gems/puma-2.8.2-java/DEPLOYMENT.md +92 -0
  53. data/vendor/gems/puma-2.8.2-java/Gemfile +17 -0
  54. data/vendor/gems/puma-2.8.2-java/History.txt +532 -0
  55. data/vendor/gems/puma-2.8.2-java/LICENSE +26 -0
  56. data/vendor/gems/puma-2.8.2-java/Manifest.txt +68 -0
  57. data/vendor/gems/puma-2.8.2-java/README.md +251 -0
  58. data/vendor/gems/puma-2.8.2-java/Rakefile +158 -0
  59. data/vendor/gems/puma-2.8.2-java/bin/puma +10 -0
  60. data/vendor/gems/puma-2.8.2-java/bin/puma-wild +17 -0
  61. data/vendor/gems/puma-2.8.2-java/bin/pumactl +12 -0
  62. data/vendor/gems/puma-2.8.2-java/docs/config.md +0 -0
  63. data/vendor/gems/puma-2.8.2-java/docs/nginx.md +80 -0
  64. data/vendor/gems/puma-2.8.2-java/docs/signals.md +42 -0
  65. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/PumaHttp11Service.java +17 -0
  66. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/ext_help.h +15 -0
  67. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/extconf.rb +8 -0
  68. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser.c +1225 -0
  69. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser.h +64 -0
  70. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser.java.rl +161 -0
  71. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser.rl +146 -0
  72. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser_common.rl +54 -0
  73. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/io_buffer.c +155 -0
  74. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/mini_ssl.c +195 -0
  75. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/org/jruby/puma/Http11.java +225 -0
  76. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/org/jruby/puma/Http11Parser.java +488 -0
  77. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/org/jruby/puma/MiniSSL.java +289 -0
  78. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/puma_http11.c +491 -0
  79. data/vendor/gems/puma-2.8.2-java/lib/puma/accept_nonblock.rb +23 -0
  80. data/vendor/gems/puma-2.8.2-java/lib/puma/app/status.rb +59 -0
  81. data/vendor/gems/puma-2.8.2-java/lib/puma/binder.rb +298 -0
  82. data/vendor/gems/puma-2.8.2-java/lib/puma/capistrano.rb +86 -0
  83. data/vendor/gems/puma-2.8.2-java/lib/puma/cli.rb +587 -0
  84. data/vendor/gems/puma-2.8.2-java/lib/puma/client.rb +289 -0
  85. data/vendor/gems/puma-2.8.2-java/lib/puma/cluster.rb +389 -0
  86. data/vendor/gems/puma-2.8.2-java/lib/puma/compat.rb +18 -0
  87. data/vendor/gems/puma-2.8.2-java/lib/puma/configuration.rb +377 -0
  88. data/vendor/gems/puma-2.8.2-java/lib/puma/const.rb +165 -0
  89. data/vendor/gems/puma-2.8.2-java/lib/puma/control_cli.rb +251 -0
  90. data/vendor/gems/puma-2.8.2-java/lib/puma/daemon_ext.rb +25 -0
  91. data/vendor/gems/puma-2.8.2-java/lib/puma/delegation.rb +11 -0
  92. data/vendor/gems/puma-2.8.2-java/lib/puma/detect.rb +4 -0
  93. data/vendor/gems/puma-2.8.2-java/lib/puma/events.rb +130 -0
  94. data/vendor/gems/puma-2.8.2-java/lib/puma/io_buffer.rb +7 -0
  95. data/vendor/gems/puma-2.8.2-java/lib/puma/java_io_buffer.rb +45 -0
  96. data/vendor/gems/puma-2.8.2-java/lib/puma/jruby_restart.rb +83 -0
  97. data/vendor/gems/puma-2.8.2-java/lib/puma/minissl.rb +148 -0
  98. data/vendor/gems/puma-2.8.2-java/lib/puma/null_io.rb +34 -0
  99. data/vendor/gems/puma-2.8.2-java/lib/puma/puma_http11.jar +0 -0
  100. data/vendor/gems/puma-2.8.2-java/lib/puma/rack_default.rb +7 -0
  101. data/vendor/gems/puma-2.8.2-java/lib/puma/rack_patch.rb +45 -0
  102. data/vendor/gems/puma-2.8.2-java/lib/puma/reactor.rb +183 -0
  103. data/vendor/gems/puma-2.8.2-java/lib/puma/runner.rb +146 -0
  104. data/vendor/gems/puma-2.8.2-java/lib/puma/server.rb +801 -0
  105. data/vendor/gems/puma-2.8.2-java/lib/puma/single.rb +102 -0
  106. data/vendor/gems/puma-2.8.2-java/lib/puma/tcp_logger.rb +32 -0
  107. data/vendor/gems/puma-2.8.2-java/lib/puma/thread_pool.rb +185 -0
  108. data/vendor/gems/puma-2.8.2-java/lib/puma/util.rb +9 -0
  109. data/vendor/gems/puma-2.8.2-java/lib/puma.rb +14 -0
  110. data/vendor/gems/puma-2.8.2-java/lib/rack/handler/puma.rb +66 -0
  111. data/vendor/gems/puma-2.8.2-java/puma.gemspec +55 -0
  112. data/vendor/gems/puma-2.8.2-java/test/test_app_status.rb +92 -0
  113. data/vendor/gems/puma-2.8.2-java/test/test_cli.rb +173 -0
  114. data/vendor/gems/puma-2.8.2-java/test/test_config.rb +26 -0
  115. data/vendor/gems/puma-2.8.2-java/test/test_http10.rb +27 -0
  116. data/vendor/gems/puma-2.8.2-java/test/test_http11.rb +144 -0
  117. data/vendor/gems/puma-2.8.2-java/test/test_integration.rb +165 -0
  118. data/vendor/gems/puma-2.8.2-java/test/test_iobuffer.rb +38 -0
  119. data/vendor/gems/puma-2.8.2-java/test/test_minissl.rb +25 -0
  120. data/vendor/gems/puma-2.8.2-java/test/test_null_io.rb +31 -0
  121. data/vendor/gems/puma-2.8.2-java/test/test_persistent.rb +238 -0
  122. data/vendor/gems/puma-2.8.2-java/test/test_puma_server.rb +323 -0
  123. data/vendor/gems/puma-2.8.2-java/test/test_rack_handler.rb +10 -0
  124. data/vendor/gems/puma-2.8.2-java/test/test_rack_server.rb +141 -0
  125. data/vendor/gems/puma-2.8.2-java/test/test_tcp_rack.rb +42 -0
  126. data/vendor/gems/puma-2.8.2-java/test/test_thread_pool.rb +156 -0
  127. data/vendor/gems/puma-2.8.2-java/test/test_unix_socket.rb +39 -0
  128. data/vendor/gems/puma-2.8.2-java/test/test_ws.rb +89 -0
  129. data/vendor/gems/puma-2.8.2-java/tools/jungle/README.md +9 -0
  130. data/vendor/gems/puma-2.8.2-java/tools/jungle/init.d/README.md +54 -0
  131. data/vendor/gems/puma-2.8.2-java/tools/jungle/init.d/puma +332 -0
  132. data/vendor/gems/puma-2.8.2-java/tools/jungle/init.d/run-puma +3 -0
  133. data/vendor/gems/puma-2.8.2-java/tools/jungle/upstart/README.md +61 -0
  134. data/vendor/gems/puma-2.8.2-java/tools/jungle/upstart/puma-manager.conf +31 -0
  135. data/vendor/gems/puma-2.8.2-java/tools/jungle/upstart/puma.conf +63 -0
  136. data/vendor/gems/puma-2.8.2-java/tools/trickletest.rb +45 -0
  137. metadata +389 -0
@@ -0,0 +1,42 @@
1
+ require "rbconfig"
2
+ require 'test/unit'
3
+ require 'socket'
4
+ require 'openssl'
5
+
6
+ require 'puma/minissl'
7
+ require 'puma/server'
8
+
9
+ require 'net/https'
10
+
11
+ class TestTCPRack < Test::Unit::TestCase
12
+
13
+ def setup
14
+ @port = 3212
15
+ @host = "127.0.0.1"
16
+
17
+ @events = Puma::Events.new STDOUT, STDERR
18
+ @server = Puma::Server.new nil, @events
19
+ end
20
+
21
+ def teardown
22
+ @server.stop(true)
23
+ end
24
+
25
+ def test_passes_the_socket
26
+ @server.tcp_mode!
27
+
28
+ body = "We sell hats for a discount!\n"
29
+
30
+ @server.app = proc do |env, socket|
31
+ socket << body
32
+ socket.close
33
+ end
34
+
35
+ @server.add_tcp_listener @host, @port
36
+ @server.run
37
+
38
+ sock = TCPSocket.new @host, @port
39
+
40
+ assert_equal body, sock.read
41
+ end
42
+ end
@@ -0,0 +1,156 @@
1
+ require 'test/unit'
2
+
3
+ require 'puma/thread_pool'
4
+
5
+ class TestThreadPool < Test::Unit::TestCase
6
+
7
+ def teardown
8
+ @pool.shutdown if @pool
9
+ end
10
+
11
+ def new_pool(min, max, &block)
12
+ block = proc { } unless block
13
+ @pool = Puma::ThreadPool.new(min, max, &block)
14
+ end
15
+
16
+ def pause
17
+ sleep 0.2
18
+ end
19
+
20
+ def test_append_spawns
21
+ saw = []
22
+
23
+ pool = new_pool(0, 1) do |work|
24
+ saw << work
25
+ end
26
+
27
+ pool << 1
28
+
29
+ pause
30
+
31
+ assert_equal [1], saw
32
+ assert_equal 1, pool.spawned
33
+ end
34
+
35
+ def test_converts_pool_sizes
36
+ pool = new_pool('0', '1')
37
+
38
+ assert_equal 0, pool.spawned
39
+
40
+ pool << 1
41
+
42
+ assert_equal 1, pool.spawned
43
+ end
44
+
45
+ def test_append_queues_on_max
46
+ finish = false
47
+ pool = new_pool(0, 1) { Thread.pass until finish }
48
+
49
+ pool << 1
50
+ pool << 2
51
+ pool << 3
52
+
53
+ pause
54
+
55
+ assert_equal 2, pool.backlog
56
+
57
+ finish = true
58
+ end
59
+
60
+ def test_trim
61
+ pool = new_pool(0, 1)
62
+
63
+ pool << 1
64
+
65
+ pause
66
+
67
+ assert_equal 1, pool.spawned
68
+ pool.trim
69
+
70
+ pause
71
+ assert_equal 0, pool.spawned
72
+ end
73
+
74
+ def test_trim_leaves_min
75
+ finish = false
76
+ pool = new_pool(1, 2) { Thread.pass until finish }
77
+
78
+ pool << 1
79
+ pool << 2
80
+
81
+ finish = true
82
+
83
+ pause
84
+
85
+ assert_equal 2, pool.spawned
86
+ pool.trim
87
+ pause
88
+
89
+ assert_equal 1, pool.spawned
90
+ pool.trim
91
+ pause
92
+
93
+ assert_equal 1, pool.spawned
94
+
95
+ end
96
+
97
+ def test_force_trim_doesnt_overtrim
98
+ finish = false
99
+ pool = new_pool(1, 2) { Thread.pass until finish }
100
+
101
+ pool << 1
102
+ pool << 2
103
+
104
+ assert_equal 2, pool.spawned
105
+ pool.trim true
106
+ pool.trim true
107
+
108
+ finish = true
109
+
110
+ pause
111
+
112
+ assert_equal 1, pool.spawned
113
+ end
114
+
115
+ def test_trim_is_ignored_if_no_waiting_threads
116
+ finish = false
117
+ pool = new_pool(1, 2) { Thread.pass until finish }
118
+
119
+ pool << 1
120
+ pool << 2
121
+
122
+ assert_equal 2, pool.spawned
123
+ pool.trim
124
+ pool.trim
125
+
126
+ assert_equal 0, pool.trim_requested
127
+
128
+ finish = true
129
+
130
+ pause
131
+ end
132
+
133
+ def test_autotrim
134
+ finish = false
135
+ pool = new_pool(1, 2) { Thread.pass until finish }
136
+
137
+ pool << 1
138
+ pool << 2
139
+
140
+ assert_equal 2, pool.spawned
141
+
142
+ finish = true
143
+
144
+ pause
145
+
146
+ assert_equal 2, pool.spawned
147
+
148
+ pool.auto_trim! 1
149
+
150
+ sleep 1
151
+
152
+ pause
153
+
154
+ assert_equal 1, pool.spawned
155
+ end
156
+ end
@@ -0,0 +1,39 @@
1
+ require "rbconfig"
2
+ require 'test/unit'
3
+ require 'puma/server'
4
+
5
+ require 'socket'
6
+
7
+ # UNIX sockets are not recommended on JRuby
8
+ # (or Windows)
9
+ unless defined?(JRUBY_VERSION) || RbConfig::CONFIG["host_os"] =~ /mingw|mswin/
10
+ class TestPumaUnixSocket < Test::Unit::TestCase
11
+
12
+ App = lambda { |env| [200, {}, ["Works"]] }
13
+
14
+ Path = "test/puma.sock"
15
+
16
+ def setup
17
+ @server = Puma::Server.new App
18
+ @server.add_unix_listener Path
19
+ @server.run
20
+ end
21
+
22
+ def teardown
23
+ @server.stop(true)
24
+ File.unlink Path if File.exist? Path
25
+ end
26
+
27
+ def test_server
28
+ sock = UNIXSocket.new Path
29
+
30
+ sock << "GET / HTTP/1.0\r\nHost: blah.com\r\n\r\n"
31
+
32
+ expected = "HTTP/1.0 200 OK\r\nConnection: close\r\nContent-Length: 5\r\n\r\nWorks"
33
+
34
+ assert_equal expected, sock.read(expected.size)
35
+
36
+ sock.close
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,89 @@
1
+ # Copyright (c) 2011 Evan Phoenix
2
+ # Copyright (c) 2005 Zed A. Shaw
3
+
4
+ require 'test/testhelp'
5
+
6
+ include Puma
7
+
8
+ class TestHandler
9
+ attr_reader :ran_test
10
+
11
+ def call(env)
12
+ @ran_test = true
13
+
14
+ [200, {"Content-Type" => "text/plain"}, ["hello!"]]
15
+ end
16
+ end
17
+
18
+ class WebServerTest < Test::Unit::TestCase
19
+
20
+ def setup
21
+ @valid_request = "GET / HTTP/1.1\r\nHost: www.zedshaw.com\r\nContent-Type: text/plain\r\n\r\n"
22
+
23
+ @tester = TestHandler.new
24
+
25
+ @server = Server.new @tester, Events.strings
26
+ @server.add_tcp_listener "127.0.0.1", 9998
27
+
28
+ @server.run
29
+ end
30
+
31
+ def teardown
32
+ @server.stop(true)
33
+ end
34
+
35
+ def test_simple_server
36
+ hit(['http://127.0.0.1:9998/test'])
37
+ assert @tester.ran_test, "Handler didn't really run"
38
+ end
39
+
40
+
41
+ def do_test(string, chunk, close_after=nil, shutdown_delay=0)
42
+ # Do not use instance variables here, because it needs to be thread safe
43
+ socket = TCPSocket.new("127.0.0.1", 9998);
44
+ request = StringIO.new(string)
45
+ chunks_out = 0
46
+
47
+ while data = request.read(chunk)
48
+ chunks_out += socket.write(data)
49
+ socket.flush
50
+ sleep 0.2
51
+ if close_after and chunks_out > close_after
52
+ socket.close
53
+ sleep 1
54
+ end
55
+ end
56
+ sleep(shutdown_delay)
57
+ socket.write(" ") # Some platforms only raise the exception on attempted write
58
+ socket.flush
59
+ end
60
+
61
+ def test_trickle_attack
62
+ do_test(@valid_request, 3)
63
+ end
64
+
65
+ def test_close_client
66
+ assert_raises IOError do
67
+ do_test(@valid_request, 10, 20)
68
+ end
69
+ end
70
+
71
+ def test_bad_client
72
+ do_test("GET /test HTTP/BAD", 3)
73
+ end
74
+
75
+ def test_header_is_too_long
76
+ long = "GET /test HTTP/1.1\r\n" + ("X-Big: stuff\r\n" * 15000) + "\r\n"
77
+ assert_raises Errno::ECONNRESET, Errno::EPIPE, Errno::ECONNABORTED, Errno::EINVAL, IOError do
78
+ do_test(long, long.length/2, 10)
79
+ end
80
+ end
81
+
82
+ def test_file_streamed_request
83
+ body = "a" * (Puma::Const::MAX_BODY * 2)
84
+ long = "GET /test HTTP/1.1\r\nContent-length: #{body.length}\r\n\r\n" + body
85
+ do_test(long, (Puma::Const::CHUNK_SIZE * 2) - 400)
86
+ end
87
+
88
+ end
89
+
@@ -0,0 +1,9 @@
1
+ # Puma as a service
2
+
3
+ ## Init.d
4
+
5
+ See `/tools/jungle/init.d` for tools to use with init.d and start-stop-daemon.
6
+
7
+ ## Upstart
8
+
9
+ See `/tools/jungle/upstart` for Ubuntu's upstart scripts.
@@ -0,0 +1,54 @@
1
+ # Puma daemon service
2
+
3
+ Init script to manage multiple Puma servers on the same box using start-stop-daemon.
4
+
5
+ ## Installation
6
+
7
+ # Copy the init script to services directory
8
+ sudo cp puma /etc/init.d
9
+ sudo chmod +x /etc/init.d/puma
10
+
11
+ # Make it start at boot time.
12
+ sudo update-rc.d -f puma defaults
13
+
14
+ # Copy the Puma runner to an accessible location
15
+ sudo cp run-puma /usr/local/bin
16
+ sudo chmod +x /usr/local/bin/run-puma
17
+
18
+ # Create an empty configuration file
19
+ sudo touch /etc/puma.conf
20
+
21
+ ## Managing the jungle
22
+
23
+ Puma apps are held in /etc/puma.conf by default. It's mainly a CSV file and every line represents one app. Here's the syntax:
24
+
25
+ app-path,user,config-file-path,log-file-path
26
+
27
+ You can add an instance by editing the file or running the following command:
28
+
29
+ sudo /etc/init.d/puma add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log
30
+
31
+ The config and log paths are optional parameters and default to:
32
+
33
+ * config: /path/to/app/*config/puma.rb*
34
+ * log: /path/to/app/*log/puma.log*
35
+
36
+ To remove an app, simply delete the line from the config file or run:
37
+
38
+ sudo /etc/init.d/puma remove /path/to/app
39
+
40
+ The command will make sure the Puma instance stops before removing it from the jungle.
41
+
42
+ ## Assumptions
43
+
44
+ * The script expects a temporary folder named /path/to/app/*tmp/puma* to exist. Create it if it's not there by default.
45
+ The pid and state files should live there and must be called: *tmp/puma/pid* and *tmp/puma/state*.
46
+ You can change those if you want but you'll have to adapt the script for it to work.
47
+
48
+ * Here's what a minimal app's config file should have:
49
+
50
+ ```
51
+ pidfile "/path/to/app/tmp/puma/pid"
52
+ state_path "/path/to/app/tmp/puma/state"
53
+ activate_control_app
54
+ ```