nonnative 1.25.0 → 1.30.0

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
  SHA256:
3
- metadata.gz: 02a90943c6dc7f21344409f9ee8be6f2a885fdf93a349ec89d3d0e690f040727
4
- data.tar.gz: '029e6c5d065db3e63a757d54fa163b9523c8dce1114341c43416709aa0fb3407'
3
+ metadata.gz: c7fcfc568dcb73f6f1b5263807e8da469598b6c800cac106ae804491a58be884
4
+ data.tar.gz: 814ef1f813b390375f91f01cfffe79fd250aa66b35f985f5923b0192313fe08f
5
5
  SHA512:
6
- metadata.gz: 8274f8202cd8b5b4a9bf81872ef9d25944b58171451469ef16c2ca9040cceda0ed41ab3e28b69c780b33260c4bfee5c231e5947738bf12413d3324e0f00a9d3e
7
- data.tar.gz: bdedecceaf8a08ca7bd8b52e69fdbb8e5cc4336ca28677d0bce5f17a9db735a08d59a7180e2cd4e65c6819be704155ac6aac8a07db48d3ba293de2839ba69d84
6
+ metadata.gz: 4f2b14b410443eab9974039a71ccfd1fbb68591096441822df23c4a64979e39d9378ff113713918446881b91e25fcef0c3a084edb5bd2fcf40d938dcdd311c4c
7
+ data.tar.gz: eea2c695c8ea090729c65ab0b8d4926d0242125b5c11f4d1ddd62576a013ea50d0f99252ffee62e28735d705e5d0b9b434687967525ee2736bb9c175e90cf62d
@@ -5,7 +5,7 @@ orbs:
5
5
  jobs:
6
6
  build:
7
7
  docker:
8
- - image: circleci/ruby:2.6
8
+ - image: circleci/ruby:2.7
9
9
  environment:
10
10
  BUNDLE_JOBS: "3"
11
11
  BUNDLE_PATH: vendor/bundle
@@ -1,6 +1,7 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.6
2
+ TargetRubyVersion: 2.7
3
3
  DisplayCopNames: true
4
+ NewCops: enable
4
5
 
5
6
  Layout/LineLength:
6
7
  Max: 120
@@ -16,54 +17,3 @@ Metrics/AbcSize:
16
17
 
17
18
  Style/Documentation:
18
19
  Enabled: false
19
-
20
- Lint/RaiseException:
21
- Enabled: true
22
-
23
- Style/HashEachMethods:
24
- Enabled: true
25
-
26
- Style/HashTransformKeys:
27
- Enabled: true
28
-
29
- Style/HashTransformValues:
30
- Enabled: true
31
-
32
- Lint/StructNewOverride:
33
- Enabled: true
34
-
35
- Layout/SpaceAroundMethodCallOperator:
36
- Enabled: true
37
-
38
- Style/ExponentialNotation:
39
- Enabled: true
40
-
41
- Layout/EmptyLinesAroundAttributeAccessor:
42
- Enabled: true
43
-
44
- Style/SlicingWithRange:
45
- Enabled: true
46
-
47
- Lint/DeprecatedOpenSSLConstant:
48
- Enabled: true
49
-
50
- Lint/MixedRegexpCaptureTypes:
51
- Enabled: true
52
-
53
- Style/RedundantRegexpCharacterClass:
54
- Enabled: true
55
-
56
- Style/RedundantRegexpEscape:
57
- Enabled: true
58
-
59
- Style/RedundantFetchBlock:
60
- Enabled: true
61
-
62
- Style/AccessorGrouping:
63
- Enabled: true
64
-
65
- Style/BisectedAttrAccessor:
66
- Enabled: true
67
-
68
- Style/RedundantAssignment:
69
- Enabled: true
@@ -1 +1 @@
1
- ruby-2.6.6
1
+ ruby-2.7.1
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nonnative (1.25.0)
4
+ nonnative (1.30.0)
5
5
  concurrent-ruby (~> 1.0, >= 1.0.5)
