nonnative 1.14.0 → 1.19.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: d3d063b72e79c07612ef45de94f2b318c59d600be60823a3b72b97e14b819863
4
- data.tar.gz: e49d9d93bd0657896c7fb1abba459ca59c6c8fc3e59b409fe9c231b20f77cf34
3
+ metadata.gz: d50a3cb35c875fa077d8ca3bd756e11d10deaffec26a90b142dc8e70a690ba97
4
+ data.tar.gz: 8396fbee42d4d138ca270a39cf916f701a3874aa55c62312f05bc613de39b1ed
5
5
  SHA512:
6
- metadata.gz: 7d12d87e1f2681fc8e9fef1eecb5b55d81eb773b1845ffb22ab094c17cd9d73bced1874ee277e11c024ca82d66d9f7c4c9d49f6f3827052f06d0ce3bdc86f1f5
7
- data.tar.gz: 6436da5c0393b9842881722a50f23e80f3264c0a36006e9aeb8402b26910645e875313b430da8df9bd2ba02b5ff08bce576cc74f590a8b5707f6454a27ca83b4
6
+ metadata.gz: f7b04f930d6743048cbb33bf5e7cdcfc915aee45ce1f788ec392fe100edab8a2a39e714fe6bb51a8bfd376d51c00c15870a3a3d5f79bd7449ce1ffaefbeea628
7
+ data.tar.gz: 35df2beddc2ef0c9aae2c5f4c5c4f4e0a3ea013af03571a01024aa0cf329804f0867bd59d8087ec04c91eef10a53150a2a251998cf4fa4a1d07a4f66812f6328
@@ -8,6 +8,12 @@ Layout/LineLength:
8
8
  Metrics/MethodLength:
9
9
  Max: 15
10
10
 
11
+ Metrics/BlockLength:
12
+ Max: 50
13
+
14
+ Metrics/AbcSize:
15
+ Max: 20
16
+
11
17
  Style/Documentation:
12
18
  Enabled: false
13
19
 
@@ -37,3 +43,18 @@ Layout/EmptyLinesAroundAttributeAccessor:
37
43
 
38
44
  Style/SlicingWithRange:
39
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nonnative (1.14.0)
4
+ nonnative (1.19.0)
5
5
  cucumber (~> 3.1, >= 3.1.2)
6
6
  grpc (~> 1.28)
7
7
  puma (~> 4.3, >= 4.3.3)
@@ -18,7 +18,7 @@ GEM
18
18
  tins (~> 1.0)
19
19
  ast (2.4.1)
20
20
  backport (1.1.2)
21
- backports (3.17.2)
21
+ backports (3.18.1)
22
22
  benchmark (0.1.0)
23
23
  benchmark-malloc (0.2.0)
24
24
  benchmark-perf (0.6.0)
@@ -47,7 +47,7 @@ GEM
47
47
  cucumber-expressions (6.0.1)
48
48
  cucumber-tag_expressions (1.1.1)
49
49
  cucumber-wire (0.0.1)
50
- diff-lcs (1.3)
50
+ diff-lcs (1.4.4)
51
51
  docile (1.3.2)
52
52
  domain_name (0.5.20190701)
53
53
  unf (>= 0.0.5, < 1.0.0)
@@ -84,8 +84,8 @@ GEM
84
84
  nokogiri (1.10.9)
85
85
  mini_portile2 (~> 2.4.0)
86
86
  parallel (1.19.2)
87
- parser (2.7.1.3)
88
- ast (~> 2.4.0)
87
+ parser (2.7.1.4)
88
+ ast (~> 2.4.1)
89
89
  pastel (0.7.4)
90
90
  equatable (~> 0.6)
91
91
  tty-color (~> 0.5)
@@ -98,6 +98,7 @@ GEM
98
98
  rack
99
99
  rainbow (3.0.0)
100
100
  rake (13.0.1)
101
+ regexp_parser (1.7.1)
101
102
  rest-client (2.1.0)
102
103
  http-accept (>= 1.7.0, < 2.0)
