nonnative 1.38.0 → 1.43.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: 66174bae17db6e0fae12b8d0be37b1373c887687901a072e32914cb00bea1f08
4
- data.tar.gz: a7430fe7c5d8bfd4a5a43fcf733fe80ef8fb1c8a25e78a2e22c5847518c547e7
3
+ metadata.gz: 62f3c862b3f62e6cbb6ada5723b5d533db060ef8c801a60b1fccbbc50d3dd99c
4
+ data.tar.gz: 22d05748db137d668e7366bed697abdffe6fddb97a0a5c445a6dc32568013c14
5
5
  SHA512:
6
- metadata.gz: 3b57cbc993f69dd8b051dcd51ccf2953dff7bede798fae49c75439e9d47b8dac8474f391d3050ec71af706bf75febfb681c65ddb247cbf7c87bc7d3d3f3e153f
7
- data.tar.gz: 30f89fcd78a1a5eedb130f4707bb60246db7ad98df733cf13e6f39146a25c955d2664fb407e65ed318de28ab61b7f222a9e380abd50349c446ab1a7c39952953
6
+ metadata.gz: da5be400a905ea0f6eeb6d62609664046e246ed95ea0f32661f03d1fe242d1cdefe3d2d787c8f92c770cc991237a39aa132bdedcdc241f29db5119ed9feebc29
7
+ data.tar.gz: f37ddb08dc0f67363f0bb5bca5f2611999d9dd2ebe22e26d3b8bcbe0f7bbb6a0564c3010a3e5eeca98c404712cfb8364f945194c579235d5158b7a660908aab9
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ repo_token: x3EcMK4Nr770BeIFZengeQ2DLDCDjNfNo
data/CHANGELOG.md CHANGED
@@ -2,6 +2,54 @@
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.43.0](https://github.com/alexfalkowski/nonnative/compare/v1.42.2...v1.43.0) (2021-04-30)
6
+
7
+
8
+ ### Features
9
+
10
+ * release version 1.43.0 ([#83](https://github.com/alexfalkowski/nonnative/issues/83)) ([b51526d](https://github.com/alexfalkowski/nonnative/commit/b51526d99d24522a26f534d28769cc8cdee4af04))
11
+
12
+ ### [1.42.2](https://github.com/alexfalkowski/nonnative/compare/v1.42.1...v1.42.2) (2021-04-30)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * make sure we parse services config ([#82](https://github.com/alexfalkowski/nonnative/issues/82)) ([2a52af7](https://github.com/alexfalkowski/nonnative/commit/2a52af74b75443674a2235c424d69f15516ab60f))
18
+
19
+ ### [1.42.1](https://github.com/alexfalkowski/nonnative/compare/v1.42.0...v1.42.1) (2021-04-30)
20
+
21
+ ## [1.42.0](https://github.com/alexfalkowski/nonnative/compare/v1.41.0...v1.42.0) (2021-04-30)
22
+
23
+
24
+ ### Features
25
+
26
+ * add services ([#80](https://github.com/alexfalkowski/nonnative/issues/80)) ([454980e](https://github.com/alexfalkowski/nonnative/commit/454980e1eb141995c96203fcf9254bfe2cb0133e))
27
+
28
+ ## [1.41.0](https://github.com/alexfalkowski/nonnative/compare/v1.40.2...v1.41.0) (2021-04-30)
29
+
30
+
31
+ ### Features
32
+
33
+ * add proxy to processes ([#79](https://github.com/alexfalkowski/nonnative/issues/79)) ([d52b2bb](https://github.com/alexfalkowski/nonnative/commit/d52b2bb6fad91612f9b9a64817c861d1c227ef0b))
34
+
35
+ ### [1.40.2](https://github.com/alexfalkowski/nonnative/compare/v1.40.1...v1.40.2) (2021-04-27)
36
+
37
+ ### [1.40.1](https://github.com/alexfalkowski/nonnative/compare/v1.40.0...v1.40.1) (2021-04-27)
38
+
39
+ ## [1.40.0](https://github.com/alexfalkowski/nonnative/compare/v1.39.0...v1.40.0) (2021-04-25)
40
+
41
+
42
+ ### Features
43
+
44
+ * update deps ([#76](https://github.com/alexfalkowski/nonnative/issues/76)) ([83c9e16](https://github.com/alexfalkowski/nonnative/commit/83c9e16b5e5f9f14ed2cc5fd2eb29b83147c1e53))
45
+
46
+ ## [1.39.0](https://github.com/alexfalkowski/nonnative/compare/v1.38.0...v1.39.0) (2021-04-23)
47
+
48
+
49
+ ### Features
50
+
51
+ * log interruptions ([#75](https://github.com/alexfalkowski/nonnative/issues/75)) ([bde3e05](https://github.com/alexfalkowski/nonnative/commit/bde3e052b422a0ca659cfb54fcf3ca9d8a1fb20c))
52
+
5
53
  ## [1.38.0](https://github.com/alexfalkowski/nonnative/compare/v1.37.0...v1.38.0) (2021-04-22)
6
54
 
7
55
 
data/Gemfile.lock CHANGED
@@ -1,10 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nonnative (1.38.0)
4
+ nonnative (1.43.0)
5
5
  concurrent-ruby (~> 1.0, >= 1.0.5)
6
- cucumber (>= 5, < 6)
6
+ cucumber (>= 6, < 7)
7
7
  grpc (>= 1, < 2)
8
+ grpc-tools (>= 1, < 2)
8
9
  puma (~> 5.0)
9
10
  rest-client (~> 2.1)
10
11
  rspec-benchmark (~> 0.6.0)
@@ -28,37 +29,44 @@ GEM
28
29
  benchmark-trend (0.4.0)
29
30
  builder (3.2.4)
30
31
  concurrent-ruby (1.1.8)
31
- cucumber (5.3.0)
32
+ coveralls (0.8.23)
33
+ json (>= 1.8, < 3)
34
+ simplecov (~> 0.16.1)
35
+ term-ansicolor (~> 1.3)
36
+ thor (>= 0.19.4, < 2.0)
37
+ tins (~> 1.6)
38
+ cucumber (6.0.0)
32
39
  builder (~> 3.2, >= 3.2.4)
33
- cucumber-core (~> 8.0, >= 8.0.1)
34
- cucumber-create-meta (~> 2.0, >= 2.0.2)
35
- cucumber-cucumber-expressions (~> 10.3, >= 10.3.0)
36
- cucumber-gherkin (~> 15.0, >= 15.0.2)
37
- cucumber-html-formatter (~> 9.0, >= 9.0.0)
38
- cucumber-messages (~> 13.1, >= 13.1.0)
39
- cucumber-wire (~> 4.0, >= 4.0.1)
40
+ cucumber-core (~> 9.0, >= 9.0.0)
41
+ cucumber-create-meta (~> 4.0, >= 4.0.0)
42
+ cucumber-cucumber-expressions (~> 12.1, >= 12.1.1)
43
+ cucumber-gherkin (~> 18.1, >= 18.1.0)
44
+ cucumber-html-formatter (~> 13.0, >= 13.0.0)
45
+ cucumber-messages (~> 15.0, >= 15.0.0)
46
+ cucumber-wire (~> 5.0, >= 5.0.0)
40
47
  diff-lcs (~> 1.4, >= 1.4.4)
48
+ mime-types (~> 3.3, >= 3.3.1)
41
49
  multi_test (~> 0.1, >= 0.1.2)
42
- sys-uname (~> 1.2, >= 1.2.1)
43
- cucumber-core (8.0.1)
44
- cucumber-gherkin (~> 15.0, >= 15.0.2)
45
- cucumber-messages (~> 13.0, >= 13.0.1)
46
- cucumber-tag-expressions (~> 2.0, >= 2.0.4)
47
- cucumber-create-meta (2.0.4)
48
- cucumber-messages (~> 13.1, >= 13.1.0)
49
- sys-uname (~> 1.2, >= 1.2.1)
50
- cucumber-cucumber-expressions (10.3.0)
51
- cucumber-gherkin (15.0.2)
52
- cucumber-messages (~> 13.0, >= 13.0.1)
53
- cucumber-html-formatter (9.0.0)
54
- cucumber-messages (~> 13.0, >= 13.0.1)
55
- cucumber-messages (13.2.1)
50
+ sys-uname (~> 1.2, >= 1.2.2)
51
+ cucumber-core (9.0.0)
52
+ cucumber-gherkin (~> 18.1, >= 18.1.0)
53
+ cucumber-messages (~> 15.0, >= 15.0.0)
54
+ cucumber-tag-expressions (~> 3.0, >= 3.0.1)
55
+ cucumber-create-meta (4.0.0)
56
+ cucumber-messages (~> 15.0, >= 15.0.0)
57
+ sys-uname (~> 1.2, >= 1.2.2)
58
+ cucumber-cucumber-expressions (12.1.1)
59
+ cucumber-gherkin (18.1.1)
60
+ cucumber-messages (~> 15.0, >= 15.0.0)
61
+ cucumber-html-formatter (13.0.0)
62
+ cucumber-messages (~> 15.0, >= 15.0.0)
63
+ cucumber-messages (15.0.0)
56
64
  protobuf-cucumber (~> 3.10, >= 3.10.8)
57
- cucumber-tag-expressions (2.0.4)
58
- cucumber-wire (4.0.1)
59
- cucumber-core (~> 8.0, >= 8.0.1)
60
- cucumber-cucumber-expressions (~> 10.3, >= 10.3.0)
61
- cucumber-messages (~> 13.0, >= 13.0.1)
65
+ cucumber-tag-expressions (3.0.1)
66
+ cucumber-wire (5.0.0)
67
+ cucumber-core (~> 9.0, >= 9.0.0)
68
+ cucumber-cucumber-expressions (~> 12.1, >= 12.1.1)
69
+ cucumber-messages (~> 15.0, >= 15.0.0)
62
70
  diff-lcs (1.4.4)
63
71
  docile (1.3.5)
64
72
  domain_name (0.5.20190701)
@@ -68,16 +76,17 @@ GEM
68
76
  google-protobuf (3.15.8)
69
77
  googleapis-common-protos-types (1.0.6)
70
78
  google-protobuf (~> 3.14)
71
- grpc (1.37.0)
79
+ grpc (1.37.1)
72
80
  google-protobuf (~> 3.15)
73
81
  googleapis-common-protos-types (~> 1.0)
74
- grpc-tools (1.37.0)
82
+ grpc-tools (1.37.1)
75
83
  http-accept (1.7.0)
76
84
  http-cookie (1.0.3)
77
85
  domain_name (~> 0.5)
78
86
  i18n (1.8.10)
79
87
  concurrent-ruby (~> 1.0)
80
88
  jaro_winkler (1.5.4)
89
+ json (2.5.1)
81
90
  kramdown (2.3.1)
82
91
  rexml
83
92
  kramdown-parser-gfm (1.1.0)
@@ -151,12 +160,11 @@ GEM
151
160
  parser (>= 2.7.1.5)
152
161
  ruby-progressbar (1.11.0)
153
162
  ruby2_keywords (0.0.4)
154
- simplecov (0.21.2)
163
+ simplecov (0.16.1)
155
164
  docile (~> 1.1)
156
- simplecov-html (~> 0.11)
157
- simplecov_json_formatter (~> 0.1)
158
- simplecov-html (0.12.3)
159
- simplecov_json_formatter (0.1.2)
165
+ json (>= 1.8, < 3)
166
+ simplecov-html (~> 0.10.0)
167
+ simplecov-html (0.10.2)
160
168
  sinatra (2.1.0)
161
169
  mustermann (~> 1.0)
162
170
  rack (~> 2.2)
@@ -176,11 +184,16 @@ GEM
176
184
  thor (~> 1.0)
177
185
  tilt (~> 2.0)
178
186
  yard (~> 0.9, >= 0.9.24)
187
+ sync (0.5.0)
179
188
  sys-uname (1.2.2)
180
189
  ffi (~> 1.1)
190
+ term-ansicolor (1.7.1)
191
+ tins (~> 1.0)
181
192
  thor (1.0.1)
182
193
  thread_safe (0.3.6)
183
194
  tilt (2.0.10)
195
+ tins (1.28.0)
196
+ sync
184
197
  tzinfo (2.0.4)
185
198
  concurrent-ruby (~> 1.0)
186
199
  unf (0.1.4)
@@ -195,10 +208,9 @@ PLATFORMS
195
208
 
196
209
  DEPENDENCIES
197
210
  bundler (~> 2.1, >= 2.1.4)
198
- grpc-tools (>= 1, < 2)
211
+ coveralls (~> 0.8.23)
199
212
  nonnative!
200
213
  rubocop (~> 1.12)
201
- simplecov (~> 0.21.2)
202
214
  solargraph (~> 0.40.4)
203
215
 
204
216
  BUNDLED WITH
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![CircleCI](https://circleci.com/gh/alexfalkowski/nonnative.svg?style=svg)](https://circleci.com/gh/alexfalkowski/nonnative)
2
+ [![Coverage Status](https://coveralls.io/repos/github/alexfalkowski/nonnative/badge.svg?branch=master)](https://coveralls.io/github/alexfalkowski/nonnative?branch=master)
2
3
 
3
4
  # Nonnative
4
5
 
@@ -32,12 +33,12 @@ Or install it yourself as:
32
33
 
33
34
  Configure nonnative with the following:
34
35
 
35
- - Process/Server that you want to start.
36
+ - Process, Server or Service that you want to start.
36
37
  - A timeout value.
37
38
  - Port to verify.
38
39
  - The class for servers.
39
40
  - The log for servers/processes
40
- - The strategy for processes/servers.
41
+ - The strategy for processes, servers and services.
41
42
 
42
43
  ### Strategy
43
44
 
@@ -52,6 +53,8 @@ This can be overridden by the following environment variables:
52
53
 
53
54
  ### Processes
54
55
 
56
+ A process is some sort of command that you would run locally.
57
+
55
58
  Setup it up programmatically:
56
59
 
57
60
  ```ruby
@@ -60,21 +63,21 @@ require 'nonnative'
60
63
  Nonnative.configure do |config|
61
64
  config.strategy = :startup
62
65
 
63
- config.process do |d|
64
- d.name = 'start_1'
65
- d.command = 'features/support/bin/start 12_321'
66
- d.timeout = config.strategy.timeout
67
- d.port = 12_321
68
- d.log = 'features/logs/12_321.log'
69
- d.signal = 'INT' # Possible values are described in Signal.list.keys
66
+ config.process do |p|
67
+ p.name = 'start_1'
68
+ p.command = 'features/support/bin/start 12_321'
69
+ p.timeout = config.strategy.timeout
70
+ p.port = 12_321
71
+ p.log = 'features/logs/12_321.log'
72
+ p.signal = 'INT' # Possible values are described in Signal.list.keys
70
73
  end
71
74
 
72
- config.process do |d|
73
- d.name = 'start_2'
74
- d.command = 'features/support/bin/start 12_322'
75
- d.timeout = 0.5
76
- d.port = 12_322
77
- d.log = 'features/logs/12_322.log'
75
+ config.process do |p|
76
+ p.name = 'start_2'
77
+ p.command = 'features/support/bin/start 12_322'
78
+ p.timeout = 0.5
79
+ p.port = 12_322
80
+ p.log = 'features/logs/12_322.log'
78
81
  end
79
82
  end
80
83
  ```
@@ -83,7 +86,7 @@ Setup it up through configuration:
83
86
 
84
87
  ```yaml
85
88
  version: 1.0
86
- strategy: manual
89
+ strategy: startup
87
90
  processes:
88
91
  -
89
92
  name: start_1
@@ -110,6 +113,8 @@ Nonnative.load_configuration('configuration.yml')
110
113
 
111
114
  ### Servers
112
115
 
116
+ A server is a dependency to some external API.
117
+
113
118
  Define your server:
114
119
 
115
120
  ```ruby
@@ -139,7 +144,7 @@ Setup it up programmatically:
139
144
  require 'nonnative'
140
145
 
141
146
  Nonnative.configure do |config|
142
- config.strategy = :manual
147
+ config.strategy = :startup
143
148
 
144
149
  config.server do |s|
145
150
  s.name = 'server_1'
@@ -163,7 +168,7 @@ Setup it up through configuration:
163
168
 
164
169
  ```yaml
165
170
  version: 1.0
166
- strategy: manual
171
+ strategy: startup
167
172
  servers:
168
173
  -
169
174
  name: server_1
@@ -219,7 +224,7 @@ Setup it up programmatically:
219
224
  require 'nonnative'
220
225
 
221
226
  Nonnative.configure do |config|
222
- config.strategy = :manual
227
+ config.strategy = :startup
223
228
 
224
229
  config.server do |s|
225
230
  s.name = 'http_server_1'
@@ -235,7 +240,7 @@ Setup it up through configuration:
235
240
 
236
241
  ```yaml
237
242
  version: 1.0
238
- strategy: manual
243
+ strategy: startup
239
244
  servers:
240
245
  -
241
246
  name: http_server_1
@@ -281,7 +286,7 @@ Setup it up programmatically:
281
286
  require 'nonnative'
282
287
 
283
288
  Nonnative.configure do |config|
284
- config.strategy = :manual
289
+ config.strategy = :startup
285
290
 
286
291
  config.server do |s|
287
292
  s.name = 'grpc_server_1'
@@ -297,7 +302,7 @@ Setup it up through configuration:
297
302
 
298
303
  ```yaml
299
304
  version: 1.0
300
- strategy: manual
305
+ strategy: startup
301
306
  servers:
302
307
  -
303
308
  name: grpc_server_1
@@ -314,22 +319,109 @@ require 'nonnative'
314
319
 
315
320
  Nonnative.load_configuration('configuration.yml')
316
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
+
317
369
  #### Proxies
318
370
 
319
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:
320
372
  - `none` (this is the default)
321
373
  - `fault_injection`
322
374
 
375
+ ##### Processes
376
+
377
+ Setup it up programmatically:
378
+
379
+ ```ruby
380
+ require 'nonnative'
381
+
382
+ Nonnative.configure do |config|
383
+ config.strategy = :startup
384
+
385
+ config.process do |p|
386
+ p.proxy = {
387
+ type: 'fault_injection',
388
+ port: 20_000,
389
+ log: 'features/logs/proxy_server.log',
390
+ options: {
391
+ delay: 5
392
+ }
393
+ }
394
+ end
395
+ end
396
+ ```
397
+
398
+ Setup it up through configuration:
399
+
400
+ ```yaml
401
+ version: 1.0
402
+ strategy: startup
403
+ processes:
404
+ -
405
+ proxy:
406
+ type: fault_injection
407
+ port: 20000
408
+ log: features/logs/proxy_server.log
409
+ options:
410
+ delay: 5
411
+ ```
412
+
413
+ ##### Servers
414
+
323
415
  Setup it up programmatically:
324
416
 
325
417
  ```ruby
326
418
  require 'nonnative'
327
419
 
328
420
  Nonnative.configure do |config|
329
- config.strategy = :manual
421
+ config.strategy = :startup
330
422
 
331
- config.server do |d|
332
- d.proxy = {
423
+ config.server do |s|
424
+ s.proxy = {
333
425
  type: 'fault_injection',
334
426
  port: 20_000,
335
427
  log: 'features/logs/proxy_server.log',
@@ -345,7 +437,7 @@ Setup it up through configuration:
345
437
 
346
438
  ```yaml
347
439
  version: 1.0
348
- strategy: manual
440
+ strategy: startup
349
441
  servers:
350
442
  -
351
443
  proxy:
@@ -356,6 +448,44 @@ servers:
356
448
  delay: 5
357
449
  ```
358
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
+
359
489
  ##### Fault Injection
360
490
 
361
491
  The `fault_injection` proxy allows you to simulate failures by injecting them. We currently support the following:
@@ -363,6 +493,20 @@ The `fault_injection` proxy allows you to simulate failures by injecting them. W
363
493
  - `delay` - This delays the communication between the connection. Default is 2 secs can be configured through options.
364
494
  - `invalid_data` - This takes the input and rearranges it to produce invalid data.
365
495
 
496
+ ###### Processes
497
+
498
+ Setup it up programmatically:
499
+
500
+ ```ruby
501
+ name = 'name of process in configuration'
502
+ server = Nonnative.pool.process_by_name(name)
503
+
504
+ server.proxy.close_all # To use close_all.
505
+ server.proxy.reset # To reset it back to a good state.
506
+ ```
507
+
508
+ ###### Servers
509
+
366
510
  Setup it up programmatically:
367
511
 
368
512
  ```ruby
@@ -373,6 +517,18 @@ server.proxy.close_all # To use close_all.
373
517
  server.proxy.reset # To reset it back to a good state.
374
518
  ```
375
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
+
376
532
  ### Go
377
533
 
378
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`
@@ -380,24 +536,27 @@ As we love using go as a language for services we have added support to start bi
380
536
  To get this to work you will need to create a `main_test.go` file with these contents:
381
537
 
382
538
  ```go
539
+ // +build features
540
+
383
541
  package main
384
542
 
385
543
  import (
386
544
  "testing"
545
+
546
+ "github.com/your_location/cmd"
387
547
  )
388
548
 
389
- // TestFeatures is a hack that allows us to figure out what the coverage is during
390
- // integration tests. I would not recommend that you use a binary built using
391
- // this hack outside of a test suite.
392
549
  func TestFeatures(t *testing.T) {
393
- main()
550
+ if err := cmd.Execute(); err != nil {
551
+ t.Fatal(err.Error())
552
+ }
394
553
  }
395
554
  ```
396
555
 
397
556
  Then to compile this binary you will need to do the following:
398
557
 
399
558
  ```sh
400
- go test -mod vendor -c -covermode=count -o your_binary -coverpkg=./... github.com/your_location
559
+ go test -mod vendor -c -tags features -covermode=count -o your_binary -coverpkg=./... github.com/your_location
401
560
  ```
402
561
 
403
562
  Then to get an executable you do the following:
data/lib/nonnative.rb CHANGED
@@ -19,13 +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_runner'
22
23
  require 'nonnative/configuration_process'
23
24
  require 'nonnative/configuration_server'
25
+ require 'nonnative/configuration_service'
24
26
  require 'nonnative/configuration_proxy'
27
+ require 'nonnative/runner'
28
+ require 'nonnative/process'
29
+ require 'nonnative/server'
25
30
  require 'nonnative/service'
26
- require 'nonnative/command'
27
31
  require 'nonnative/pool'
28
- require 'nonnative/server'
29
32
  require 'nonnative/http_client'
30
33
  require 'nonnative/http_server'
31
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
@@ -11,6 +11,7 @@ module Nonnative
11
11
 
12
12
  processes(file, c)
13
13
  servers(file, c)
14
+ services(file, c)
14
15
  end
15
16
  end
16
17
 
@@ -26,6 +27,8 @@ module Nonnative
26
27
  d.port = fd['port']
27
28
  d.log = fd['log']
28
29
  d.signal = fd['signal']
30
+
31
+ proxy d, fd['proxy']
29
32
  end
30
33
  end
31
34
  end
@@ -45,6 +48,20 @@ module Nonnative
45
48
  end
46
49
  end
47
50
 
51
+ def services(file, config)
52
+ services = file['services'] || []
53
+ services.each do |fd|
54
+ config.service do |s|
55
+ s.name = fd['name']
56
+ s.timeout = fd['timeout']
57
+ s.port = fd['port']
58
+ s.log = fd['log']
59
+
60
+ proxy s, fd['proxy']
61
+ end
62
+ end
63
+ end
64
+
48
65
  def proxy(server, proxy)
49
66
  return unless proxy
50
67
 
@@ -61,9 +78,10 @@ module Nonnative
61
78
  @strategy = Strategy.new
62
79
  @processes = []
63
80
  @servers = []
81
+ @services = []
64
82
  end
65
83
 
66
- attr_accessor :processes, :servers
84
+ attr_accessor :processes, :servers, :services
67
85
  attr_reader :strategy
68
86
 
69
87
  def strategy=(value)
@@ -83,5 +101,12 @@ module Nonnative
83
101
 
84
102
  servers << server
85
103
  end
104
+
105
+ def service
106
+ service = Nonnative::ConfigurationService.new
107
+ yield service
108
+
109
+ services << service
110
+ end
86
111
  end
87
112
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class ConfigurationProcess
5
- attr_accessor :name, :command, :timeout, :port, :log, :signal
4
+ class ConfigurationProcess < ConfigurationRunner
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,19 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class ConfigurationServer
5
- attr_accessor :name, :klass, :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 ConfigurationServer < ConfigurationRunner
5
+ attr_accessor :klass
18
6
  end
19
7
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nonnative
4
+ class ConfigurationService < ConfigurationRunner
5
+ end
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
@@ -51,7 +51,6 @@ module Nonnative
51
51
  accept_connection local_socket
52
52
  end
53
53
 
54
- thread.report_on_exception = false
55
54
  connections[thread.object_id] = thread
56
55
  end
57
56
  end
@@ -60,16 +59,23 @@ module Nonnative
60
59
  id = Thread.current.object_id
61
60
  socket_info = local_socket.inspect
62
61
 
63
- connect local_socket
62
+ error = connect(local_socket)
63
+ if error
64
+ logger.error "could not handle the connection for '#{id}' with socket '#{socket_info}' and error '#{error}'"
65
+ else
66
+ logger.info "handled connection for '#{id}' with socket '#{socket_info}'"
67
+ end
68
+
64
69
  connections.delete(id)
65
- ensure
66
- logger.info "handled connection for #{id} with socket #{socket_info}"
67
70
  end
68
71
 
69
72
  def connect(local_socket)
70
73
  pair = SocketPairFactory.create(read_state, service.proxy)
71
-
72
74
  pair.connect(local_socket)
75
+ rescue StandardError => e
76
+ local_socket.close
77
+
78
+ e
73
79
  end
74
80
 
75
81
  def close_connections
@@ -7,11 +7,18 @@ 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)
17
+ end
18
+
19
+ def process_by_name(name)
20
+ index = configuration.processes.find_index { |s| s.name == name }
21
+ processes[index].first
15
22
  end
16
23
 
17
24
  def server_by_name(name)
@@ -19,22 +26,31 @@ module Nonnative
19
26
  servers[index].first
20
27
  end
21
28
 
29
+ def service_by_name(name)
30
+ index = configuration.services.find_index { |s| s.name == name }
31
+ services[index]
32
+ end
33
+
22
34
  private
23
35
 
24
36
  attr_reader :configuration
25
37
 
26
38
  def processes
27
- @processes ||= configuration.processes.map do |d|
28
- [Nonnative::Command.new(d), Nonnative::Port.new(d)]
39
+ @processes ||= configuration.processes.map do |p|
40
+ [Nonnative::Process.new(p), Nonnative::Port.new(p)]
29
41
  end
30
42
  end
31
43
 
32
44
  def servers
33
- @servers ||= configuration.servers.map do |d|
34
- [d.klass.new(d), Nonnative::Port.new(d)]
45
+ @servers ||= configuration.servers.map do |s|
46
+ [s.klass.new(s), Nonnative::Port.new(s)]
35
47
  end
36
48
  end
37
49
 
50
+ def services
51
+ @services ||= configuration.services.map { |s| Nonnative::Service.new(s) }
52
+ end
53
+
38
54
  def process(all, type_method, port_method, &block)
39
55
  types = []
40
56
  pids = []
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class Command < Nonnative::Service
4
+ class Process < Runner
5
5
  def start
6
- unless command_exists?
7
- @pid = command_spawn
6
+ unless process_exists?
7
+ proxy.start
8
+ @pid = process_spawn
8
9
  wait_start
9
10
  end
10
11
 
@@ -12,8 +13,9 @@ module Nonnative
12
13
  end
13
14
 
14
15
  def stop
15
- if command_exists?
16
- command_kill
16
+ if process_exists?
17
+ process_kill
18
+ proxy.stop
17
19
  wait_stop
18
20
  end
19
21
 
@@ -24,7 +26,7 @@ module Nonnative
24
26
 
25
27
  def wait_stop
26
28
  timeout.perform do
27
- Process.waitpid2(pid)
29
+ ::Process.waitpid2(pid)
28
30
  end
29
31
  end
30
32
 
@@ -32,20 +34,20 @@ module Nonnative
32
34
 
33
35
  attr_reader :pid
34
36
 
35
- def command_kill
37
+ def process_kill
36
38
  signal = Signal.list[service.signal || 'INT'] || Signal.list['INT']
37
- Process.kill(signal, pid)
39
+ ::Process.kill(signal, pid)
38
40
  end
39
41
 
40
- def command_spawn
42
+ def process_spawn
41
43
  spawn(service.command, %i[out err] => [service.log, 'a'])
42
44
  end
43
45
 
44
- def command_exists?
46
+ def process_exists?
45
47
  return false if pid.nil?
46
48
 
47
49
  signal = Signal.list['EXIT']
48
- Process.kill(signal, pid)
50
+ ::Process.kill(signal, pid)
49
51
  true
50
52
  rescue Errno::ESRCH
51
53
  false
@@ -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,15 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class Server < Nonnative::Service
5
- attr_reader :proxy
6
-
7
- def initialize(service)
8
- @proxy = Nonnative::ProxyFactory.create(service)
9
-
10
- super service
11
- end
12
-
4
+ class Server < Runner
13
5
  def start
14
6
  unless thread
15
7
  proxy.start
@@ -1,26 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class Service
5
- def initialize(service)
6
- @service = service
7
- @timeout = Nonnative::Timeout.new(service.timeout)
4
+ class Service < Runner
5
+ def start
6
+ proxy.start
8
7
  end
9
8
 
10
- def name
11
- service.name
12
- end
13
-
14
- protected
15
-
16
- attr_reader :service, :timeout
17
-
18
- def wait_start
19
- sleep 0.1
20
- end
21
-
22
- def wait_stop
23
- sleep 0.1
9
+ def stop
10
+ proxy.stop
24
11
  end
25
12
  end
26
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- VERSION = '1.38.0'
4
+ VERSION = '1.43.0'
5
5
  end
data/nonnative.gemspec CHANGED
@@ -24,8 +24,9 @@ Gem::Specification.new do |spec|
24
24
  spec.required_ruby_version = ['>= 2.7.0', '< 2.8.0']
25
25
 
26
26
  spec.add_dependency 'concurrent-ruby', '~> 1.0', '>= 1.0.5'
27
- spec.add_dependency 'cucumber', ['>= 5', '< 6']
27
+ spec.add_dependency 'cucumber', ['>= 6', '< 7']
28
28
  spec.add_dependency 'grpc', ['>= 1', '< 2']
29
+ spec.add_dependency 'grpc-tools', ['>= 1', '< 2']
29
30
  spec.add_dependency 'puma', '~> 5.0'
30
31
  spec.add_dependency 'rest-client', '~> 2.1'
31
32
  spec.add_dependency 'rspec-benchmark', '~> 0.6.0'
@@ -33,8 +34,7 @@ Gem::Specification.new do |spec|
33
34
  spec.add_dependency 'sinatra', '~> 2.0', '>= 2.0.8.1'
34
35
 
35
36
  spec.add_development_dependency 'bundler', '~> 2.1', '>= 2.1.4'
36
- spec.add_development_dependency 'grpc-tools', ['>= 1', '< 2']
37
+ spec.add_development_dependency 'coveralls', '~> 0.8.23'
37
38
  spec.add_development_dependency 'rubocop', '~> 1.12'
38
- spec.add_development_dependency 'simplecov', '~> 0.21.2'
39
39
  spec.add_development_dependency 'solargraph', '~> 0.40.4'
40
40
  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.38.0
4
+ version: 1.43.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: 2021-04-22 00:00:00.000000000 Z
11
+ date: 2021-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -36,20 +36,20 @@ dependencies:
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '5'
39
+ version: '6'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '6'
42
+ version: '7'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: '5'
49
+ version: '6'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '6'
52
+ version: '7'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: grpc
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -70,6 +70,26 @@ dependencies:
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
72
  version: '2'
73
+ - !ruby/object:Gem::Dependency
74
+ name: grpc-tools
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '1'
80
+ - - "<"
81
+ - !ruby/object:Gem::Version
82
+ version: '2'
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '1'
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: '2'
73
93
  - !ruby/object:Gem::Dependency
74
94
  name: puma
75
95
  requirement: !ruby/object:Gem::Requirement
@@ -173,25 +193,19 @@ dependencies:
173
193
  - !ruby/object:Gem::Version
174
194
  version: 2.1.4
175
195
  - !ruby/object:Gem::Dependency
176
- name: grpc-tools
196
+ name: coveralls
177
197
  requirement: !ruby/object:Gem::Requirement
178
198
  requirements:
179
- - - ">="
180
- - !ruby/object:Gem::Version
181
- version: '1'
182
- - - "<"
199
+ - - "~>"
183
200
  - !ruby/object:Gem::Version
184
- version: '2'
201
+ version: 0.8.23
185
202
  type: :development
186
203
  prerelease: false
187
204
  version_requirements: !ruby/object:Gem::Requirement
188
205
  requirements:
189
- - - ">="
190
- - !ruby/object:Gem::Version
191
- version: '1'
192
- - - "<"
206
+ - - "~>"
193
207
  - !ruby/object:Gem::Version
194
- version: '2'
208
+ version: 0.8.23
195
209
  - !ruby/object:Gem::Dependency
196
210
  name: rubocop
197
211
  requirement: !ruby/object:Gem::Requirement
@@ -206,20 +220,6 @@ dependencies:
206
220
  - - "~>"
207
221
  - !ruby/object:Gem::Version
208
222
  version: '1.12'
209
- - !ruby/object:Gem::Dependency
210
- name: simplecov
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - "~>"
214
- - !ruby/object:Gem::Version
215
- version: 0.21.2
216
- type: :development
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - "~>"
221
- - !ruby/object:Gem::Version
222
- version: 0.21.2
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: solargraph
225
225
  requirement: !ruby/object:Gem::Requirement
@@ -243,6 +243,7 @@ extra_rdoc_files: []
243
243
  files:
244
244
  - ".circleci/config.yml"
245
245
  - ".config/cucumber.yml"
246
+ - ".coveralls.yml"
246
247
  - ".editorconfig"
247
248
  - ".gitignore"
248
249
  - ".rubocop.yml"
@@ -258,11 +259,12 @@ files:
258
259
  - lib/nonnative.rb
259
260
  - lib/nonnative/before.rb
260
261
  - lib/nonnative/close_all_socket_pair.rb
261
- - lib/nonnative/command.rb
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
267
+ - lib/nonnative/configuration_service.rb
266
268
  - lib/nonnative/delay_socket_pair.rb
267
269
  - lib/nonnative/error.rb
268
270
  - lib/nonnative/fault_injection_proxy.rb
@@ -276,8 +278,10 @@ files:
276
278
  - lib/nonnative/observability.rb
277
279
  - lib/nonnative/pool.rb
278
280
  - lib/nonnative/port.rb
281
+ - lib/nonnative/process.rb
279
282
  - lib/nonnative/proxy.rb
280
283
  - lib/nonnative/proxy_factory.rb
284
+ - lib/nonnative/runner.rb
281
285
  - lib/nonnative/server.rb
282
286
  - lib/nonnative/service.rb
283
287
  - lib/nonnative/socket_pair.rb