nonnative 1.25.0 → 1.26.0

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
  SHA256:
3
- metadata.gz: 02a90943c6dc7f21344409f9ee8be6f2a885fdf93a349ec89d3d0e690f040727
4
- data.tar.gz: '029e6c5d065db3e63a757d54fa163b9523c8dce1114341c43416709aa0fb3407'
3
+ metadata.gz: 12206912ca29ab82602d7d07fdc15f5b42124e890572d463ad1c4358c7de9f08
4
+ data.tar.gz: ee0393650b33d8a3c5b1d31019f717a3fb680f8872171c7fea1ac4892e186ad5
5
5
  SHA512:
6
- metadata.gz: 8274f8202cd8b5b4a9bf81872ef9d25944b58171451469ef16c2ca9040cceda0ed41ab3e28b69c780b33260c4bfee5c231e5947738bf12413d3324e0f00a9d3e
7
- data.tar.gz: bdedecceaf8a08ca7bd8b52e69fdbb8e5cc4336ca28677d0bce5f17a9db735a08d59a7180e2cd4e65c6819be704155ac6aac8a07db48d3ba293de2839ba69d84
6
+ metadata.gz: 9bbd95d62ddf01d04fd7f6bc4a783276e65dcc7775fbc1844316ee5f12ce150cf06cb3536c77e98f2b600fa5126fd2ed6e2946466559a53a4444ea4e1448b62f
7
+ data.tar.gz: 4417fe28fb3f291a7ac81bab44cbf398fc897acbf815397bd58aba7a72548c0320faba7aeab15778f7037c05b9fb84e2429cbd0a19ec6daba2d0c4f9f646318e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nonnative (1.25.0)
4
+ nonnative (1.26.0)
5
5
  concurrent-ruby (~> 1.0, >= 1.0.5)
6
6
  cucumber (>= 4, < 5)
7
7
  grpc (>= 1, < 2)
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
- - `chaos`
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: 'chaos',
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: chaos
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 `chaos` proxy allows you to simulate failures by injecting them. We currently support the following:
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.
@@ -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/chaos_proxy'
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'
@@ -46,6 +46,7 @@ module Nonnative
46
46
  s.proxy = {
47
47
  type: proxy['type'],
48
48
  port: proxy['port'],
49
+ log: proxy['log'],
49
50
  options: proxy['options']
50
51
  }
51
52
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Nonnative
4
4
  class ConfigurationProxy
5
- attr_accessor :type, :port, :options
5
+ attr_accessor :type, :port, :log, :options
6
6
 
7
7
  def initialize
8
8
  self.type = 'none'
@@ -12,6 +12,7 @@ module Nonnative
12
12
  def proxy=(value)
13
13
  proxy.type = value[:type]
14
14
  proxy.port = value[:port]
15
+ proxy.log = value[:log]
15
16
  proxy.options = value[:options]
16
17
  end
17
18
  end
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class ChaosProxy < Nonnative::Proxy
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
- SocketPairFactory.create(read_state, service.proxy).connect(local_socket)
51
- connections.delete(Thread.current.object_id)
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
- when 'chaos'
9
- ChaosProxy.new(service)
10
- else
11
- # By default we want no proxy.
12
- NoProxy.new(service)
13
- end
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, port)
7
- case type
8
- when :close_all
9
- CloseAllSocketPair.new(port)
10
- when :delay
11
- DelaySocketPair.new(port)
12
- when :invalid_data
13
- InvalidDataSocketPair.new(port)
14
- else
15
- SocketPair.new(port)
16
- end
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- VERSION = '1.25.0'
4
+ VERSION = '1.26.0'
5
5
  end
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.25.0
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