nonnative 1.25.0 → 1.26.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +6 -4
- data/lib/nonnative.rb +1 -1
- data/lib/nonnative/configuration.rb +1 -0
- data/lib/nonnative/configuration_proxy.rb +1 -1
- data/lib/nonnative/configuration_server.rb +1 -0
- data/lib/nonnative/{chaos_proxy.rb → fault_injection_proxy.rb} +16 -4
- data/lib/nonnative/proxy_factory.rb +8 -7
- data/lib/nonnative/socket_pair.rb +5 -2
- data/lib/nonnative/socket_pair_factory.rb +13 -11
- data/lib/nonnative/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12206912ca29ab82602d7d07fdc15f5b42124e890572d463ad1c4358c7de9f08
|
4
|
+
data.tar.gz: ee0393650b33d8a3c5b1d31019f717a3fb680f8872171c7fea1ac4892e186ad5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bbd95d62ddf01d04fd7f6bc4a783276e65dcc7775fbc1844316ee5f12ce150cf06cb3536c77e98f2b600fa5126fd2ed6e2946466559a53a4444ea4e1448b62f
|
7
|
+
data.tar.gz: 4417fe28fb3f291a7ac81bab44cbf398fc897acbf815397bd58aba7a72548c0320faba7aeab15778f7037c05b9fb84e2429cbd0a19ec6daba2d0c4f9f646318e
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -310,7 +310,7 @@ Nonnative.load_configuration('configuration.yml')
|
|
310
310
|
|
311
311
|
We allow different proxies to be configured. These proxies can be used to simulate all kind of situations. The proxies that can be configured are:
|
312
312
|
- `none` (this is the default)
|
313
|
-
- `
|
313
|
+
- `fault_injection`
|
314
314
|
|
315
315
|
Setup it up programmatically:
|
316
316
|
|
@@ -322,8 +322,9 @@ Nonnative.configure do |config|
|
|
322
322
|
|
323
323
|
config.server do |d|
|
324
324
|
d.proxy = {
|
325
|
-
type: '
|
325
|
+
type: 'fault_injection',
|
326
326
|
port: 20_000,
|
327
|
+
log: 'features/logs/proxy_server.log',
|
327
328
|
options: {
|
328
329
|
delay: 5
|
329
330
|
}
|
@@ -340,15 +341,16 @@ strategy: manual
|
|
340
341
|
servers:
|
341
342
|
-
|
342
343
|
proxy:
|
343
|
-
type:
|
344
|
+
type: fault_injection
|
344
345
|
port: 20000
|
346
|
+
log: features/logs/proxy_server.log
|
345
347
|
options:
|
346
348
|
delay: 5
|
347
349
|
```
|
348
350
|
|
349
351
|
##### Fault Injection
|
350
352
|
|
351
|
-
The `
|
353
|
+
The `fault_injection` proxy allows you to simulate failures by injecting them. We currently support the following:
|
352
354
|
- `close_all` - Closes the socket as soon as it connects.
|
353
355
|
- `delay` - This delays the communication between the connection. Default is 2 secs can be configured through options.
|
354
356
|
- `invalid_data` - This takes the input and rearranges it to produce invalid data.
|
data/lib/nonnative.rb
CHANGED
@@ -34,7 +34,7 @@ require 'nonnative/observability'
|
|
34
34
|
require 'nonnative/proxy_factory'
|
35
35
|
require 'nonnative/proxy'
|
36
36
|
require 'nonnative/no_proxy'
|
37
|
-
require 'nonnative/
|
37
|
+
require 'nonnative/fault_injection_proxy'
|
38
38
|
require 'nonnative/socket_pair'
|
39
39
|
require 'nonnative/close_all_socket_pair'
|
40
40
|
require 'nonnative/delay_socket_pair'
|
@@ -1,9 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Nonnative
|
4
|
-
class
|
4
|
+
class FaultInjectionProxy < Nonnative::Proxy
|
5
5
|
def initialize(service)
|
6
6
|
@connections = Concurrent::Hash.new
|
7
|
+
@logger = Logger.new(service.proxy.log)
|
7
8
|
@mutex = Mutex.new
|
8
9
|
@state = :none
|
9
10
|
|
@@ -42,19 +43,30 @@ module Nonnative
|
|
42
43
|
|
43
44
|
private
|
44
45
|
|
45
|
-
attr_reader :tcp_server, :thread, :connections, :mutex, :state
|
46
|
+
attr_reader :tcp_server, :thread, :connections, :mutex, :state, :logger
|
46
47
|
|
47
48
|
def perform_start
|
48
49
|
loop do
|
49
50
|
thread = Thread.start(tcp_server.accept) do |local_socket|
|
50
|
-
|
51
|
-
|
51
|
+
id = Thread.current.object_id
|
52
|
+
|
53
|
+
logger.info "started connection for #{id} with socket #{local_socket.inspect}"
|
54
|
+
|
55
|
+
connect local_socket
|
56
|
+
connections.delete(id)
|
57
|
+
|
58
|
+
logger.info "finished connection for #{id} with socket #{local_socket.inspect}"
|
52
59
|
end
|
60
|
+
|
53
61
|
thread.report_on_exception = false
|
54
62
|
connections[thread.object_id] = thread
|
55
63
|
end
|
56
64
|
end
|
57
65
|
|
66
|
+
def connect(local_socket)
|
67
|
+
SocketPairFactory.create(read_state, service.proxy, logger).connect(local_socket)
|
68
|
+
end
|
69
|
+
|
58
70
|
def apply_state(state)
|
59
71
|
mutex.synchronize { @state = state }
|
60
72
|
end
|
@@ -4,13 +4,14 @@ module Nonnative
|
|
4
4
|
class ProxyFactory
|
5
5
|
class << self
|
6
6
|
def create(service)
|
7
|
-
case service.proxy.type
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
proxy = case service.proxy.type
|
8
|
+
when 'fault_injection'
|
9
|
+
FaultInjectionProxy
|
10
|
+
else
|
11
|
+
NoProxy
|
12
|
+
end
|
13
|
+
|
14
|
+
proxy.new(service)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
module Nonnative
|
4
4
|
class SocketPair
|
5
|
-
def initialize(proxy)
|
5
|
+
def initialize(proxy, logger)
|
6
6
|
@proxy = proxy
|
7
|
+
@logger = logger
|
7
8
|
end
|
8
9
|
|
9
10
|
def connect(local_socket)
|
@@ -15,6 +16,8 @@ module Nonnative
|
|
15
16
|
break if pipe(ready, local_socket, remote_socket)
|
16
17
|
break if pipe(ready, remote_socket, local_socket)
|
17
18
|
end
|
19
|
+
rescue StandardError => e
|
20
|
+
logger.error e
|
18
21
|
ensure
|
19
22
|
local_socket.close
|
20
23
|
remote_socket&.close
|
@@ -22,7 +25,7 @@ module Nonnative
|
|
22
25
|
|
23
26
|
protected
|
24
27
|
|
25
|
-
attr_reader :proxy
|
28
|
+
attr_reader :proxy, :logger
|
26
29
|
|
27
30
|
def create_remote_socket
|
28
31
|
::TCPSocket.new('0.0.0.0', proxy.port)
|
@@ -3,17 +3,19 @@
|
|
3
3
|
module Nonnative
|
4
4
|
class SocketPairFactory
|
5
5
|
class << self
|
6
|
-
def create(type,
|
7
|
-
case type
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
def create(type, proxy, logger)
|
7
|
+
pair = case type
|
8
|
+
when :close_all
|
9
|
+
CloseAllSocketPair
|
10
|
+
when :delay
|
11
|
+
DelaySocketPair
|
12
|
+
when :invalid_data
|
13
|
+
InvalidDataSocketPair
|
14
|
+
else
|
15
|
+
SocketPair
|
16
|
+
end
|
17
|
+
|
18
|
+
pair.new(proxy, logger)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
data/lib/nonnative/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nonnative
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.26.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Falkowski
|
@@ -283,7 +283,6 @@ files:
|
|
283
283
|
- bin/setup
|
284
284
|
- lib/nonnative.rb
|
285
285
|
- lib/nonnative/before.rb
|
286
|
-
- lib/nonnative/chaos_proxy.rb
|
287
286
|
- lib/nonnative/close_all_socket_pair.rb
|
288
287
|
- lib/nonnative/command.rb
|
289
288
|
- lib/nonnative/configuration.rb
|
@@ -292,6 +291,7 @@ files:
|
|
292
291
|
- lib/nonnative/configuration_server.rb
|
293
292
|
- lib/nonnative/delay_socket_pair.rb
|
294
293
|
- lib/nonnative/error.rb
|
294
|
+
- lib/nonnative/fault_injection_proxy.rb
|
295
295
|
- lib/nonnative/grpc_server.rb
|
296
296
|
- lib/nonnative/http_client.rb
|
297
297
|
- lib/nonnative/http_server.rb
|