103
104
  http-cookie (>= 1.0.2, < 2.0)
@@ -124,13 +125,17 @@ GEM
124
125
  diff-lcs (>= 1.2.0, < 2.0)
125
126
  rspec-support (~> 3.9.0)
126
127
  rspec-support (3.9.3)
127
- rubocop (0.83.0)
128
+ rubocop (0.86.0)
128
129
  parallel (~> 1.10)
129
130
  parser (>= 2.7.0.1)
130
131
  rainbow (>= 2.2.2, < 4.0)
132
+ regexp_parser (>= 1.7)
131
133
  rexml
134
+ rubocop-ast (>= 0.0.3, < 1.0)
132
135
  ruby-progressbar (~> 1.7)
133
136
  unicode-display_width (>= 1.4.0, < 2.0)
137
+ rubocop-ast (0.1.0)
138
+ parser (>= 2.7.0.1)
134
139
  ruby-progressbar (1.10.1)
135
140
  ruby2_keywords (0.0.2)
136
141
  ruby_parser (3.14.2)
@@ -146,7 +151,7 @@ GEM
146
151
  rack (~> 2.0)
147
152
  rack-protection (= 2.0.8.1)
148
153
  tilt (~> 2.0)
149
- solargraph (0.39.8)
154
+ solargraph (0.39.11)
150
155
  backport (~> 1.1)
151
156
  benchmark
152
157
  bundler (>= 1.17.2)
@@ -185,7 +190,7 @@ DEPENDENCIES
185
190
  grpc-tools (~> 1.28)
186
191
  nonnative!
187
192
  rake (~> 13.0, >= 13.0.1)
188
- rubocop (~> 0.83.0)
193
+ rubocop (~> 0.86.0)
189
194
  simplecov (~> 0.17.1)
190
195
  solargraph (~> 0.39.7)
191
196
 
data/Makefile CHANGED
@@ -7,7 +7,7 @@ outdated-dependencies:
7
7
  bundle outdated --only-explicit
8
8
 
9
9
  features: clean
10
- bundle exec cucumber --profile report $(feature)
10
+ bundle exec cucumber --profile report --fail-fast $(feature)
11
11
 
12
12
  analysis:
13
13
  bundle exec rubocop
data/README.md CHANGED
@@ -38,13 +38,11 @@ Configure nonnative with the following:
38
38
  - Port to verify.
39
39
  - The class for servers.
40
40
  - The file you want STDOUT to be logged to for processes.
41
- - The strategy (Startup will start the process once and before will hook into cucumbers Before and After) for processes.
41
+ - The strategy for processes/servers.
42
+ * Startup will start the process once.
43
+ * Before will hook into cucumbers Before and After.
42
44
 
43
- ### Ruby
44
-
45
- We can start a process, server or both.
46
-
47
- #### Processes
45
+ ### Processes
48
46
 
49
47
  Setup it up programmatically:
50
48
 
@@ -55,13 +53,16 @@ Nonnative.configure do |config|
55
53
  config.strategy = :startup or :before or :manual
56
54
 
57
55
  config.process do |d|
56
+ d.name = 'start_1'
58
57
  d.command = 'features/support/bin/start 12_321'
59
58
  d.timeout = 0.5
60
59
  d.port = 12_321
61
60
  d.file = 'features/logs/12_321.log'
61
+ d.signal = 'INT' # Possible values are described in Signal.list.keys
62
62
  end
63
63
 
64
64
  config.process do |d|
65
+ d.name = 'start_2'
65
66
  d.command = 'features/support/bin/start 12_322'
66
67
  d.timeout = 0.5
67
68
  d.port = 12_322
@@ -77,11 +78,14 @@ version: 1.0
77
78
  strategy: manual
78
79
  processes:
79
80
  -
81
+ name: start_1
80
82
  command: features/support/bin/start 12_321
81
83
  timeout: 5
82
84
  port: 12321
83
85
  file: features/logs/12_321.log
86
+ signal: INT # Possible values are described in Signal.list.keys
84
87
  -
