nonnative 1.36.0 → 1.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d759dcc303c41272e596bf51efa2cd6602f2209105a66a419ee8543da8592a0c
4
- data.tar.gz: d300b24f8fbd84912d822e7235ee40dd9059f3a119fd3f7aa45d460c2b61300f
3
+ metadata.gz: 50953dcfe695bf9196b5d3968a88f15fa6db81c630c0537e8c796ad63486d15f
4
+ data.tar.gz: f910aec0fdb41fd9cea678657be191be85756d2c99ae45d64750a6f31c2534f7
5
5
  SHA512:
6
- metadata.gz: a5c26403802ae92c24c6ff36e9ab0f544772001ebb3e148891884fac300b0c3cb87a926ddda9da40169379ecfe522c69e186743ff334d3515cf6b4d66e2310ac
7
- data.tar.gz: 728a9b4b2c09aab1be02f003a868a5fe041c23d317768aff56f658dcd6bd84d09f9202241362725ae8a00b856f5a5fdae446fc218681be99d9dfb726b49e4078
6
+ metadata.gz: 621d4af2d17163e749f0a706b991a52583f32603f64ba3a0fd978c31961c1de11c4b713a0023e0baf7309a9abf072f8642a4551d5a87d1c33bb4caa8844116b6
7
+ data.tar.gz: 7f1516ab344e4ce99388046490809cb6a63e4de40909aab41c018b73d18e70d3d3b6c76069b9a747a15eed801d9bc94d83e097012bd82cdbcc49ff7a140443eb
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ repo_token: x3EcMK4Nr770BeIFZengeQ2DLDCDjNfNo
data/.rubocop.yml CHANGED
@@ -4,7 +4,7 @@ AllCops:
4
4
  NewCops: enable
5
5
 
6
6
  Layout/LineLength:
7
- Max: 120
7
+ Max: 160
8
8
 
9
9
  Metrics/MethodLength:
10
10
  Max: 20
