semian 0.4.2 → 0.4.3
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 +4 -4
- data/lib/semian/redis.rb +11 -5
- data/lib/semian/version.rb +1 -1
- data/test/fixtures/binary.sql +1 -0
- data/test/mysql2_test.rb +2 -5
- data/test/redis_test.rb +19 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37818bb2b8352953c8a3977a29381a812dd6a5aa
|
4
|
+
data.tar.gz: c1cf6be9179e4d21a41d2ff3bc831af8bca7b71f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
data/lib/semian/version.rb
CHANGED
@@ -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,
|
23
|
-
assert_equal :'redis_127.0.0.1:
|
24
|
-
assert_equal :'redis_example.com:42/
|
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
|
214
|
-
|
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:
|
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.
|
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-
|
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
|