6
6
  cucumber (>= 4, < 5)
7
7
  grpc (>= 1, < 2)
8
- puma (~> 4.3, >= 4.3.3)
8
+ puma (~> 5.0)
9
9
  rest-client (~> 2.1)
10
10
  rspec-benchmark (~> 0.6.0)
11
11
  rspec-expectations (~> 3.9, >= 3.9.2)
@@ -14,7 +14,7 @@ PATH
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
- activesupport (6.0.3.2)
17
+ activesupport (6.0.3.3)
18
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
19
  i18n (>= 0.7, < 2)
20
20
  minitest (~> 5.1)
@@ -27,7 +27,7 @@ GEM
27
27
  benchmark-perf (0.6.0)
28
28
  benchmark-trend (0.4.0)
29
29
  builder (3.2.4)
30
- concurrent-ruby (1.1.6)
30
+ concurrent-ruby (1.1.7)
31
31
  cucumber (4.1.0)
32
32
  builder (~> 3.2, >= 3.2.3)
33
33
  cucumber-core (~> 7.1, >= 7.1.0)
@@ -47,12 +47,12 @@ GEM
47
47
  cucumber-create-meta (1.0.0)
48
48
  cucumber-messages (~> 12.2, >= 12.2.0)
49
49
  sys-uname (~> 1.2, >= 1.2.1)
50
- cucumber-cucumber-expressions (10.2.1)
51
- cucumber-gherkin (14.0.1)
52
- cucumber-messages (~> 12.2, >= 12.2.0)
53
- cucumber-html-formatter (7.0.0)
54
- cucumber-messages (~> 12.2, >= 12.2.0)
55
- cucumber-messages (12.2.0)
50
+ cucumber-cucumber-expressions (10.3.0)
51
+ cucumber-gherkin (14.2.0)
52
+ cucumber-messages (~> 12.4, >= 12.4.0)
53
+ cucumber-html-formatter (7.2.0)
54
+ cucumber-messages (~> 12.4, >= 12.4.0)
55
+ cucumber-messages (12.4.0)
56
56
  protobuf-cucumber (~> 3.10, >= 3.10.8)
57
57
  cucumber-tag-expressions (2.0.4)
58
58
  cucumber-wire (3.1.0)
@@ -65,50 +65,50 @@ GEM
65
65
  unf (>= 0.0.5, < 1.0.0)
66
66
  e2mmap (0.1.0)
67
67
  ffi (1.13.1)
68
- google-protobuf (3.12.2)
68
+ google-protobuf (3.13.0)
69
69
  googleapis-common-protos-types (1.0.5)
70
70
  google-protobuf (~> 3.11)
71
- grpc (1.30.1)
72
- google-protobuf (~> 3.12)
71
+ grpc (1.32.0)
72
+ google-protobuf (~> 3.13)
73
73
  googleapis-common-protos-types (~> 1.0)
74
- grpc-tools (1.30.1)
74
+ grpc-tools (1.32.0)
75
75
  http-accept (1.7.0)
76
76
  http-cookie (1.0.3)
77
77
  domain_name (~> 0.5)
78
- i18n (1.8.3)
78
+ i18n (1.8.5)
79
79
  concurrent-ruby (~> 1.0)
80
80
  jaro_winkler (1.5.4)
81
- json (2.3.0)
81
+ json (2.3.1)
82
82
  maruku (0.7.3)
83
83
  middleware (0.1.0)
84
84
  mime-types (3.3.1)
85
85
  mime-types-data (~> 3.2015)
86
86
  mime-types-data (3.2020.0512)
87
87
  mini_portile2 (2.4.0)
88
- minitest (5.14.1)
88
+ minitest (5.14.2)
89
89
  multi_test (0.1.2)
90
90
  mustermann (1.1.1)
91
91
  ruby2_keywords (~> 0.0.1)
92
92
  netrc (0.11.0)
93
- nio4r (2.5.2)
93
+ nio4r (2.5.4)
94
94
  nokogiri (1.10.10)
95
95
  mini_portile2 (~> 2.4.0)