88
+ name: start_2
85
89
  command: features/support/bin/start 12_322
86
90
  timeout: 5
87
91
  port: 12322
@@ -96,7 +100,7 @@ require 'nonnative'
96
100
  Nonnative.load_configuration('configuration.yml')
97
101
  ```
98
102
 
99
- #### Servers
103
+ ### Servers
100
104
 
101
105
  Define your server:
102
106
 
@@ -130,12 +134,14 @@ Nonnative.configure do |config|
130
134
  config.strategy = :manual
131
135
 
132
136
  config.server do |d|
137
+ d.name = 'server_1'
133
138
  d.klass = Nonnative::EchoServer
134
139
  d.timeout = 1
135
140
  d.port = 12_323
136
141
  end
137
142
 
138
143
  config.server do |d|
144
+ d.name = 'server_2'
139
145
  d.klass = Nonnative::EchoServer
140
146
  d.timeout = 1
141
147
  d.port = 12_324
@@ -150,10 +156,12 @@ version: 1.0
150
156
  strategy: manual
151
157
  servers:
152
158
  -
159
+ name: server_1
153
160
  klass: Nonnative::EchoServer
154
161
  timeout: 1
155
162
  port: 12323
156
163
  -
164
+ name: server_2
157
165
  klass: Nonnative::EchoServer
158
166
  timeout: 1
159
167
  port: 12324
@@ -167,26 +175,22 @@ require 'nonnative'
167
175
  Nonnative.load_configuration('configuration.yml')
168
176
  ```
169
177
 
170
- ##### HTTP
178
+ #### HTTP
171
179
 
172
180
  Define your server:
173
181
 
174
182
  ```ruby
175
183
  module Nonnative
176
184
  module Features
177
- module Hello
178
- class << self
179
- def registered(app)
180
- app.get '/hello' do
181
- 'Hello World!'
182
- end
183
- end
185
+ class Application < Sinatra::Base
186
+ get '/hello' do
187
+ 'Hello World!'
184
188
  end
185
189
  end
186
190
 
187
191
  class HTTPServer < Nonnative::HTTPServer
188
- def configure(http)
189
- http.register(Hello)
192
+ def app
193
+ Application.new
190
194
  end
191
195
  end
192
196
  end
@@ -202,6 +206,7 @@ Nonnative.configure do |config|
202
206
  config.strategy = :manual
203
207
 
204
208
  config.server do |d|
209
+ d.name = 'http_server_1'
205
210
  d.klass = Nonnative::Features::HTTPServer
206
211
  d.timeout = 1
207
212
  d.port = 4567
@@ -216,6 +221,7 @@ version: 1.0
216
221
  strategy: manual
217
222
  servers:
218
223
  -
224
+ name: http_server_1
219
225
  klass: Nonnative::Features::HTTPServer
220
226
  timeout: 1
221
227
  port: 4567
@@ -229,7 +235,7 @@ require 'nonnative'
229
235
  Nonnative.load_configuration('configuration.yml')
230
236
  ```
231
237
 
232
- ##### gRPC
238
+ #### gRPC
233
239
 
234
240
  Define your server:
235
241
 
@@ -243,8 +249,8 @@ module Nonnative
243
249
  end
244
250
 
245
251
  class GRPCServer < Nonnative::GRPCServer
246
- def configure(grpc)
247
- grpc.handle(GreeterService.new)
252
+ def svc
253
+ GreeterService.new
248
254
  end
249
255
  end
250
256
  end
@@ -260,6 +266,7 @@ Nonnative.configure do |config|
260
266
  config.strategy = :manual
261
267
 
262
268
  config.server do |d|
269
+ d.name = 'grpc_server_1'
263
270
  d.klass = Nonnative::Features::GRPCServer
264
271
  d.timeout = 1
265
272
  d.port = 9002
@@ -274,6 +281,7 @@ version: 1.0
274
281
  strategy: manual
275
282
  servers:
276
283
  -
284
+ name: grpc_server_1
277
285
  klass: Nonnative::Features::GRPCServer
