bixby-common 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01cbdbfa0c13d2e8614a46e771ef0e9e16e21308
4
- data.tar.gz: 6457c2b1f50b6569dbcc6cb97d9053e63ec01b80
3
+ metadata.gz: 1f5f1fb87533cdcdfaba7bd9ba0532d0c6c1aed0
4
+ data.tar.gz: 1937a3c76c45d644396d17a9e75c6c1b38689686
5
5
  SHA512:
6
- metadata.gz: 445c45438b177e91cde8c25b71f70ebc28fcff1fffa290a2247c5db3b952a3a68cb151d697dde0882684f6fe5eaeb943b9d696c44342e3a830dcd9070401b21c
7
- data.tar.gz: bc88104b4157c8986d64078fa836c5acee5df142c7968474069b77d5e208ea855eed198e0b8ce93b3ea6da89b549f249a72cbba53e69822f3161c41cb15d3c51
6
+ metadata.gz: 4208517467da1d40ee2c706a10ef794742d173fab1bfa669a9c48dcf94466e10d078c473d7bd0165c5516b3f0ba4d12307ddb0a0e35b2391ebb9edcdbeea1e13
7
+ data.tar.gz: 54a5a6c786e43aede794bbd0d70aa7468aa729fd5451c4d560c4e06281d4db0616f4f887a612f40c97b067bca8c842e665433345c9e4196e0dfa3c5fc0fcd6ab
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  before_install:
2
+ - "gem install bundler --no-ri --no-rdoc"
2
3
  - "curl -sL https://s3.bixby.io/wad > ~/wad"
3
4
  - "chmod +x ~/wad"
4
5
  install:
@@ -8,8 +9,8 @@ after_script: "rake coveralls"
8
9
 
9
10
  language: ruby
10
11
  rvm:
11
- - 2.1.1
12
- - 1.9.3
12
+ - 2.1.5
13
+ - 2.2.0
13
14
 
14
15
  branches:
15
16
  only:
data/Gemfile.lock CHANGED
@@ -24,7 +24,7 @@ GIT
24
24
 
25
25
  GIT
26
26
  remote: git://github.com/chetan/micron.git
27
- revision: 0c1e9c0b9d9e052805f43485fe3454cbd25913c5
27
+ revision: 576f6699e2a7ff1828ce5c333cc5fa433c0be380
28
28
  specs:
29
29
  micron (0.5.1)
30
30
  ansi
@@ -56,7 +56,7 @@ GEM
56
56
  remote: https://rubygems.org/
57
57
  specs:
58
58
  addressable (2.3.6)
59
- ansi (1.4.3)
59
+ ansi (1.5.0)
60
60
  awesome_print (1.6.1)
61
61
  bixby-auth (0.1.1)
62
62
  builder (3.2.2)
@@ -132,7 +132,7 @@ GEM
132
132
  multi_json (~> 1.3)
133
133
  multi_xml (~> 0.5)
134
134
  rack (~> 1.2)
135
- oj (2.11.2)
135
+ oj (2.11.4)
136
136
  pry (0.10.1)
137
137
  coderay (~> 1.1.0)
138
138
  method_source (~> 0.8.1)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.6.1
data/bixby-common.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: bixby-common 0.6.0 ruby lib
5
+ # stub: bixby-common 0.6.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "bixby-common"
9
- s.version = "0.6.0"
9
+ s.version = "0.6.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Chetan Sarva"]
14
- s.date = "2015-01-16"
14
+ s.date = "2015-01-23"
15
15
  s.description = "Bixby Common files/libs"
16
16
  s.email = "chetan@pixelcop.net"
