toxiproxy 0.1.3 → 0.1.4
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/README.md +7 -2
- data/bin/start-toxiproxy.sh +2 -1
- data/lib/toxiproxy.rb +19 -18
- data/lib/toxiproxy/collection.rb +0 -2
- data/lib/toxiproxy/version.rb +1 -1
- data/test/toxiproxy_test.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 841ffa13a93004733dc2adfa28c71bc641ee5981
|
4
|
+
data.tar.gz: dbbf44472e95affc62b5143685ce50429924ce9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d27b3bec80952c35dec464d1b9cc3d952651af99e209d397a80695f0bd6573749e10846785866f6bb851bd02e4a7437a88f2d27979b46a2b42e3a616a913c2dc
|
7
|
+
data.tar.gz: b4171531e74753276229f73163afcb44a41b0e4df88929c4746deabed8d4114c5e12060705034e3221a43d6bdc640d7d1a7018303d9f3a06ce91c5be51fdd759
|
data/README.md
CHANGED
@@ -17,7 +17,12 @@ documentation](https://github.com/shopify/toxiproxy)
|
|
17
17
|
|
18
18
|
## Usage
|
19
19
|
|
20
|
-
The Ruby client communicates with the Toxiproxy daemon via HTTP.
|
20
|
+
The Ruby client communicates with the Toxiproxy daemon via HTTP. By default it
|
21
|
+
connects to `http://127.0.0.1:8474`, but you can point to any host:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Toxiproxy.host = 'http://toxiproxy.local:5665'
|
25
|
+
```
|
21
26
|
|
22
27
|
For example, to simulate 1000ms latency on a database server you can use the
|
23
28
|
`latency` toxic with the `latency` argument (see the Toxiproxy project for a
|
@@ -79,7 +84,7 @@ Toxiproxy.populate([{
|
|
79
84
|
name: "mysql_read_only",
|
80
85
|
listen: "localhost:21213",
|
81
86
|
upstream: "localhost:3306",
|
82
|
-
})
|
87
|
+
}])
|
83
88
|
```
|
84
89
|
|
85
90
|
This will create the proxies passed, or replace the proxies if they already exist in Toxiproxy.
|
data/bin/start-toxiproxy.sh
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
#!/bin/bash -e
|
2
2
|
|
3
3
|
VERSION='21a264cc75549c3ae837b606eb6e17ea'
|
4
|
+
TOXIPROXY_LOG_DIR=${CIRCLE_ARTIFACTS:-'/tmp'}
|
4
5
|
|
5
6
|
echo "[start toxiproxy]"
|
6
7
|
curl --silent http://shopify-vagrant.s3.amazonaws.com/toxiproxy/toxiproxy-$VERSION -o ./bin/toxiproxy
|
7
8
|
chmod +x ./bin/toxiproxy
|
8
|
-
nohup bash -c "./bin/toxiproxy > ${
|
9
|
+
nohup bash -c "./bin/toxiproxy > ${TOXIPROXY_LOG_DIR}/toxiproxy.log 2>&1 &"
|
data/lib/toxiproxy.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
require "json"
|
2
2
|
require "uri"
|
3
3
|
require "net/http"
|
4
|
+
require "forwardable"
|
4
5
|
|
5
6
|
require "toxiproxy/collection"
|
6
7
|
require "toxiproxy/toxic"
|
7
8
|
require "toxiproxy/toxic_collection"
|
8
9
|
|
9
10
|
class Toxiproxy
|
10
|
-
|
11
|
+
extend SingleForwardable
|
12
|
+
|
13
|
+
DEFAULT_URI = 'http://127.0.0.1:8474'
|
11
14
|
VALID_DIRECTIONS = [:upstream, :downstream]
|
12
15
|
|
13
16
|
class NotFound < StandardError; end
|
@@ -23,16 +26,7 @@ class Toxiproxy
|
|
23
26
|
@enabled = options[:enabled]
|
24
27
|
end
|
25
28
|
|
26
|
-
|
27
|
-
# `define_method` to delegate from Toxiproxy to #all, and from there to the
|
28
|
-
# proxy collection.
|
29
|
-
class << self
|
30
|
-
Collection::METHODS.each do |method|
|
31
|
-
define_method(method) do |*args, &block|
|
32
|
-
self.all.send(method, *args, &block)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
29
|
+
def_delegators :all, *Collection::METHODS
|
36
30
|
|
37
31
|
# Re-enables all proxies and disables all toxics.
|
38
32
|
def self.reset
|
@@ -60,6 +54,11 @@ class Toxiproxy
|
|
60
54
|
Collection.new(proxies)
|
61
55
|
end
|
62
56
|
|
57
|
+
# Sets the toxiproxy host to use.
|
58
|
+
def self.host=(host)
|
59
|
+
@uri = host.is_a?(::URI) ? host : ::URI.parse(host)
|
60
|
+
end
|
61
|
+
|
63
62
|
# Convenience method to create a proxy.
|
64
63
|
def self.create(options)
|
65
64
|
self.new(options).create
|
@@ -99,7 +98,7 @@ class Toxiproxy
|
|
99
98
|
end
|
100
99
|
|
101
100
|
def self.running?
|
102
|
-
TCPSocket.new(
|
101
|
+
TCPSocket.new(uri.host, uri.port).close
|
103
102
|
true
|
104
103
|
rescue Errno::ECONNREFUSED, Errno::ECONNRESET
|
105
104
|
false
|
@@ -126,11 +125,9 @@ class Toxiproxy
|
|
126
125
|
# failure, such as a data store becoming completely unavailable.
|
127
126
|
def down(&block)
|
128
127
|
disable
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
enable
|
133
|
-
end
|
128
|
+
yield
|
129
|
+
ensure
|
130
|
+
enable
|
134
131
|
end
|
135
132
|
|
136
133
|
# Disables a Toxiproxy. This will drop all active connections and stop the proxy from listening.
|
@@ -207,8 +204,12 @@ class Toxiproxy
|
|
207
204
|
|
208
205
|
private
|
209
206
|
|
207
|
+
def self.uri
|
208
|
+
@uri ||= ::URI.parse(DEFAULT_URI)
|
209
|
+
end
|
210
|
+
|
210
211
|
def self.http
|
211
|
-
@http ||= Net::HTTP.new(
|
212
|
+
@http ||= Net::HTTP.new(uri.host, uri.port)
|
212
213
|
end
|
213
214
|
|
214
215
|
def http
|
data/lib/toxiproxy/collection.rb
CHANGED
data/lib/toxiproxy/version.rb
CHANGED
data/test/toxiproxy_test.rb
CHANGED
@@ -24,6 +24,13 @@ class ToxiproxyTest < MiniTest::Unit::TestCase
|
|
24
24
|
assert_equal "test_mysql_master", proxy.name
|
25
25
|
end
|
26
26
|
|
27
|
+
def test_proxy_not_running_with_bad_host
|
28
|
+
Toxiproxy.host = 'http://0.0.0.0:12345'
|
29
|
+
assert !Toxiproxy.running?, 'toxiproxy should not be running'
|
30
|
+
ensure
|
31
|
+
Toxiproxy.host = Toxiproxy::DEFAULT_URI
|
32
|
+
end
|
33
|
+
|
27
34
|
def test_enable_and_disable_proxy
|
28
35
|
with_tcpserver do |port|
|
29
36
|
proxy = Toxiproxy.create(upstream: "localhost:#{port}", name: "test_rubby_server")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toxiproxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Eskildsen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-02-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|