96
96
  parallel (1.19.2)
97
- parser (2.7.1.4)
97
+ parser (2.7.1.5)
98
98
  ast (~> 2.4.1)
99
99
  protobuf-cucumber (3.10.8)
100
100
  activesupport (>= 3.2)
101
101
  middleware
102
102
  thor
103
103
  thread_safe
104
- puma (4.3.5)
104
+ puma (5.0.0)
105
105
  nio4r (~> 2.0)
106
106
  rack (2.2.3)
107
- rack-protection (2.0.8.1)
107
+ rack-protection (2.1.0)
108
108
  rack
109
109
  rainbow (3.0.0)
110
110
  rake (13.0.1)
111
- regexp_parser (1.7.1)
111
+ regexp_parser (1.8.0)
112
112
  rest-client (2.1.0)
113
113
  http-accept (>= 1.7.0, < 2.0)
114
114
  http-cookie (>= 1.0.2, < 2.0)
@@ -135,17 +135,17 @@ GEM
135
135
  diff-lcs (>= 1.2.0, < 2.0)
136
136
  rspec-support (~> 3.9.0)
137
137
  rspec-support (3.9.3)
138
- rubocop (0.87.1)
138
+ rubocop (0.92.0)
139
139
  parallel (~> 1.10)
140
- parser (>= 2.7.1.1)
140
+ parser (>= 2.7.1.5)
141
141
  rainbow (>= 2.2.2, < 4.0)
142
142
  regexp_parser (>= 1.7)
143
143
  rexml
144
- rubocop-ast (>= 0.1.0, < 1.0)
144
+ rubocop-ast (>= 0.5.0)
145
145
  ruby-progressbar (~> 1.7)
146
146
  unicode-display_width (>= 1.4.0, < 2.0)
147
- rubocop-ast (0.1.0)
148
- parser (>= 2.7.0.1)
147
+ rubocop-ast (0.6.0)
148
+ parser (>= 2.7.1.5)
149
149
  ruby-progressbar (1.10.1)
150
150
  ruby2_keywords (0.0.2)
151
151
  simplecov (0.17.1)
@@ -153,12 +153,12 @@ GEM
153
153
  json (>= 1.8, < 3)
154
154
  simplecov-html (~> 0.10.0)
155
155
  simplecov-html (0.10.2)
156
- sinatra (2.0.8.1)
156
+ sinatra (2.1.0)
157
157
  mustermann (~> 1.0)
158
- rack (~> 2.0)
159
- rack-protection (= 2.0.8.1)
158
+ rack (~> 2.2)
159
+ rack-protection (= 2.1.0)
160
160
  tilt (~> 2.0)
161
- solargraph (0.39.11)
161
+ solargraph (0.39.15)
162
162
  backport (~> 1.1)
163
163
  benchmark
164
164
  bundler (>= 1.17.2)
@@ -184,7 +184,7 @@ GEM
184
184
  unf_ext (0.0.7.7)
185
185
  unicode-display_width (1.7.0)
186
186
  yard (0.9.25)
187
- zeitwerk (2.3.1)
187
+ zeitwerk (2.4.0)
188
188
 
189
189
  PLATFORMS
190
190
  ruby
@@ -194,7 +194,7 @@ DEPENDENCIES
194
194
  grpc-tools (>= 1, < 2)
195
195
  nonnative!
196
196
  rake (~> 13.0, >= 13.0.1)
197
- rubocop (~> 0.87.1)
197
+ rubocop (~> 0.88)
198
198
  simplecov (~> 0.17.1)
199
199
  solargraph (~> 0.39.11)
200
200
 
data/Makefile CHANGED
@@ -13,7 +13,7 @@ analysis:
13
13
  bundle exec rubocop
14
14
 
15
15
  cleanup-analysis:
16
- bundle exec rubocop -a
16
+ bundle exec rubocop -A
17
17
 
18
18
  cleanup-logs:
19
19
  rm -rf features/logs/*.log
data/README.md CHANGED
@@ -37,10 +37,19 @@ Configure nonnative with the following:
37
37
  - A timeout value.
38
38
  - Port to verify.
39
39
  - The class for servers.
40
- - The file you want STDOUT to be logged to for processes.
40
+ - The log for servers/processes
41
41
  - The strategy for processes/servers.
42
- * Startup will start the process once.
43
- * Before will hook into cucumbers Before and After.
42
+
43
+ ### Strategy
44
+
45
+ The strategy can be one of the following values:
46
+ - startup - will start the process once.
47
+ - before - will hook into cucumbers Before and After.
48
+ - manual - do this manually
49
+
50
+ This can be overridden by the following environment variables:
51
+ - NONNATIVE_STRATEGY - Set this to override what is set in the config.
52
+ - NONNATIVE_TIMEOUT - Set this (in seconds, e.g 5) to override what is set in the config.
44
53
 
45
54
  ### Processes
46
55
 
@@ -50,12 +59,12 @@ Setup it up programmatically:
50
59
  require 'nonnative'
51
60
 
52
61
  Nonnative.configure do |config|
53
- config.strategy = :startup or :before or :manual
62
+ config.strategy = :startup
54
63
 
55
64
  config.process do |d|
56
65
  d.name = 'start_1'
57
66
  d.command = 'features/support/bin/start 12_321'
58
- d.timeout = 0.5
67
+ d.timeout = config.strategy.timeout
59
68
  d.port = 12_321
60
69
  d.log = 'features/logs/12_321.log'
61
70
  d.signal = 'INT' # Possible values are described in Signal.list.keys
@@ -310,7 +319,7 @@ Nonnative.load_configuration('configuration.yml')
310
319
 
311
320
  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
321
  - `none` (this is the default)
313
- - `chaos`
322
+ - `fault_injection`
314
323
 
315
324
  Setup it up programmatically:
316
325
 
@@ -322,8 +331,9 @@ Nonnative.configure do |config|
322
331
 
323
332
  config.server do |d|
324
333
  d.proxy = {
325
- type: 'chaos',
334
+ type: 'fault_injection',
326
335
  port: 20_000,
336
+ log: 'features/logs/proxy_server.log',
327
337
  options: {
328
338
  delay: 5
329
339
  }
@@ -340,15 +350,16 @@ strategy: manual
340
350
  servers:
341
351
  -
342
352
  proxy:
343
- type: chaos
353
+ type: fault_injection
344
354
  port: 20000
355
+ log: features/logs/proxy_server.log
345
356
  options:
346
357
  delay: 5
347
358
  ```
348
359
 
349
360
  ##### Fault Injection
350
361
 
351
- The `chaos` proxy allows you to simulate failures by injecting them. We currently support the following:
362
+ The `fault_injection` proxy allows you to simulate failures by injecting them. We currently support the following:
352
363
  - `close_all` - Closes the socket as soon as it connects.
353
364
  - `delay` - This delays the communication between the connection. Default is 2 secs can be configured through options.
354
365
  - `invalid_data` - This takes the input and rearranges it to produce invalid data.
@@ -362,3 +373,39 @@ server = Nonnative.pool.server_by_name(name)
362
373
  server.proxy.close_all # To use close_all.
363
374
  server.proxy.reset # To reset it back to a good state.
364
375
  ```
376
+
377
+
378
+ ### Go
379
+
380
+ As we love using go as a language for services we have added support to start binaries with defined parameters. This expects that you build your services in the format of `command sub_command --params`
381
+
382
+ To get this to work you will need to create a `main_test.go` file with these contents:
383
+
384
+ ```go
385
+ // +build features
386
+
387
+ package main
388
+
389
+ import (
390
+ "testing"
391
+ )
392
+
393
+ // TestFeatures is a hack that allows us to figure out what the coverage is during
394
+ // integration tests. I would not recommend that you use a binary built using
395
+ // this hack outside of a test suite.
396
+ func TestFeatures(t *testing.T) {
397
+ main()
398
+ }
399
+ ```
400
+
401
+ Then to compile this binary you will need to do the following:
402
+
403
+ ```sh
404
+ go test -mod vendor -c -tags features -covermode=count -o your_binary -coverpkg=./... github.com/your_location
405
+ ```
406
+
407
+ Then to get an executable you do the following:
408
+
409
+ ```ruby
410
+ Nonnative::GoCommand.new('your_binary', 'reports').executable('sub_command', '--config config.yaml')
411
+ ```
@@ -2,8 +2,8 @@
2
2
 
3
3
  require 'socket'
4
4
  require 'timeout'
5
- require 'thwait'
6
5
  require 'yaml'
6
+ require 'open3'
7
7
 
8
8
  require 'grpc'
9
9
  require 'sinatra'
@@ -29,17 +29,18 @@ require 'nonnative/server'
29
29
  require 'nonnative/http_client'
30
30
  require 'nonnative/http_server'
31
31
  require 'nonnative/grpc_server'
32
- require 'nonnative/grpc_server'
33
32
  require 'nonnative/observability'
34
33
  require 'nonnative/proxy_factory'
35
34
  require 'nonnative/proxy'
36
35
  require 'nonnative/no_proxy'
37
- require 'nonnative/chaos_proxy'
36
+ require 'nonnative/fault_injection_proxy'
38
37
  require 'nonnative/socket_pair'
39
38
  require 'nonnative/close_all_socket_pair'
40
39
  require 'nonnative/delay_socket_pair'
41
40
  require 'nonnative/invalid_data_socket_pair'
42
41
  require 'nonnative/socket_pair_factory'
42
+ require 'nonnative/strategy'
43
+ require 'nonnative/go_command'
43
44
 
44
45
  module Nonnative
45
46
  class << self
@@ -40,27 +40,35 @@ module Nonnative
40
40
  s.port = fd['port']
41
41
  s.log = fd['log']
42
42
 
43
- proxy = fd['proxy']
44
-
45
- if proxy
46
- s.proxy = {
47
- type: proxy['type'],
48
- port: proxy['port'],
49
- options: proxy['options']
50
- }
51
- end
43
+ proxy s, fd['proxy']
52
44
  end
53
45
  end
54
46
  end
47
+
48
+ def proxy(server, proxy)
49
+ return unless proxy
50
+
51
+ server.proxy = {
52
+ type: proxy['type'],
53
+ port: proxy['port'],
54
+ log: proxy['log'],
55
+ options: proxy['options']
56
+ }
57
+ end
55
58
  end
56
59
 
57
60
  def initialize
58
- self.strategy = :before
59
- self.processes = []
60
- self.servers = []
61
+ @strategy = Strategy.new
62
+ @processes = []
63
+ @servers = []
61
64
  end
62
65
 
63
- attr_accessor :strategy, :processes, :servers
66
+ attr_accessor :processes, :servers
67
+ attr_reader :strategy
68
+
69
+ def strategy=(value)
70
+ @strategy = Strategy.new(value)
71
+ end
64
72
 
65
73
  def process
66
74
  process = Nonnative::ConfigurationProcess.new
@@ -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
@@ -3,7 +3,7 @@
3
3
  module Nonnative
4
4
  class DelaySocketPair < SocketPair
5
5
  def read(socket)
6
- duration = proxy.options.dig(:delay) || 2
6
+ duration = proxy.options[:delay] || 2
7
7
  sleep duration
8
8
 
9
9
  super socket
@@ -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
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nonnative
4
+ class GoCommand
5
+ def initialize(main, output)
6
+ @main = main
7
+ @output = output
8
+ end
9
+
10
+ def executable(cmd, *params)
11
+ params = params.join(' ')
12
+ "#{main} #{flags(cmd, params).join(' ')} #{cmd} #{params}"
13
+ end
14
+
15
+ def execute(cmd, *params)
16
+ Open3.popen3(executable(cmd, params)) do |_stdin, stdout, stderr, wait_thr|
17
+ return stdout.read, stderr.read, wait_thr.value
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :main, :output
24
+
25
+ def flags(cmd, params)
26
+ m = File.basename(main, File.extname(main))
27
+ p = params.gsub(/\W/, '')
28
+ path = "#{output}/#{m}-#{cmd}-#{p}"
29
+
30
+ [
31
+ "-test.cpuprofile=#{path}-cpu.prof",
32
+ "-test.memprofile=#{path}-mem.prof",
33
+ "-test.blockprofile=#{path}-block.prof",
34
+ "-test.mutexprofile=#{path}-mutex.prof",
35
+ "-test.coverprofile=#{path}.cov",
36
+ "-test.trace=#{path}-trace.out"
37
+ ]
38
+ end
39
+ end
40
+ end
@@ -46,8 +46,6 @@ module Nonnative
46
46
  threads << Thread.new { port.send(port_method) }
47
47
  end
48
48
 
49
- ThreadsWait.all_waits(*threads)
50
-
51
49
  ports = threads.map(&:value)
52
50
 
53
51
  yield_results(types, pids, ports, &block)
@@ -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
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nonnative
4
+ class Strategy
5
+ def initialize(strategy = 'before', timeout = 5)
6
+ @strategy = strategy
7
+ @timeout = timeout
8
+ end
9
+
10
+ def timeout
11
+ (env_timeout || @timeout).to_i
12
+ end
13
+
14
+ def to_s
15
+ (env_strategy || @strategy).to_s
16
+ end
17
+
18
+ private
19
+
20
+ def env_strategy
21
+ @env_strategy ||= ENV['NONNATIVE_STRATEGY']
22
+ end
23
+
24
+ def env_timeout
25
+ @env_timeout ||= ENV['NONNATIVE_TIMEOUT']
26
+ end
27
+ end
28
+ end
@@ -6,10 +6,8 @@ module Nonnative
6
6
  @time = time
7
7
  end
8
8
 
9
- def perform
10
- ::Timeout.timeout(time) do
11
- yield
12
- end
9
+ def perform(&block)
10
+ ::Timeout.timeout(time, &block)
13
11
  rescue ::Timeout::Error
14
12
  false
15
13
  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.30.0'
5
5
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
5
6
  require 'nonnative/version'
6
7
 
7
8
  Gem::Specification.new do |spec|
@@ -14,20 +15,18 @@ Gem::Specification.new do |spec|
14
15
  spec.description = spec.summary
15
16
  spec.homepage = 'https://github.com/alexfalkowski/nonnative'
16
17
  spec.license = 'Unlicense'
17
-
18
- # Specify which files should be added to the gem when it is released.
19
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
18
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
19
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
20
  end
23
21
  spec.bindir = 'exe'
24
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
23
  spec.require_paths = ['lib']
24
+ spec.required_ruby_version = ['>= 2.0.0', '< 2.8.0']
26
25
 
27
26
  spec.add_dependency 'concurrent-ruby', '~> 1.0', '>= 1.0.5'
28
27
  spec.add_dependency 'cucumber', ['>= 4', '< 5']
29
28
  spec.add_dependency 'grpc', ['>= 1', '< 2']
30
- spec.add_dependency 'puma', '~> 4.3', '>= 4.3.3'
29
+ spec.add_dependency 'puma', '~> 5.0'
31
30
  spec.add_dependency 'rest-client', '~> 2.1'
32
31
  spec.add_dependency 'rspec-benchmark', '~> 0.6.0'
33
32
  spec.add_dependency 'rspec-expectations', '~> 3.9', '>= 3.9.2'
@@ -36,7 +35,7 @@ Gem::Specification.new do |spec|
36
35
  spec.add_development_dependency 'bundler', '~> 2.1', '>= 2.1.4'
37
36
  spec.add_development_dependency 'grpc-tools', ['>= 1', '< 2']
38
37
  spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.1'
39
- spec.add_development_dependency 'rubocop', '~> 0.87.1'
38
+ spec.add_development_dependency 'rubocop', '~> 0.88'
40
39
  spec.add_development_dependency 'simplecov', '~> 0.17.1'
41
40
  spec.add_development_dependency 'solargraph', '~> 0.39.11'
42
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.30.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Falkowski
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-12 00:00:00.000000000 Z
11
+ date: 2020-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -76,20 +76,14 @@ dependencies:
76
76
  requirements:
77
77
  - - "~>"
78
78
  - !ruby/object:Gem::Version
79
- version: '4.3'
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 4.3.3
79
+ version: '5.0'
83
80
  type: :runtime
84
81
  prerelease: false
85
82
  version_requirements: !ruby/object:Gem::Requirement
86
83
  requirements:
87
84
  - - "~>"
88
85
  - !ruby/object:Gem::Version
89
- version: '4.3'
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: 4.3.3
86
+ version: '5.0'
93
87
  - !ruby/object:Gem::Dependency
94
88
  name: rest-client
95
89
  requirement: !ruby/object:Gem::Requirement
@@ -224,14 +218,14 @@ dependencies:
224
218
  requirements:
225
219
  - - "~>"
226
220
  - !ruby/object:Gem::Version
227
- version: 0.87.1
221
+ version: '0.88'
228
222
  type: :development
229
223
  prerelease: false
230
224
  version_requirements: !ruby/object:Gem::Requirement
231
225
  requirements:
232
226
  - - "~>"
233
227
  - !ruby/object:Gem::Version
234
- version: 0.87.1
228
+ version: '0.88'
235
229
  - !ruby/object:Gem::Dependency
236
230
  name: simplecov
237
231
  requirement: !ruby/object:Gem::Requirement
@@ -283,7 +277,6 @@ files:
283
277
  - bin/setup
284
278
  - lib/nonnative.rb
285
279
  - lib/nonnative/before.rb
286
- - lib/nonnative/chaos_proxy.rb
287
280
  - lib/nonnative/close_all_socket_pair.rb
288
281
  - lib/nonnative/command.rb
289
282
  - lib/nonnative/configuration.rb
@@ -292,6 +285,8 @@ files:
292
285
  - lib/nonnative/configuration_server.rb
293
286
  - lib/nonnative/delay_socket_pair.rb
294
287
  - lib/nonnative/error.rb
288
+ - lib/nonnative/fault_injection_proxy.rb
289
+ - lib/nonnative/go_command.rb
295
290
  - lib/nonnative/grpc_server.rb
296
291
  - lib/nonnative/http_client.rb
297
292
  - lib/nonnative/http_server.rb
@@ -310,6 +305,7 @@ files:
310
305
  - lib/nonnative/start_error.rb
311
306
  - lib/nonnative/startup.rb
312
307
  - lib/nonnative/stop_error.rb
308
+ - lib/nonnative/strategy.rb
313
309
  - lib/nonnative/timeout.rb
314
310
  - lib/nonnative/version.rb
315
311
  - nonnative.gemspec
@@ -318,7 +314,7 @@ homepage: https://github.com/alexfalkowski/nonnative
318
314
  licenses:
319
315
  - Unlicense
320
316
  metadata: {}
321
- post_install_message:
317
+ post_install_message:
322
318
  rdoc_options: []
323
319
  require_paths:
324
320
  - lib
@@ -326,15 +322,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
326
322
  requirements:
327
323
  - - ">="
328
324
  - !ruby/object:Gem::Version
329
- version: '0'
325
+ version: 2.0.0
326
+ - - "<"
327
+ - !ruby/object:Gem::Version
328
+ version: 2.8.0
330
329
  required_rubygems_version: !ruby/object:Gem::Requirement
331
330
  requirements:
332
331
  - - ">="
333
332
  - !ruby/object:Gem::Version
334
333
  version: '0'
335
334
  requirements: []
336
- rubygems_version: 3.0.8
337
- signing_key:
335
+ rubygems_version: 3.1.2
336
+ signing_key:
338
337
  specification_version: 4
339
338
  summary: Allows you to keep using the power of ruby to test other systems
340
339
  test_files: []