17
17
  s.extra_rdoc_files = [
@@ -77,6 +77,7 @@ Gem::Specification.new do |s|
77
77
  "test/util/http_client_test.rb",
78
78
  "test/util/jsonify_test.rb",
79
79
  "test/util/log_test.rb",
80
+ "test/util/signal_test.rb",
80
81
  "test/util/thread_pool_test.rb",
81
82
  "test/websocket/api_channel_test.rb",
82
83
  "test/websocket/async_response_test.rb",
@@ -85,7 +86,7 @@ Gem::Specification.new do |s|
85
86
  ]
86
87
  s.homepage = "http://github.com/chetan/bixby-common"
87
88
  s.licenses = ["MIT"]
88
- s.rubygems_version = "2.4.2"
89
+ s.rubygems_version = "2.4.5"
89
90
  s.summary = "Bixby Common"
90
91
 
91
92
  if s.respond_to? :specification_version then
@@ -22,7 +22,9 @@ module Bixby
22
22
  Thread.new do
23
23
  while true
24
24
  sig = trap_r.readline.strip
25
- block.call(sig)
25
+ Thread.new do
26
+ block.call(sig)
27
+ end
26
28
  end
27
29
  end
28
30
 
@@ -15,6 +15,10 @@ module Bixby
15
15
 
16
16
  # Prints a thread dump on ALRM signal
17
17
  # kill -ALRM <pid>
18
+ #
19
+ # You can cancel the signal trap by saving the returned Thread and killing it
20
+ #
21
+ # @return [Thread]
18
22
  def trap!
19
23
  t = Bixby::Signal.trap("SIGALRM") do
20
24
  write(LoggerIO.new(Logging.logger[ThreadDump]))
@@ -22,6 +26,7 @@ module Bixby
22
26
  t[:_name] = "dumper [ignore me]"
23
27
 
24
28
  Logging.logger[ThreadDump].info "Trapping SIGALRM: kill -ALRM #{Process.pid}"
29
+ return t
25
30
  end
26
31
 
27
32
  # Write thread dump to the given IO-like handle (must respond to #puts)
@@ -29,6 +29,7 @@ module Bixby
29
29
  end
30
30
 
31
31
  def enqueue(command, block=nil)
32
+ logger.debug { "enqueue new task: #{command}" }
32
33
  @input_queue.push(Task.new(command, block))
33
34
  if command == :perform then
34
35
  grow_pool
@@ -104,7 +105,7 @@ module Bixby
104
105
 
105
106
  def expand(count)
106
107
  @lock.synchronize do
107
- # logger.debug "expanding by #{count} threads (from #{@size})"
108
+ logger.debug "expanding by #{count} threads (from #{@size})"
108
109
  count.times do
109
110
  create_worker
110
111
  end
@@ -159,7 +160,7 @@ module Bixby
159
160
 
160
161
  def create_worker
161
162
  @lock.synchronize do
162
- # logger.debug "spawning new worker thread"
163
+ logger.debug "spawning new worker thread"
163
164
 
