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 +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +1 -1
- data/README.md +114 -13
- data/lib/nonnative.rb +5 -3
- data/lib/nonnative/close_all_socket_pair.rb +0 -1
- data/lib/nonnative/configuration.rb +23 -1
- data/lib/nonnative/configuration_process.rb +1 -1
- data/lib/nonnative/configuration_runner.rb +19 -0
- data/lib/nonnative/configuration_server.rb +1 -1
- data/lib/nonnative/configuration_service.rb +1 -14
- data/lib/nonnative/fault_injection_proxy.rb +2 -2
- data/lib/nonnative/pool.rb +15 -4
- data/lib/nonnative/process.rb +1 -1
- data/lib/nonnative/runner.rb +29 -0
- data/lib/nonnative/server.rb +1 -3
- data/lib/nonnative/service.rb +5 -21
- data/lib/nonnative/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16a378ffdce68b4ac61ec07aed090eab3b907b9138ea4bcce3a1d435bc386723
|
4
|
+
data.tar.gz: 8a3f84148bf7d47786f0bd0793c16524ab49b6ec779ca6ce23d3d4b2c16d2053
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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
|
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
|
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:
|
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 = :
|
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:
|
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 = :
|
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:
|
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 = :
|
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:
|
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 = :
|
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:
|
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 = :
|
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:
|
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/
|
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/
|
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'
|
@@ -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
|
@@ -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,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
|
data/lib/nonnative/pool.rb
CHANGED
@@ -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 |
|
33
|
-
[Nonnative::Process.new(
|
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 |
|
39
|
-
[
|
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 = []
|
data/lib/nonnative/process.rb
CHANGED
@@ -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
|
data/lib/nonnative/server.rb
CHANGED
data/lib/nonnative/service.rb
CHANGED
@@ -1,29 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Nonnative
|
4
|
-
class Service
|
5
|
-
|
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
|
26
|
-
|
9
|
+
def stop
|
10
|
+
proxy.stop
|
27
11
|
end
|
28
12
|
end
|
29
13
|
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.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
|