data/CHANGELOG.md CHANGED
@@ -2,6 +2,52 @@
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.41.0](https://github.com/alexfalkowski/nonnative/compare/v1.40.2...v1.41.0) (2021-04-30)
6
+
7
+
8
+ ### Features
9
+
10
+ * add proxy to processes ([#79](https://github.com/alexfalkowski/nonnative/issues/79)) ([d52b2bb](https://github.com/alexfalkowski/nonnative/commit/d52b2bb6fad91612f9b9a64817c861d1c227ef0b))
11
+
12
+ ### [1.40.2](https://github.com/alexfalkowski/nonnative/compare/v1.40.1...v1.40.2) (2021-04-27)
13
+
14
+ ### [1.40.1](https://github.com/alexfalkowski/nonnative/compare/v1.40.0...v1.40.1) (2021-04-27)
15
+
16
+ ## [1.40.0](https://github.com/alexfalkowski/nonnative/compare/v1.39.0...v1.40.0) (2021-04-25)
17
+
18
+
19
+ ### Features
20
+
21
+ * update deps ([#76](https://github.com/alexfalkowski/nonnative/issues/76)) ([83c9e16](https://github.com/alexfalkowski/nonnative/commit/83c9e16b5e5f9f14ed2cc5fd2eb29b83147c1e53))
22
+
23
+ ## [1.39.0](https://github.com/alexfalkowski/nonnative/compare/v1.38.0...v1.39.0) (2021-04-23)
24
+
25
+
26
+ ### Features
27
+
28
+ * log interruptions ([#75](https://github.com/alexfalkowski/nonnative/issues/75)) ([bde3e05](https://github.com/alexfalkowski/nonnative/commit/bde3e052b422a0ca659cfb54fcf3ca9d8a1fb20c))
29
+
30
+ ## [1.38.0](https://github.com/alexfalkowski/nonnative/compare/v1.37.0...v1.38.0) (2021-04-22)
31
+
32
+
33
+ ### Features
34
+
35
+ * terminate connections on change ([#74](https://github.com/alexfalkowski/nonnative/issues/74)) ([6c1cc8e](https://github.com/alexfalkowski/nonnative/commit/6c1cc8e1c3f15d11848889852897b523f5848794))
36
+
37
+ ## [1.37.0](https://github.com/alexfalkowski/nonnative/compare/v1.36.0...v1.37.0) (2021-04-22)
38
+
39
+
40
+ ### Features
41
+
42
+ * simplify go exeutable ([#73](https://github.com/alexfalkowski/nonnative/issues/73)) ([95e4cf4](https://github.com/alexfalkowski/nonnative/commit/95e4cf44180ee84d32cc42ee058d6742732b57b9))
43
+
44
+ ## [1.36.0](https://github.com/alexfalkowski/nonnative/compare/v1.35.2...v1.36.0) (2021-04-21)
45
+
46
+
47
+ ### Features
48
+
49
+ * remove badge from docs ([#72](https://github.com/alexfalkowski/nonnative/issues/72)) ([2cd384c](https://github.com/alexfalkowski/nonnative/commit/2cd384cb9f73da1f131829f1eaf9b0c9e1ae3cdf))
50
+
5
51
  ### [1.35.2](https://github.com/alexfalkowski/nonnative/compare/v1.35.1...v1.35.2) (2021-04-21)
6
52
 
7
53
 
data/Gemfile.lock CHANGED
@@ -1,10 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nonnative (1.36.0)
4
+ nonnative (1.41.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,5 +1,5 @@
1
1
  [![CircleCI](https://circleci.com/gh/alexfalkowski/nonnative.svg?style=svg)](https://circleci.com/gh/alexfalkowski/nonnative)
2
- [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=alexfalkowski_nonnative&metric=alert_status)](https://sonarcloud.io/dashboard?id=alexfalkowski_nonnative)
2
+ [![Coverage Status](https://coveralls.io/repos/github/alexfalkowski/nonnative/badge.svg?branch=master)](https://coveralls.io/github/alexfalkowski/nonnative?branch=master)
3
3
 
4
4
  # Nonnative
5
5
 
@@ -61,21 +61,21 @@ require 'nonnative'
61
61
  Nonnative.configure do |config|
62
62
  config.strategy = :startup
63
63
 
64
- config.process do |d|
65
- d.name = 'start_1'
66
- d.command = 'features/support/bin/start 12_321'
67
- d.timeout = config.strategy.timeout
68
- d.port = 12_321
69
- d.log = 'features/logs/12_321.log'
70
- d.signal = 'INT' # Possible values are described in Signal.list.keys
64
+ config.process do |p|
65
+ p.name = 'start_1'
66
+ p.command = 'features/support/bin/start 12_321'
67
+ p.timeout = config.strategy.timeout
68
+ p.port = 12_321
69
+ p.log = 'features/logs/12_321.log'
70
+ p.signal = 'INT' # Possible values are described in Signal.list.keys
71
71
  end
72
72
 
73
- config.process do |d|
74
- d.name = 'start_2'
75
- d.command = 'features/support/bin/start 12_322'
76
- d.timeout = 0.5
77
- d.port = 12_322
78
- d.log = 'features/logs/12_322.log'
73
+ config.process do |p|
74
+ p.name = 'start_2'
75
+ p.command = 'features/support/bin/start 12_322'
76
+ p.timeout = 0.5
77
+ p.port = 12_322
78
+ p.log = 'features/logs/12_322.log'
79
79
  end
80
80
  end
81
81
  ```
@@ -321,6 +321,8 @@ We allow different proxies to be configured. These proxies can be used to simula
321
321
  - `none` (this is the default)
322
322
  - `fault_injection`
323
323
 
324
+ ##### Processes
325
+
324
326
  Setup it up programmatically:
325
327
 
326
328
  ```ruby
@@ -329,8 +331,46 @@ require 'nonnative'
329
331
  Nonnative.configure do |config|
330
332
  config.strategy = :manual
331
333
 
332
- config.server do |d|
333
- d.proxy = {
334
+ config.process do |p|
335
+ p.proxy = {
336
+ type: 'fault_injection',
337
+ port: 20_000,
338
+ log: 'features/logs/proxy_server.log',
339
+ options: {
340
+ delay: 5
341
+ }
342
+ }
343
+ end
344
+ end
345
+ ```
346
+
347
+ Setup it up through configuration:
348
+
349
+ ```yaml
350
+ version: 1.0
351
+ strategy: manual
352
+ processes:
353
+ -
354
+ proxy:
355
+ type: fault_injection
356
+ port: 20000
357
+ log: features/logs/proxy_server.log
358
+ options:
359
+ delay: 5
360
+ ```
361
+
362
+ ##### Servers
363
+
364
+ Setup it up programmatically:
365
+
366
+ ```ruby
367
+ require 'nonnative'
368
+
369
+ Nonnative.configure do |config|
370
+ config.strategy = :manual
371
+
372
+ config.server do |s|
373
+ s.proxy = {
334
374
  type: 'fault_injection',
335
375
  port: 20_000,
336
376
  log: 'features/logs/proxy_server.log',
@@ -364,6 +404,20 @@ The `fault_injection` proxy allows you to simulate failures by injecting them. W
364
404
  - `delay` - This delays the communication between the connection. Default is 2 secs can be configured through options.
365
405
  - `invalid_data` - This takes the input and rearranges it to produce invalid data.
366
406
 
407
+ ###### Processes
408
+
409
+ Setup it up programmatically:
410
+
411
+ ```ruby
412
+ name = 'name of process in configuration'
413
+ server = Nonnative.pool.process_by_name(name)
414
+
415
+ server.proxy.close_all # To use close_all.
416
+ server.proxy.reset # To reset it back to a good state.
417
+ ```
418
+
419
+ ###### Servers
420
+
367
421
  Setup it up programmatically:
368
422
 
369
423
  ```ruby
@@ -374,7 +428,6 @@ server.proxy.close_all # To use close_all.
374
428
  server.proxy.reset # To reset it back to a good state.
375
429
  ```
376
430
 
377
-
378
431
  ### Go
379
432
 
380
433
  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`
@@ -388,13 +441,14 @@ package main
388
441
 
389
442
  import (
390
443
  "testing"
444
+
445
+ "github.com/your_location/cmd"
391
446
  )
392
447
 
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
448
  func TestFeatures(t *testing.T) {
397
- main()
449
+ if err := cmd.Execute(); err != nil {
450
+ t.Fatal(err.Error())
451
+ }
398
452
  }
399
453
  ```
400
454
 
@@ -407,5 +461,5 @@ go test -mod vendor -c -tags features -covermode=count -o your_binary -coverpkg=
407
461
  Then to get an executable you do the following:
408
462
 
409
463
  ```ruby
410
- Nonnative::GoCommand.new('your_binary', 'reports').executable('sub_command', '--config config.yaml')
464
+ Nonnative.go_executable('reports', 'your_binary', 'sub_command', '--config config.yaml')
411
465
  ```
data/lib/nonnative.rb CHANGED
@@ -19,11 +19,12 @@ 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
23
  require 'nonnative/configuration_process'
23
24
  require 'nonnative/configuration_server'
24
25
  require 'nonnative/configuration_proxy'
25
26
  require 'nonnative/service'
26
- require 'nonnative/command'
27
+ require 'nonnative/process'
27
28
  require 'nonnative/pool'
28
29
  require 'nonnative/server'
29
30
  require 'nonnative/http_client'
@@ -46,6 +47,10 @@ module Nonnative
46
47
  class << self
47
48
  attr_reader :pool
48
49
 
50
+ def go_executable(output, exec, cmd, *params)
51
+ Nonnative::GoCommand.new(exec, output).executable(cmd, params)
52
+ end
53
+
49
54
  def load_configuration(path)
50
55
  @configuration ||= Nonnative::Configuration.load_file(path) # rubocop:disable Naming/MemoizedInstanceVariableName
51
56
  end
@@ -3,6 +3,7 @@
3
3
  module Nonnative
4
4
  class CloseAllSocketPair < SocketPair
5
5
  def connect(local_socket)
6
+ ensure
6
7
  local_socket.close
7
8
  end
8
9
  end
@@ -26,6 +26,8 @@ module Nonnative
26
26
  d.port = fd['port']
27
27
  d.log = fd['log']
28
28
  d.signal = fd['signal']
29
+
30
+ proxy d, fd['proxy']
29
31
  end
30
32
  end
31
33
  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 < ConfigurationService
5
+ attr_accessor :command, :signal
6
6
  end
7
7
  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 < ConfigurationService
5
+ attr_accessor :klass
18
6
  end
19
7
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
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
18
+ end
19
+ end
@@ -48,27 +48,46 @@ module Nonnative
48
48
  def perform_start
49
49
  loop do
50
50
  thread = Thread.start(tcp_server.accept) do |local_socket|
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}"
51
+ accept_connection local_socket
59
52
  end
60
53
 
61
- thread.report_on_exception = false
62
54
  connections[thread.object_id] = thread
63
55
  end
64
56
  end
65
57
 
58
+ def accept_connection(local_socket)
59
+ id = Thread.current.object_id
60
+ socket_info = local_socket.inspect
61
+
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
+
69
+ connections.delete(id)
70
+ end
71
+
66
72
  def connect(local_socket)
67
- SocketPairFactory.create(read_state, service.proxy, logger).connect(local_socket)
73
+ pair = SocketPairFactory.create(read_state, service.proxy)
74
+ pair.connect(local_socket)
75
+ rescue StandardError => e
76
+ local_socket.close
77
+
78
+ e
79
+ end
80
+
81
+ def close_connections
82
+ connections.each_value(&:terminate)
83
+ connections.clear
68
84
  end
69
85
 
70
86
  def apply_state(state)
71
- mutex.synchronize { @state = state }
87
+ mutex.synchronize do
88
+ @state = state
89
+ close_connections
90
+ end
72
91
  end
73
92
 
74
93
  def read_state
@@ -12,12 +12,6 @@ module Nonnative
12
12
  "#{exec} #{flags(cmd, params).join(' ')} #{cmd} #{params}".strip
13
13
  end
14
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
15
  private
22
16
 
23
17
  attr_reader :exec, :output
@@ -14,6 +14,11 @@ module Nonnative
14
14
  [processes, servers].each { |t| process(t, :stop, :closed?, &block) }
15
15
  end
16
16
 
17
+ def process_by_name(name)
18
+ index = configuration.processes.find_index { |s| s.name == name }
19
+ processes[index].first
20
+ end
21
+
17
22
  def server_by_name(name)
18
23
  index = configuration.servers.find_index { |s| s.name == name }
19
24
  servers[index].first
@@ -25,7 +30,7 @@ module Nonnative
25
30
 
26
31
  def processes
27
32
  @processes ||= configuration.processes.map do |d|
28
- [Nonnative::Command.new(d), Nonnative::Port.new(d)]
33
+ [Nonnative::Process.new(d), Nonnative::Port.new(d)]
29
34
  end
30
35
  end
31
36
 
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class Command < Nonnative::Service
4
+ class Process < Nonnative::Service
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
@@ -4,12 +4,6 @@ module Nonnative
4
4
  class Server < Nonnative::Service
5
5
  attr_reader :proxy
6
6
 
7
- def initialize(service)
8
- @proxy = Nonnative::ProxyFactory.create(service)
9
-
10
- super service
11
- end
12
-
13
7
  def start
14
8
  unless thread
15
9
  proxy.start
@@ -2,9 +2,12 @@
2
2
 
3
3
  module Nonnative
4
4
  class Service
5
+ attr_reader :proxy
6
+
5
7
  def initialize(service)
6
8
  @service = service
7
9
  @timeout = Nonnative::Timeout.new(service.timeout)
10
+ @proxy = Nonnative::ProxyFactory.create(service)
8
11
  end
9
12
 
10
13
  def name
@@ -2,9 +2,8 @@
2
2
 
3
3
  module Nonnative
4
4
  class SocketPair
5
- def initialize(proxy, logger)
5
+ def initialize(proxy)
6
6
  @proxy = proxy
7
- @logger = logger
8
7
  end
9
8
 
10
9
  def connect(local_socket)
@@ -16,8 +15,6 @@ module Nonnative
16
15
  break if pipe(ready, local_socket, remote_socket)
17
16
  break if pipe(ready, remote_socket, local_socket)
18
17
  end
19
- rescue StandardError => e
20
- logger.error e
21
18
  ensure
22
19
  local_socket.close
23
20
  remote_socket&.close
@@ -25,7 +22,7 @@ module Nonnative
25
22
 
26
23
  protected
27
24
 
28
- attr_reader :proxy, :logger
25
+ attr_reader :proxy
29
26
 
30
27
  def create_remote_socket
31
28
  ::TCPSocket.new('0.0.0.0', proxy.port)
@@ -3,7 +3,7 @@
3
3
  module Nonnative
4
4
  class SocketPairFactory
5
5
  class << self
6
- def create(type, proxy, logger)
6
+ def create(type, proxy)
7
7
  pair = case type
8
8
  when :close_all
9
9
  CloseAllSocketPair
@@ -15,7 +15,7 @@ module Nonnative
15
15
  SocketPair
16
16
  end
17
17
 
18
- pair.new(proxy, logger)
18
+ pair.new(proxy)
19
19
  end
20
20
  end
21
21
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- VERSION = '1.36.0'
4
+ VERSION = '1.41.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.36.0
4
+ version: 1.41.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-21 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,11 @@ 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
265
  - lib/nonnative/configuration_server.rb
266
+ - lib/nonnative/configuration_service.rb
266
267
  - lib/nonnative/delay_socket_pair.rb
267
268
  - lib/nonnative/error.rb
268
269
  - lib/nonnative/fault_injection_proxy.rb
@@ -276,6 +277,7 @@ files:
276
277
  - lib/nonnative/observability.rb
277
278
  - lib/nonnative/pool.rb
278
279
  - lib/nonnative/port.rb
280
+ - lib/nonnative/process.rb
279
281
  - lib/nonnative/proxy.rb
280
282
  - lib/nonnative/proxy_factory.rb
281
283
  - lib/nonnative/server.rb