nonnative 1.41.0 → 1.42.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: 50953dcfe695bf9196b5d3968a88f15fa6db81c630c0537e8c796ad63486d15f
4
- data.tar.gz: f910aec0fdb41fd9cea678657be191be85756d2c99ae45d64750a6f31c2534f7
3
+ metadata.gz: 16a378ffdce68b4ac61ec07aed090eab3b907b9138ea4bcce3a1d435bc386723
4
+ data.tar.gz: 8a3f84148bf7d47786f0bd0793c16524ab49b6ec779ca6ce23d3d4b2c16d2053
5
5
  SHA512:
6
- metadata.gz: 621d4af2d17163e749f0a706b991a52583f32603f64ba3a0fd978c31961c1de11c4b713a0023e0baf7309a9abf072f8642a4551d5a87d1c33bb4caa8844116b6
7
- data.tar.gz: 7f1516ab344e4ce99388046490809cb6a63e4de40909aab41c018b73d18e70d3d3b6c76069b9a747a15eed801d9bc94d83e097012bd82cdbcc49ff7a140443eb
6
+ metadata.gz: 31c1a5e132f2686355a595b76f5da900256b3948fe70e6b64b07d76e93603ac24f808914b2d0bec97bdabe57a8cfca4888a1293e50cf0ca04e7fb1e9b6e7d6c1
7
+ data.tar.gz: b7fb0522f26ff25b988ba464c4993647e22b595a8a6f857216fcf9cc4f821360720361e486b3e578962f15b5ec63334a43495da405355d57efe21e254c5b7897
data/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.42.1](https://github.com/alexfalkowski/nonnative/compare/v1.42.0...v1.42.1) (2021-04-30)
6
+
7
+ ## [1.42.0](https://github.com/alexfalkowski/nonnative/compare/v1.41.0...v1.42.0) (2021-04-30)
8
+
9
+
10
+ ### Features
11
+
12
+ * add services ([#80](https://github.com/alexfalkowski/nonnative/issues/80)) ([454980e](https://github.com/alexfalkowski/nonnative/commit/454980e1eb141995c96203fcf9254bfe2cb0133e))
13
+
5
14
  ## [1.41.0](https://github.com/alexfalkowski/nonnative/compare/v1.40.2...v1.41.0) (2021-04-30)
6
15
 
7
16
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nonnative (1.41.0)
4
+ nonnative (1.42.0)
5
5
  concurrent-ruby (~> 1.0, >= 1.0.5)
6
6
  cucumber (>= 6, < 7)
7
7
  grpc (>= 1, < 2)
data/README.md CHANGED
@@ -33,12 +33,12 @@ Or install it yourself as:
33
33
 
34
34
  Configure nonnative with the following:
35
35
 
36
- - Process/Server that you want to start.
36
+ - Process, Server or Service that you want to start.
37
37
  - A timeout value.
38
38
  - Port to verify.
39
39
  - The class for servers.
40
40
  - The log for servers/processes
41
- - The strategy for processes/servers.
41
+ - The strategy for processes, servers and services.
42
42
 
43
43
  ### Strategy
44
44
 
@@ -53,6 +53,8 @@ This can be overridden by the following environment variables:
53
53
 
54
54
  ### Processes
55
55
 
56
+ A process is some sort of command that you would run locally.
57
+
56
58
  Setup it up programmatically:
57
59
 
58
60
  ```ruby
@@ -84,7 +86,7 @@ Setup it up through configuration:
84
86
 
85
87
  ```yaml
86
88
  version: 1.0
87
- strategy: manual
89
+ strategy: startup
88
90
  processes:
89
91
  -
90
92
  name: start_1
@@ -111,6 +113,8 @@ Nonnative.load_configuration('configuration.yml')
111
113
 
112
114
  ### Servers
113
115
 
116
+ A server is a dependency to some external API.
117
+
114
118
  Define your server:
115
119
 
116
120
  ```ruby
@@ -140,7 +144,7 @@ Setup it up programmatically:
140
144
  require 'nonnative'
141
145
 
142
146
  Nonnative.configure do |config|
143
- config.strategy = :manual
147
+ config.strategy = :startup
144
148
 
145
149
  config.server do |s|
146
150
  s.name = 'server_1'
@@ -164,7 +168,7 @@ Setup it up through configuration:
164
168
 
165
169
  ```yaml
166
170
  version: 1.0
167
- strategy: manual
171
+ strategy: startup
168
172
  servers:
169
173
  -
170
174
  name: server_1
@@ -220,7 +224,7 @@ Setup it up programmatically:
220
224
  require 'nonnative'
221
225
 
222
226
  Nonnative.configure do |config|
223
- config.strategy = :manual
227
+ config.strategy = :startup
224
228
 
225
229
  config.server do |s|
226
230
  s.name = 'http_server_1'
@@ -236,7 +240,7 @@ Setup it up through configuration:
236
240
 
237
241
  ```yaml
238
242
  version: 1.0
239
- strategy: manual
243
+ strategy: startup
240
244
  servers:
241
245
  -
242
246
  name: http_server_1
@@ -282,7 +286,7 @@ Setup it up programmatically:
282
286
  require 'nonnative'
283
287
 
284
288
  Nonnative.configure do |config|
285
- config.strategy = :manual
289
+ config.strategy = :startup
286
290
 
287
291
  config.server do |s|
288
292
  s.name = 'grpc_server_1'
@@ -298,7 +302,7 @@ Setup it up through configuration:
298
302
 
299
303
  ```yaml
300
304
  version: 1.0
301
- strategy: manual
305
+ strategy: startup
302
306
  servers:
303
307
  -
304
308
  name: grpc_server_1
@@ -315,6 +319,53 @@ require 'nonnative'
315
319
 
316
320
  Nonnative.load_configuration('configuration.yml')
317
321
  ```
322
+
323
+ ### Services
324
+
325
+ A service is an external dependency to your system. This is usually an expensive process to start like a DB and you would prefer to be managed externally. Services are not really exciting by themselves, it's when we add proxies that they allow us to do some extra work.
326
+
327
+ Setup it up programmatically:
328
+
329
+ ```ruby
330
+ require 'nonnative'
331
+
332
+ Nonnative.configure do |config|
333
+ config.strategy = :startup
334
+
335
+ config.service do |s|
336
+ s.name = 'postgres'
337
+ p.port = 5432
338
+ end
339
+
340
+ config.service do |s|
341
+ s.name = 'redis'
342
+ s.port = 6379
343
+ end
344
+ end
345
+ ```
346
+
347
+ Setup it up through configuration:
348
+
349
+ ```yaml
350
+ version: 1.0
351
+ strategy: startup
352
+ processes:
353
+ -
354
+ name: postgres
355
+ port: 5432
356
+ -
357
+ name: redis
358
+ port: 6379
359
+ ```
360
+
361
+ Then load the file with
362
+
363
+ ```ruby
364
+ require 'nonnative'
365
+
366
+ Nonnative.load_configuration('configuration.yml')
367
+ ```
368
+
318
369
  #### Proxies
319
370
 
320
371
  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:
@@ -329,7 +380,7 @@ Setup it up programmatically:
329
380
  require 'nonnative'
330
381
 
331
382
  Nonnative.configure do |config|
332
- config.strategy = :manual
383
+ config.strategy = :startup
333
384
 
334
385
  config.process do |p|
335
386
  p.proxy = {
@@ -348,7 +399,7 @@ Setup it up through configuration:
348
399
 
349
400
  ```yaml
350
401
  version: 1.0
351
- strategy: manual
402
+ strategy: startup
352
403
  processes:
353
404
  -
354
405
  proxy:
@@ -367,7 +418,7 @@ Setup it up programmatically:
367
418
  require 'nonnative'
368
419
 
369
420
  Nonnative.configure do |config|
370
- config.strategy = :manual
421
+ config.strategy = :startup
371
422
 
372
423
  config.server do |s|
373
424
  s.proxy = {
@@ -386,7 +437,7 @@ Setup it up through configuration:
386
437
 
387
438
  ```yaml
388
439
  version: 1.0
389
- strategy: manual
440
+ strategy: startup
390
441
  servers:
391
442
  -
392
443
  proxy:
@@ -397,6 +448,44 @@ servers:
397
448
  delay: 5
398
449
  ```
399
450
 
451
+ ##### Services
452
+
453
+ Setup it up programmatically:
454
+
455
+ ```ruby
456
+ require 'nonnative'
457
+
458
+ Nonnative.configure do |config|
459
+ config.strategy = :startup
460
+
461
+ config.service do |s|
462
+ s.proxy = {
463
+ type: 'fault_injection',
464
+ port: 20_000,
465
+ log: 'features/logs/proxy_server.log',
466
+ options: {
467
+ delay: 5
468
+ }
469
+ }
470
+ end
471
+ end
472
+ ```
473
+
474
+ Setup it up through configuration:
475
+
476
+ ```yaml
477
+ version: 1.0
478
+ strategy: startup
479
+ services:
480
+ -
481
+ proxy:
482
+ type: fault_injection
483
+ port: 20000
484
+ log: features/logs/proxy_server.log
485
+ options:
486
+ delay: 5
487
+ ```
488
+
400
489
  ##### Fault Injection
401
490
 
402
491
  The `fault_injection` proxy allows you to simulate failures by injecting them. We currently support the following:
@@ -428,6 +517,18 @@ server.proxy.close_all # To use close_all.
428
517
  server.proxy.reset # To reset it back to a good state.
429
518
  ```
430
519
 
520
+ ###### Services
521
+
522
+ Setup it up programmatically:
523
+
524
+ ```ruby
525
+ name = 'name of service in configuration'
526
+ service = Nonnative.pool.service_by_name(name)
527
+
528
+ service.proxy.close_all # To use close_all.
529
+ service.proxy.reset # To reset it back to a good state.
530
+ ```
531
+
431
532
  ### Go
432
533
 
433
534
  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`
data/lib/nonnative.rb CHANGED
@@ -19,14 +19,16 @@ require 'nonnative/stop_error'
19
19
  require 'nonnative/timeout'
20
20
  require 'nonnative/port'
21
21
  require 'nonnative/configuration'
22
- require 'nonnative/configuration_service'
22
+ require 'nonnative/configuration_runner'
23
23
  require 'nonnative/configuration_process'
24
24
  require 'nonnative/configuration_server'
25
+ require 'nonnative/configuration_service'
25
26
  require 'nonnative/configuration_proxy'
26
- require 'nonnative/service'
27
+ require 'nonnative/runner'
27
28
  require 'nonnative/process'
28
- require 'nonnative/pool'
29
29
  require 'nonnative/server'
30
+ require 'nonnative/service'
31
+ require 'nonnative/pool'
30
32
  require 'nonnative/http_client'
31
33
  require 'nonnative/http_server'
32
34
  require 'nonnative/grpc_server'
@@ -3,7 +3,6 @@
3
3
  module Nonnative
4
4
  class CloseAllSocketPair < SocketPair
5
5
  def connect(local_socket)
6
- ensure
7
6
  local_socket.close
8
7
  end
9
8
  end
@@ -47,6 +47,20 @@ module Nonnative
47
47
  end
48
48
  end
49
49
 
50
+ def services(file, config)
51
+ services = file['services'] || []
52
+ services.each do |fd|
53
+ config.service do |s|
54
+ s.name = fd['name']
55
+ s.timeout = fd['timeout']
56
+ s.port = fd['port']
57
+ s.log = fd['log']
58
+
59
+ proxy s, fd['proxy']
60
+ end
61
+ end
62
+ end
63
+
50
64
  def proxy(server, proxy)
51
65
  return unless proxy
52
66
 
@@ -63,9 +77,10 @@ module Nonnative
63
77
  @strategy = Strategy.new
64
78
  @processes = []
65
79
  @servers = []
80
+ @services = []
66
81
  end
67
82
 
68
- attr_accessor :processes, :servers
83
+ attr_accessor :processes, :servers, :services
69
84
  attr_reader :strategy
70
85
 
71
86
  def strategy=(value)
@@ -85,5 +100,12 @@ module Nonnative
85
100
 
86
101
  servers << server
87
102
  end
103
+
104
+ def service
105
+ service = Nonnative::ConfigurationService.new
106
+ yield service
107
+
108
+ services << service
109
+ end
88
110
  end
89
111
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class ConfigurationProcess < ConfigurationService
4
+ class ConfigurationProcess < ConfigurationRunner
5
5
  attr_accessor :command, :signal
6
6
  end
7
7
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nonnative
4
+ class ConfigurationRunner
5
+ attr_accessor :name, :timeout, :port, :log
6
+ attr_reader :proxy
7
+
8
+ def initialize
9
+ @proxy = Nonnative::ConfigurationProxy.new
10
+ end
11
+
12
+ def proxy=(value)
13
+ proxy.type = value[:type]
14
+ proxy.port = value[:port]
15
+ proxy.log = value[:log]
16
+ proxy.options = value[:options]
17
+ end
18
+ end
19
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class ConfigurationServer < ConfigurationService
4
+ class ConfigurationServer < ConfigurationRunner
5
5
  attr_accessor :klass
6
6
  end
7
7
  end
@@ -1,19 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class ConfigurationService
5
- attr_accessor :name, :timeout, :port, :log
6
- attr_reader :proxy
7
-
8
- def initialize
9
- @proxy = Nonnative::ConfigurationProxy.new
10
- end
11
-
12
- def proxy=(value)
13
- proxy.type = value[:type]
14
- proxy.port = value[:port]
15
- proxy.log = value[:log]
16
- proxy.options = value[:options]
17
- end
4
+ class ConfigurationService < ConfigurationRunner
18
5
  end
19
6
  end
@@ -17,8 +17,8 @@ module Nonnative
17
17
  end
18
18
 
19
19
  def stop
20
- thread.terminate
21
- tcp_server.close
20
+ thread&.terminate
21
+ tcp_server&.close
22
22
  end
23
23
 
24
24
  def close_all
@@ -7,11 +7,13 @@ module Nonnative
7
7
  end
8
8
 
9
9
  def start(&block)
10
+ services.each(&:start)
10
11
  [servers, processes].each { |t| process(t, :start, :open?, &block) }
11
12
  end
12
13
 
13
14
  def stop(&block)
14
15
  [processes, servers].each { |t| process(t, :stop, :closed?, &block) }
16
+ services.each(&:stop)
15
17
  end
16
18
 
17
19
  def process_by_name(name)
@@ -24,22 +26,31 @@ module Nonnative
24
26
  servers[index].first
25
27
  end
26
28
 
29
+ def service_by_name(name)
30
+ index = configuration.services.find_index { |s| s.name == name }
31
+ services[index]
32
+ end
33
+
27
34
  private
28
35
 
29
36
  attr_reader :configuration
30
37
 
31
38
  def processes
32
- @processes ||= configuration.processes.map do |d|
33
- [Nonnative::Process.new(d), Nonnative::Port.new(d)]
39
+ @processes ||= configuration.processes.map do |p|
40
+ [Nonnative::Process.new(p), Nonnative::Port.new(p)]
34
41
  end
35
42
  end
36
43
 
37
44
  def servers
38
- @servers ||= configuration.servers.map do |d|
39
- [d.klass.new(d), Nonnative::Port.new(d)]
45
+ @servers ||= configuration.servers.map do |s|
46
+ [s.klass.new(s), Nonnative::Port.new(s)]
40
47
  end
41
48
  end
42
49
 
50
+ def services
51
+ @services ||= configuration.services.map { |s| Nonnative::Service.new(s) }
52
+ end
53
+
43
54
  def process(all, type_method, port_method, &block)
44
55
  types = []
45
56
  pids = []
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class Process < Nonnative::Service
4
+ class Process < Runner
5
5
  def start
6
6
  unless process_exists?
7
7
  proxy.start
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nonnative
4
+ class Runner
5
+ attr_reader :proxy
6
+
7
+ def initialize(service)
8
+ @service = service
9
+ @timeout = Nonnative::Timeout.new(service.timeout)
10
+ @proxy = Nonnative::ProxyFactory.create(service)
11
+ end
12
+
13
+ def name
14
+ service.name
15
+ end
16
+
17
+ protected
18
+
19
+ attr_reader :service, :timeout
20
+
21
+ def wait_start
22
+ sleep 0.1
23
+ end
24
+
25
+ def wait_stop
26
+ sleep 0.1
27
+ end
28
+ end
29
+ end
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class Server < Nonnative::Service
5
- attr_reader :proxy
6
-
4
+ class Server < Runner
7
5
  def start
8
6
  unless thread
9
7
  proxy.start
@@ -1,29 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class Service
5
- attr_reader :proxy
6
-
7
- def initialize(service)
8
- @service = service
9
- @timeout = Nonnative::Timeout.new(service.timeout)
10
- @proxy = Nonnative::ProxyFactory.create(service)
11
- end
12
-
13
- def name
14
- service.name
15
- end
16
-
17
- protected
18
-
19
- attr_reader :service, :timeout
20
-
21
- def wait_start
22
- sleep 0.1
4
+ class Service < Runner
5
+ def start
6
+ proxy.start
23
7
  end
24
8
 
25
- def wait_stop
26
- sleep 0.1
9
+ def stop
10
+ proxy.stop
27
11
  end
28
12
  end
29
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- VERSION = '1.41.0'
4
+ VERSION = '1.42.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.41.0
4
+ version: 1.42.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Falkowski
@@ -262,6 +262,7 @@ files:
262
262
  - lib/nonnative/configuration.rb
263
263
  - lib/nonnative/configuration_process.rb
264
264
  - lib/nonnative/configuration_proxy.rb
265
+ - lib/nonnative/configuration_runner.rb
265
266
  - lib/nonnative/configuration_server.rb
266
267
  - lib/nonnative/configuration_service.rb
267
268
  - lib/nonnative/delay_socket_pair.rb
@@ -280,6 +281,7 @@ files:
280
281
  - lib/nonnative/process.rb
281
282
  - lib/nonnative/proxy.rb
282
283
  - lib/nonnative/proxy_factory.rb
284
+ - lib/nonnative/runner.rb
283
285
  - lib/nonnative/server.rb
284
286
  - lib/nonnative/service.rb
285
287
  - lib/nonnative/socket_pair.rb