sensu-redis 0.1.13 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42a4cb01825d97e36febefee1e7a1d200bc5aec5
4
- data.tar.gz: 78addc7a9d53422e76a68ea0dd03d2df183c3859
3
+ metadata.gz: c22a06a2ec430bbba10f536339e6e8bdb9e50dfc
4
+ data.tar.gz: 29dfd7de2495c052fa353e01b90e36e7c9ea2ae7
5
5
  SHA512:
6
- metadata.gz: 5f30c9aed44dd9f6c26603250c2c4e5ce5a1f613ebabb685bbdcbc75b0a655ac9e51170d4cf692d1b18b6ebda342d156e20ff3422734b692e6d92710f1402cfc
7
- data.tar.gz: 5842c20f550a2530789328e89f24f7ce6f51edd4eb1ba9f96f71c24344ce34548c9fa1de197dcdfa080862a497c002127901fc2586932f5f2b002bcb1cc9fb79
6
+ metadata.gz: 244a5a233101f19a973df8153bfeca2c470012b200aacb6a4790e19c3b73c7d11bd29804b29e92a2e1d7d03e7c61bd63c4926e7dda1a2d1e1ab705b66a3cd6ba
7
+ data.tar.gz: e4764f5827e5ab8440b259132bf5cd8e75f8ce9fc5038cbdca0e4c0adc1ba4c218c8269570450a3e812d731ecec7e06cfc6190167e4109f9e3f81181fb800538
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/lib/sensu/redis.rb CHANGED
@@ -32,12 +32,10 @@ module Sensu
32
32
  # @yield callback to be called with the redis connection object.
33
33
  def connect_via_sentinel(options, &block)
34
34
  sentinel = Sentinel.new(options)
35
- sentinel.callback do
36
- sentinel.resolve do |host, port|
37
- redis = EM.connect(host, port, Client, options)
38
- redis.sentinel = sentinel
39
- block.call(redis)
40
- end
35
+ sentinel.resolve do |host, port|
36
+ redis = EM.connect(host, port, Client, options)
37
+ redis.sentinel = sentinel
38
+ block.call(redis)
41
39
  end
42
40
  end
43
41
 
@@ -63,7 +61,7 @@ module Sensu
63
61
  end
64
62
  options[:host] ||= "127.0.0.1"
65
63
  options[:port] ||= 6379
66
- if options[:sentinels].is_a?(Array)
64
+ if options[:sentinels].is_a?(Array) && options[:sentinels].size > 0
67
65
  connect_via_sentinel(options, &block)
68
66
  else
69
67
  connect_direct(options, &block)
@@ -4,8 +4,6 @@ require "eventmachine"
4
4
  module Sensu
5
5
  module Redis
6
6
  class Sentinel
7
- include EM::Deferrable
8
-
9
7
  # Initialize the Sentinel connections. The default Redis master
10
8
  # name is "mymaster", which is the same name that the Sensu HA
11
9
  # Redis documentation uses. The master name must be set
@@ -18,20 +16,14 @@ module Sensu
18
16
  @sentinels = connect_to_sentinels(options[:sentinels])
19
17
  end
20
18
 
21
- # Connect to a Sentinel instance. A successful connection will
22
- # set the deferrable status to `:successful`, triggering any
23
- # queued Sentinel callback calls (e.g. `resolve()`).
19
+ # Connect to a Sentinel instance.
24
20
  #
25
21
  # @param options [Hash] containing the host and port.
26
22
  # @return [Object] Sentinel connection.
27
23
  def connect_to_sentinel(options={})
28
24
  options[:host] ||= "127.0.0.1"
29
25
  options[:port] ||= 26379
30
- connection = EM.connect(options[:host], options[:port], Client, options)
31
- connection.callback do
32
- succeed
33
- end
34
- connection
26
+ EM.connect(options[:host], options[:port], Client, options)
35
27
  end
36
28
 
37
29
  # Connect to all Sentinel instances. This method defaults the
@@ -85,7 +77,7 @@ module Sensu
85
77
  sentinel.errback do
86
78
  retry_resolve(&block)
87
79
  end
88
- sentinel.timeout(10)
80
+ sentinel.timeout(60)
89
81
  end
90
82
  end
91
83
  end
data/sensu-redis.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "sensu-redis"
5
- spec.version = "0.1.13"
5
+ spec.version = "0.1.14"
6
6
  spec.authors = ["Sean Porter"]
7
7
  spec.email = ["portertech@gmail.com"]
8
8
  spec.summary = "The Sensu Redis client library"
data/spec/helpers.rb ADDED
@@ -0,0 +1,29 @@
1
+ require "rspec"
2
+ require "eventmachine"
3
+
4
+ unless RUBY_VERSION < "1.9" || RUBY_PLATFORM =~ /java/
5
+ require "codeclimate-test-reporter"
6
+ CodeClimate::TestReporter.start
7
+ end
8
+
9
+ module Helpers
10
+ def timer(delay, &callback)
11
+ periodic_timer = EM::PeriodicTimer.new(delay) do
12
+ callback.call
13
+ periodic_timer.cancel
14
+ end
15
+ end
16
+
17
+ def async_wrapper(&callback)
18
+ EM.run do
19
+ timer(10) do
20
+ raise "test timed out"
21
+ end
22
+ callback.call
23
+ end
24
+ end
25
+
26
+ def async_done
27
+ EM.stop_event_loop
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), "helpers")
2
+ require "sensu/redis"
3
+
4
+ describe "Sensu::Redis" do
5
+ include Helpers
6
+
7
+ it "can connect to a redis instance" do
8
+ async_wrapper do
9
+ Sensu::Redis.connect do |redis|
10
+ redis.callback do
11
+ expect(redis.connected?).to eq(true)
12
+ async_done
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ it "can connect to a redis master via sentinel", :sentinel => true do
19
+ async_wrapper do
20
+ Sensu::Redis.connect(:sentinels => [{:port => 26379}]) do |redis|
21
+ redis.callback do
22
+ expect(redis.connected?).to eq(true)
23
+ async_done
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Porter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-12 00:00:00.000000000 Z
11
+ date: 2016-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -102,6 +102,8 @@ files:
102
102
  - lib/sensu/redis/client/errors.rb
103
103
  - lib/sensu/redis/sentinel.rb
104
104
  - sensu-redis.gemspec
105
+ - spec/helpers.rb
106
+ - spec/redis_spec.rb
105
107
  homepage: https://github.com/sensu/sensu-redis
106
108
  licenses:
107
109
  - MIT
@@ -126,4 +128,6 @@ rubygems_version: 2.4.5.1
126
128
  signing_key:
127
129
  specification_version: 4
128
130
  summary: The Sensu Redis client library
129
- test_files: []
131
+ test_files:
132
+ - spec/helpers.rb
133
+ - spec/redis_spec.rb