semian 0.4.2 → 0.4.3

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: d993b21e41c60680d8229a6dc5cdd7b738f63a2c
4
- data.tar.gz: f7d661b33ad871138625904ab945787814c692fd
3
+ metadata.gz: 37818bb2b8352953c8a3977a29381a812dd6a5aa
4
+ data.tar.gz: c1cf6be9179e4d21a41d2ff3bc831af8bca7b71f
5
5
  SHA512:
6
- metadata.gz: 68ee4e3fed2cbe0cae47ca21ab08c2896bcfa73ef053b5e99e56e0d62b0b97cd514c232ab0c7cf9b25a530eeb5d3e90d1f65fb870fb80eaa461c7fadb7415b11
7
- data.tar.gz: bf5a184b767a1e2db9417119ced349d0f528efb54e2ed763eeffcccac4d5986368befd4bd5f9f674be0366d395af95f8d933d59b7b9dd6091d7288a26be9086d
6
+ metadata.gz: af8ced42836152bebc2f8bebc5a8046c8a69c2cc0bf2c5ce22d286a394d621f140f191df1339a0b90dfe426b7c38e4c3e05f25ced591c008450eb2d3f82a418b
7
+ data.tar.gz: 309107cb264ad1665103fbcd001134a91491618f6be66d463e2f024892021a80a3f9b7c4f02f97d37e96aca9f31fab6a5a4a7edb402233995c14fb07e4547b15
data/lib/semian/redis.rb CHANGED
@@ -16,11 +16,17 @@ class Redis
16
16
  ResourceBusyError = Class.new(SemianError)
17
17
  CircuitOpenError = Class.new(SemianError)
18
18
 
19
- # This memoized alias is necessary because during a `pipelined` block
20
- # the client is replaced by an instance of `Redis::Pipeline` and there is
21
- # no way to access the original client.
22
- def semian_resource
23
- @semian_resource ||= @client.semian_resource
19
+ attr_reader :semian_resource
20
+
21
+ alias_method :_original_initialize, :initialize
22
+
23
+ def initialize(*args, &block)
24
+ _original_initialize(*args, &block)
25
+
26
+ # This alias is necessary because during a `pipelined` block
27
+ # the client is replaced by an instance of `Redis::Pipeline` and there is
28
+ # no way to access the original client.
29
+ @semian_resource = client.semian_resource
24
30
  end
25
31
 
26
32
  def semian_identifier
@@ -1,3 +1,3 @@
1
1
  module Semian
2
- VERSION = '0.4.2'
2
+ VERSION = '0.4.3'
3
3
  end
@@ -0,0 +1 @@
1
+ INSERT IGNORE INTO `theme_template_bodies` (`cityhash`, `body`, `created_at`) VALUES ('716374049952273167', '��{\"current\":{\"bg_color\":\"#ff0000\"},\"presets\":{\"sandbox>,\0\07, grey_bg\":6M\0\06! blueJ!\0lff!redJ \0$ff0000\"}}}', '2015-11-06 19:08:03.498432')
data/test/mysql2_test.rb CHANGED
@@ -181,12 +181,9 @@ class TestMysql2 < MiniTest::Unit::TestCase
181
181
  end
182
182
 
183
183
  def test_query_whitelisted_returns_false_for_binary_sql
184
+ binary_query = File.read(File.expand_path('../fixtures/binary.sql', __FILE__))
184
185
  client = connect_to_mysql!
185
-
186
- q = "INSERT IGNORE INTO `theme_template_bodies` (`cityhash`, `body`, `created_at`) VALUES ('716374049952273167', \
187
- '\xB1\x01\xD0{\\\"current\\\":{\\\"bg_color\\\":\\\"#ff0000\\\"},\\\"presets\\\":{\\\"sandbox>,\\0\\07\x05\x01\x01, \
188
- grey_bg\\\":6M\\0\\06\x05\x01\x01!\fblueJ!\\0\x01l\x04ff\x01!\bredJ \\0$ff0000\\\"}}}', '2015-11-06 19:08:03.498432')"
189
- refute client.send(:query_whitelisted?, q)
186
+ refute client.send(:query_whitelisted?, binary_query)
190
187
  end
191
188
 
192
189
  def test_semian_allows_rollback_to_safepoint
data/test/redis_test.rb CHANGED
@@ -19,9 +19,9 @@ class TestRedis < MiniTest::Unit::TestCase
19
19
  end
20
20
 
21
21
  def test_semian_identifier
22
- assert_equal :redis_foo, Redis.new(semian: {name: 'foo'}).client.semian_identifier
23
- assert_equal :'redis_127.0.0.1:6379/0', Redis.new.client.semian_identifier
24
- assert_equal :'redis_example.com:42/0', Redis.new(host: 'example.com', port: 42).client.semian_identifier
22
+ assert_equal :redis_foo, new_redis(semian: {name: 'foo'}).client.semian_identifier
23
+ assert_equal :'redis_127.0.0.1:16379/1', new_redis(semian: {name: nil}).client.semian_identifier
24
+ assert_equal :'redis_example.com:42/1', new_redis(host: 'example.com', port: 42, semian: {name: nil}).client.semian_identifier
25
25
  end
26
26
 
27
27
  def test_client_alias
@@ -35,6 +35,13 @@ class TestRedis < MiniTest::Unit::TestCase
35
35
  assert_instance_of Semian::UnprotectedResource, resource
36
36
  end
37
37
 
38
+ def test_semian_resource_in_pipeline
39
+ redis = connect_to_redis!
40
+ redis.pipelined do
41
+ assert_instance_of Semian::ProtectedResource, redis.semian_resource
42
+ end
43
+ end
44
+
38
45
  def test_connection_errors_open_the_circuit
39
46
  client = connect_to_redis!
40
47
 
@@ -210,15 +217,20 @@ class TestRedis < MiniTest::Unit::TestCase
210
217
 
211
218
  private
212
219
 
213
- def connect_to_redis!(semian_options = {})
214
- redis = Redis.new(
220
+ def new_redis(options = {})
221
+ semian_options = SEMIAN_OPTIONS.merge(options.delete(:semian) || {})
222
+ Redis.new({
215
223
  host: '127.0.0.1',
216
224
  port: 16_379,
217
225
  reconnect_attempts: 0,
218
226
  db: 1,
219
227
  timeout: 0.5,
220
- semian: SEMIAN_OPTIONS.merge(semian_options),
221
- )
228
+ semian: semian_options,
229
+ }.merge(options))
230
+ end
231
+
232
+ def connect_to_redis!(semian_options = {})
233
+ redis = new_redis(semian: semian_options)
222
234
  redis.client.connect
223
235
  redis
224
236
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Francis
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-22 00:00:00.000000000 Z
12
+ date: 2016-05-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler
@@ -161,6 +161,7 @@ files:
161
161
  - scripts/install_toxiproxy.sh
162
162
  - semian.gemspec
163
163
  - test/circuit_breaker_test.rb
164
+ - test/fixtures/binary.sql
164
165
  - test/helpers/background_helper.rb
165
166
  - test/instrumentation_test.rb
166
167
  - test/mysql2_test.rb