278
286
  timeout: 1
279
287
  port: 9002
@@ -286,3 +294,35 @@ require 'nonnative'
286
294
 
287
295
  Nonnative.load_configuration('configuration.yml')
288
296
  ```
297
+ #### Proxies
298
+
299
+ 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:
300
+ - none (this is the default)
301
+ - chaos
302
+
303
+ Setup it up programmatically:
304
+
305
+ ```ruby
306
+ require 'nonnative'
307
+
308
+ Nonnative.configure do |config|
309
+ config.strategy = :manual
310
+
311
+ config.server do |d|
312
+ d.proxy.type = 'chaos'
313
+ d.proxy.port = 20_000
314
+ end
315
+ end
316
+ ```
317
+
318
+ Setup it up through configuration:
319
+
320
+ ```yaml
321
+ version: 1.0
322
+ strategy: manual
323
+ servers:
324
+ -
325
+ proxy:
326
+ type: chaos
327
+ port: 20000
328
+ ```
@@ -8,6 +8,8 @@ require 'yaml'
8
8
  require 'grpc'
9
9
  require 'sinatra'
10
10
  require 'rest-client'
11
+ require 'puma'
12
+ require 'puma/server'
11
13
 
12
14
  require 'nonnative/version'
13
15
  require 'nonnative/error'
@@ -18,16 +20,22 @@ require 'nonnative/port'
18
20
  require 'nonnative/configuration'
19
21
  require 'nonnative/configuration_process'
20
22
  require 'nonnative/configuration_server'
23
+ require 'nonnative/configuration_proxy'
21
24
  require 'nonnative/service'
22
25
  require 'nonnative/command'
23
26
  require 'nonnative/pool'
24
27
  require 'nonnative/server'
25
28
  require 'nonnative/http_client'
26
- require 'nonnative/application'
27
29
  require 'nonnative/http_server'
28
30
  require 'nonnative/grpc_server'
29
31
  require 'nonnative/grpc_server'
30
32
  require 'nonnative/observability'
33
+ require 'nonnative/proxy_factory'
34
+ require 'nonnative/proxy'
35
+ require 'nonnative/no_proxy'
36
+ require 'nonnative/chaos_proxy'
37
+
38
+ Thread.abort_on_exception = true
31
39
 
32
40
  module Nonnative
33
41
  class << self
@@ -40,7 +48,7 @@ module Nonnative
40
48
  end
41
49
 
42
50
  def configure
43
- yield configuration if block_given?
51
+ yield configuration
44
52
 
45
53
  require "nonnative/#{configuration.strategy}"
46
54
  end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nonnative
4
+ class ChaosProxy < Nonnative::Proxy
5
+ def start
6
+ @tcp_server = ::TCPServer.new('0.0.0.0', service.port)
7
+ @thread = Thread.new { perform_start }
8
+ end
9
+
10
+ def stop
11
+ thread.terminate
12
+ tcp_server.close
13
+ end
14
+
15
+ def port
16
+ service.proxy.port
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :tcp_server, :thread
22
+
23
+ def perform_start
24
+ loop do
25
+ Thread.start(tcp_server.accept) { |local_socket| connect(local_socket) }
26
+ end
27
+ end
28
+
29
+ def connect(local_socket)
30
+ remote_socket = create_remote_socket
31
+ return unless remote_socket
32
+
33
+ loop do
34
+ ready = select([local_socket, remote_socket], nil, nil)
35
+
36
+ break if write(ready, local_socket, remote_socket)
37
+ break if write(ready, remote_socket, local_socket)
38
+ end
39
+ rescue Errno::ECONNRESET
40
+ # Just ignore it.
41
+ ensure
42
+ local_socket.close
43
+ remote_socket&.close
44
+ end
45
+
46
+ def create_remote_socket
47
+ timeout.perform do
48
+ ::TCPSocket.new('0.0.0.0', port)
49
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
50
+ sleep 0.01
51
+ retry
52
+ end
53
+ end
54
+
55
+ def write(ready, socket1, socket2)
56
+ if ready[0].include?(socket1)
57
+ data = socket1.recv(1024)
58
+ return true if data.empty?
59
+
60
+ socket2.write(data)
61
+ end
62
+
63
+ false
64
+ end
65
+ end
66
+ end
@@ -2,15 +2,6 @@
2
2
 
3
3
  module Nonnative
4
4
  class Command < Nonnative::Service
5
- def initialize(service)
6
- @service = service
7
- @timeout = Nonnative::Timeout.new(service.timeout)
8
- end
9
-
10
- def name
11
- service.command
12
- end
13
-
14
5
  def start
15
6
  unless command_exists?
16
7
  @pid = command_spawn
@@ -39,10 +30,11 @@ module Nonnative
39
30
 
40
31
  private
41
32
 
42
- attr_reader :service, :timeout, :pid
33
+ attr_reader :pid
43
34
 
44
35
  def command_kill
45
- Process.kill('SIGINT', pid)
36
+ signal = Signal.list[service.signal || 'INT'] || Signal.list['INT']
37
+ Process.kill(signal, pid)
46
38
  end
47
39
 
48
40
  def command_spawn
@@ -52,7 +44,8 @@ module Nonnative
52
44
  def command_exists?
53
45
  return false if pid.nil?
54
46
 
55
- Process.kill(0, pid)
47
+ signal = Signal.list['EXIT']
48
+ Process.kill(signal, pid)
56
49
  true
57
50
  rescue Errno::ESRCH
58
51
  false
@@ -20,10 +20,12 @@ module Nonnative
20
20
  processes = file['processes'] || []
21
21
  processes.each do |fd|
22
22
  config.process do |d|
23
+ d.name = fd['name']
23
24
  d.command = fd['command']
24
25
  d.timeout = fd['timeout']
25
26
  d.port = fd['port']
26
27
  d.file = fd['file']
28
+ d.signal = fd['signal']
27
29
  end
28
30
  end
29
31
  end
@@ -32,9 +34,17 @@ module Nonnative
32
34
  servers = file['servers'] || []
33
35
  servers.each do |fd|
34
36
  config.server do |s|
37
+ s.name = fd['name']
35
38
  s.klass = Object.const_get(fd['klass'])
36
39
  s.timeout = fd['timeout']
37
40
  s.port = fd['port']
41
+
42
+ proxy = fd['proxy']
43
+
44
+ if proxy
45
+ s.proxy.type = proxy['type']
46
+ s.proxy.port = proxy['port']
47
+ end
38
48
  end
39
49
  end
40
50
  end
@@ -2,9 +2,11 @@
2
2
 
3
3
  module Nonnative
4
4
  class ConfigurationProcess
5
+ attr_accessor :name
5
6
  attr_accessor :command
6
7
  attr_accessor :timeout
7
8
  attr_accessor :port
8
9
  attr_accessor :file
10
+ attr_accessor :signal
9
11
  end
10
12
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nonnative
4
+ class ConfigurationProxy
5
+ attr_accessor :type
6
+ attr_accessor :port
7
+
8
+ def initialize
9
+ self.type = 'none'
10
+ self.port = 0
11
+ end
12
+ end
13
+ end
@@ -2,8 +2,14 @@
2
2
 
3
3
  module Nonnative
4
4
  class ConfigurationServer
5
+ attr_accessor :name
5
6
  attr_accessor :klass
6
7
  attr_accessor :timeout
7
8
  attr_accessor :port
9
+ attr_accessor :proxy
10
+
11
+ def initialize
12
+ self.proxy = Nonnative::ConfigurationProxy.new
13
+ end
8
14
  end
9
15
  end
@@ -4,18 +4,15 @@ module Nonnative
4
4
  class GRPCServer < Nonnative::Server
5
5
  def initialize(service)
6
6
  @server = GRPC::RpcServer.new
7
-
8
- server.add_http2_port("0.0.0.0:#{service.port}", :this_port_is_insecure)
9
- configure server
7
+ server.handle(svc)
10
8
 
11
9
  super service
12
10
  end
13
11
 
14
- def configure(grpc)
15
- # Classes will add configuration
16
- end
12
+ protected
17
13
 
18
14
  def perform_start
15
+ server.add_http2_port("0.0.0.0:#{proxy.port}", :this_port_is_insecure)
19
16
  server.run
20
17
  end
21
18
 
@@ -23,10 +20,16 @@ module Nonnative
23
20
  server.stop
24
21
  end
25
22
 
26
- protected
27
-
28
23
  def wait_start
29
- server.wait_till_running(service.timeout)
24
+ timeout.perform do
25
+ super until server.running?
26
+ end
27
+ end
28
+
29
+ def wait_stop
30
+ timeout.perform do
31
+ super until server.stopped?
32
+ end
30
33
  end
31
34
 
32
35
  private
@@ -3,39 +3,36 @@
3
3
  module Nonnative
4
4
  class HTTPServer < Nonnative::Server
5
5
  def initialize(service)
6
- @timeout = Nonnative::Timeout.new(service.timeout)
7
- @queue = Queue.new
8
-
9
- Application.set :port, service.port
10
- configure Application
6
+ @server = Puma::Server.new(app, Puma::Events.strings)
11
7
 
12
8
  super service
13
9
  end
14
10
 
15
- def configure(http)
16
- # Classes will add configuration
17
- end
11
+ protected
18
12
 
19
13
  def perform_start
20
- Application.start! do |server|
21
- queue << server
22
- end
14
+ server.add_tcp_listener '0.0.0.0', proxy.port
15
+ server.run.join
23
16
  end
24
17
 
25
18
  def perform_stop
26
- Application.stop!
19
+ server.stop(true)
27
20
  end
28
21
 
29
- protected
30
-
31
22
  def wait_start
32
23
  timeout.perform do
33
- queue.pop
24
+ super until server.running
25
+ end
26
+ end
27
+
28
+ def wait_stop
29
+ timeout.perform do
30
+ super while server.running
34
31
  end
35
32
  end
36
33
 
37
34
  private
38
35
 
39
- attr_reader :timeout, :queue
36
+ attr_reader :queue, :server
40
37
  end
41
38
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nonnative
4
+ class NoProxy < Proxy
5
+ def start
6
+ # Do nothing.
7
+ end
8
+
9
+ def stop
10
+ # Do nothing.
11
+ end
12
+
13
+ def port
14
+ service.port
15
+ end
16
+ end
17
+ end
@@ -7,13 +7,11 @@ module Nonnative
7
7
  end
8
8
 
9
9
  def start(&block)
10
- all = processes + servers
11
- process_all(all, :start, :open?, &block)
10
+ [servers, processes].each { |t| process(t, :start, :open?, &block) }
12
11
  end
13
12
 
14
13
  def stop(&block)
15
- all = processes + servers
16
- process_all(all, :stop, :closed?, &block)
14
+ [processes, servers].each { |t| process(t, :stop, :closed?, &block) }
17
15
  end
18
16
 
19
17
  private
@@ -32,7 +30,7 @@ module Nonnative
32
30
  end
33
31
  end
34
32
 
35
- def process_all(all, type_method, port_method, &block)
33
+ def process(all, type_method, port_method, &block)
36
34
  types = []
37
35
  pids = []
38
36
  threads = []
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nonnative
4
+ class Proxy
5
+ def initialize(service)
6
+ @service = service
7
+ @timeout = Nonnative::Timeout.new(service.timeout)
8
+ end
9
+
10
+ protected
11
+
12
+ attr_reader :service, :timeout
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nonnative
4
+ class ProxyFactory
5
+ class << self
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
14
+ end
15
+ end
16
+ end
17
+ end
@@ -3,17 +3,17 @@
3
3
  module Nonnative
4
4
  class Server < Nonnative::Service
5
5
  def initialize(service)
6
- @service = service
7
6
  @id = SecureRandom.hex(5)
8
- end
7
+ @proxy = Nonnative::ProxyFactory.create(service)
9
8
 
10
- def name
11
- self.class.to_s
9
+ super service
12
10
  end
13
11
 
14
12
  def start
15
13
  unless thread
14
+ proxy.start
16
15
  @thread = Thread.new { perform_start }
16
+
17
17
  wait_start
18
18
  end
19
19
 
@@ -24,6 +24,8 @@ module Nonnative
24
24
  if thread
25
25
  perform_stop
26
26
  thread.terminate
27
+ proxy.stop
28
+
27
29
  @thread = nil
28
30
  wait_stop
29
31
  end
@@ -31,6 +33,12 @@ module Nonnative
31
33
  id
32
34
  end
33
35
 
34
- attr_reader :service, :id, :thread
36
+ protected
37
+
38
+ attr_reader :id
39
+
40
+ private
41
+
42
+ attr_reader :proxy, :thread
35
43
  end
36
44
  end
@@ -2,8 +2,19 @@
2
2
 
3
3
  module Nonnative
4
4
  class Service
5
+ def initialize(service)
6
+ @service = service
7
+ @timeout = Nonnative::Timeout.new(service.timeout)
8
+ end
9
+
10
+ def name
11
+ service.name
12
+ end
13
+
5
14
  protected
6
15
 
16
+ attr_reader :service, :timeout
17
+
7
18
  def wait_start
8
19
  sleep 0.1
9
20
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- VERSION = '1.14.0'
4
+ VERSION = '1.19.0'
5
5
  end
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency 'chutney', '~> 2.0', '>= 2.0.3.1'
37
37
  spec.add_development_dependency 'grpc-tools', '~> 1.28'
38
38
  spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.1'
39
- spec.add_development_dependency 'rubocop', '~> 0.83.0'
39
+ spec.add_development_dependency 'rubocop', '~> 0.86.0'
40
40
  spec.add_development_dependency 'simplecov', '~> 0.17.1'
41
41
  spec.add_development_dependency 'solargraph', '~> 0.39.7'
42
42
  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.14.0
4
+ version: 1.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Falkowski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-18 00:00:00.000000000 Z
11
+ date: 2020-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber
@@ -212,14 +212,14 @@ dependencies:
212
212
  requirements:
213
213
  - - "~>"
214
214
  - !ruby/object:Gem::Version
215
- version: 0.83.0
215
+ version: 0.86.0
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
- version: 0.83.0
222
+ version: 0.86.0
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: simplecov
225
225
  requirement: !ruby/object:Gem::Requirement
@@ -270,20 +270,24 @@ files:
270
270
  - bin/console
271
271
  - bin/setup
272
272
  - lib/nonnative.rb
273
- - lib/nonnative/application.rb
274
273
  - lib/nonnative/before.rb
274
+ - lib/nonnative/chaos_proxy.rb
275
275
  - lib/nonnative/command.rb
276
276
  - lib/nonnative/configuration.rb
277
277
  - lib/nonnative/configuration_process.rb
278
+ - lib/nonnative/configuration_proxy.rb
278
279
  - lib/nonnative/configuration_server.rb
279
280
  - lib/nonnative/error.rb
280
281
  - lib/nonnative/grpc_server.rb
281
282
  - lib/nonnative/http_client.rb
282
283
  - lib/nonnative/http_server.rb
283
284
  - lib/nonnative/manual.rb
285
+ - lib/nonnative/no_proxy.rb
284
286
  - lib/nonnative/observability.rb
285
287
  - lib/nonnative/pool.rb
286
288
  - lib/nonnative/port.rb
289
+ - lib/nonnative/proxy.rb
290
+ - lib/nonnative/proxy_factory.rb
287
291
  - lib/nonnative/server.rb
288
292
  - lib/nonnative/service.rb
289
293
  - lib/nonnative/start_error.rb
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nonnative
4
- class Application < Sinatra::Application
5
- set :bind, '0.0.0.0'
6
- set :server, :puma
7
- set :logging, false
8
- set :quiet, true
9
- end
10
- end