164
165
  exit_handler = lambda { |worker, reason|
165
166
  @lock.synchronize do
@@ -180,12 +181,14 @@ module Bixby
180
181
  # Grow the pool by one if we have more jobs than idle workers
181
182
  def grow_pool
182
183
  @lock.synchronize do
183
- # logger.debug { "busy: #{num_working}; idle: #{num_idle}" }
184
+ logger.debug { "jobs: #{num_jobs}; busy: #{num_working}; idle: #{num_idle}" }
184
185
  if @size < @max_size && num_jobs > 0 && num_jobs > num_idle then
185
186
  space = @max_size-@size
186
187
  jobs = num_jobs-num_idle
187
188
  needed = space < jobs ? space : jobs
188
189
  expand(needed)
190
+ else
191
+ logger.debug "NOT growing the pool!"
189
192
  end
190
193
  end
191
194
 
@@ -40,8 +40,6 @@ module Bixby
40
40
  #
41
41
  # @return [String] request id
42
42
  def execute_async(json_request, &block)
43
- logger.debug { "execute_async:\n#{json_request.to_s}" }
44
-
45
43
  if json_request.kind_of? Request then
46
44
  id, request = json_request.id, json_request
47
45
  else
@@ -50,6 +48,8 @@ module Bixby
50
48
  end
51
49
  @responses[id] = AsyncResponse.new(id, &block)
52
50
 
51
+ logger.debug { request.type == "connect" ? "execute_async: CONNECT [#{id}]" : "execute_async: RPC [#{id}]\n#{request.to_s}" }
52
+
53
53
  EM.next_tick {
54
54
  ws.send(request.to_wire)
55
55
  }
@@ -108,7 +108,7 @@ module Bixby
108
108
  elsif req.type == "rpc_result" then
109
109
  # Pass the result back to the caller
110
110
  res = req.json_response
111
- logger.debug { "RPC_RESULT for request id #{req.id}\n#{res}" }
111
+ logger.debug { "RPC_RESULT for request id [#{req.id}]\n#{res}" }
112
112
  @responses[req.id].response = res
113
113
 
114
114
  elsif req.type == "connect" then
@@ -0,0 +1,34 @@
1
+ require 'helper'
2
+
3
+ module Bixby
4
+ module Test
5
+ class TestSignal < TestCase
6
+
7
+ def test_create_signal
8
+
9
+ foo = 0
10
+ thread = Bixby::Signal.trap("ALRM") do
11
+ foo += 1
12
+ end
13
+
14
+ assert thread.kind_of? Thread
15
+ assert thread.alive?
16
+ assert_equal 0, foo
17
+
18
+ Process.kill("ALRM", Process.pid)
19
+ sleep 0.01
20
+ assert_equal 1, foo
21
+
22
+ Process.kill("ALRM", Process.pid)
23
+ sleep 0.01
24
+ assert_equal 2, foo
25
+
26
+ assert thread.alive?
27
+ thread.kill
28
+ thread.join
29
+ refute thread.alive?
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -15,7 +15,7 @@ class TestThreadPool < TestCase
15
15
  begin
16
16
  puts "tearing down, shutting down pool"
17
17
  @pool.shutdown
18
- @pool.join(5)
18
+ @pool.join(0.1)
19
19
  assert_equal 0, @pool.size
20
20
  rescue Exception => ex
21
21
  end
@@ -41,20 +41,23 @@ class TestThreadPool < TestCase
41
41
  foo = []
42
42
  4.times do |i|
43
43
  @pool.perform do
44
+ logger.debug "running job #{i}, sleeping 10"
45
+ sleep 10
44
46
  foo << "thread #{i}"
45
47
  end
48
+ sleep 0.1
46
49
  end
47
50
  assert_equal 4, @pool.size
48
51
 
49
52
  10.times do |i|
50
53
  @pool.perform do
54
+ sleep 10
51
55
  foo << "thread #{i}"
52
56
  end
53
57
  end
54
58
  assert_equal 8, @pool.size
55
59
 
56
- @pool.dispose
57
- assert_equal 14, foo.size
60
+ # assert_equal 14, foo.size
58
61
  end
59
62
 
60
63
  def test_pool_shrinks_on_idle
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bixby-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chetan Sarva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-16 00:00:00.000000000 Z
11
+ date: 2015-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bixby-auth
@@ -272,6 +272,7 @@ files:
272
272
  - test/util/http_client_test.rb
273
273
  - test/util/jsonify_test.rb
274
274
  - test/util/log_test.rb
275
+ - test/util/signal_test.rb
275
276
  - test/util/thread_pool_test.rb
276
277
  - test/websocket/api_channel_test.rb
277
278
  - test/websocket/async_response_test.rb
@@ -297,7 +298,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
297
298
  version: '0'
298
299
  requirements: []
299
300
  rubyforge_project:
300
- rubygems_version: 2.4.2
301
+ rubygems_version: 2.4.5
301
302
  signing_key:
302
303
  specification_version: 4
303
304
  summary: Bixby Common