specwrk 0.2.0 → 0.3.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 +4 -4
- data/lib/specwrk/cli.rb +16 -27
- data/lib/specwrk/client.rb +12 -5
- data/lib/specwrk/version.rb +1 -1
- data/lib/specwrk/worker/completion_formatter.rb +10 -5
- data/lib/specwrk/worker/executor.rb +4 -0
- data/lib/specwrk/worker.rb +11 -0
- data/lib/specwrk.rb +22 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 620355ee669758b42abdd60b638044fbe7bbc4880d51356ea20e9785ab1bb4e3
|
4
|
+
data.tar.gz: 4444c229b60e2b83b5adfc620290965c1a866d5de0cdcfab8a63fab4a7948312
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec37f9d67476e6e0ce8ac12d970dc153ca4cdcec1f931b4e35973d71f05459599e8e38b750d8a5bfd81bc218866bc55f1e9dacc561340d9d67fa75b437cd4efa
|
7
|
+
data.tar.gz: 5267ffee5481ca36ce19559e84bc1c276de5351abe755950f22d2b8a2047ba931376d6c07adc69fd678375487d120964c04c090bdb5f121c32cde433d61bfe59
|
data/lib/specwrk/cli.rb
CHANGED
@@ -16,7 +16,7 @@ module Specwrk
|
|
16
16
|
extend Hookable
|
17
17
|
|
18
18
|
on_included do |base|
|
19
|
-
base.unique_option :uri, type: :string, default: ENV.fetch("SPECWRK_SRV_URI", "
|
19
|
+
base.unique_option :uri, type: :string, default: ENV.fetch("SPECWRK_SRV_URI", "http://localhost:#{ENV.fetch("SPECWRK_SRV_PORT", "5138")}"), desc: "HTTP URI of the server to pull jobs from. Overrides SPECWRK_SRV_PORT. Default 5138."
|
20
20
|
base.unique_option :key, type: :string, default: ENV.fetch("SPECWRK_SRV_KEY", ""), aliases: ["-k"], desc: "Authentication key clients must use for access. Overrides SPECWRK_SRV_KEY. Default ''."
|
21
21
|
base.unique_option :run, type: :string, default: ENV.fetch("SPECWRK_RUN", "main"), aliases: ["-r"], desc: "The run identifier for this job execution. Overrides SPECWRK_RUN. Default main."
|
22
22
|
base.unique_option :timeout, type: :integer, default: ENV.fetch("SPECWRK_TIMEOUT", "5"), aliases: ["-t"], desc: "The amount of time to wait for the server to respond. Overrides SPECWRK_TIMEOUT. Default 5."
|
@@ -54,7 +54,8 @@ module Specwrk
|
|
54
54
|
|
55
55
|
require "specwrk/worker"
|
56
56
|
|
57
|
-
Specwrk::Worker.run!
|
57
|
+
status = Specwrk::Worker.run!
|
58
|
+
exit(status)
|
58
59
|
end
|
59
60
|
end
|
60
61
|
end
|
@@ -133,13 +134,21 @@ module Specwrk
|
|
133
134
|
self.class.setup(**args)
|
134
135
|
|
135
136
|
start_workers
|
136
|
-
|
137
|
+
wait_for_workers_exit
|
137
138
|
|
138
139
|
require "specwrk/cli_reporter"
|
139
|
-
|
140
|
+
Specwrk::CLIReporter.new.report
|
140
141
|
|
141
142
|
exit(status)
|
142
143
|
end
|
144
|
+
|
145
|
+
def wait_for_workers_exit
|
146
|
+
@exited_pids = Specwrk.wait_for_pids_exit(@worker_pids)
|
147
|
+
end
|
148
|
+
|
149
|
+
def status
|
150
|
+
@exited_pids.value?(1) ? 1 : 0
|
151
|
+
end
|
143
152
|
end
|
144
153
|
|
145
154
|
class Serve < Dry::CLI::Command
|
@@ -194,44 +203,24 @@ module Specwrk
|
|
194
203
|
status "Samples seeded ✓"
|
195
204
|
end
|
196
205
|
|
197
|
-
wait_for_pids_exit([seed_pid])
|
206
|
+
Specwrk.wait_for_pids_exit([seed_pid])
|
198
207
|
|
199
208
|
return if Specwrk.force_quit
|
200
209
|
status "Starting #{worker_count} workers..."
|
201
210
|
start_workers
|
202
211
|
|
203
212
|
status "#{worker_count} workers started ✓\n"
|
204
|
-
wait_for_pids_exit(@worker_pids)
|
213
|
+
Specwrk.wait_for_pids_exit(@worker_pids)
|
205
214
|
|
206
215
|
return if Specwrk.force_quit
|
207
216
|
|
208
217
|
require "specwrk/cli_reporter"
|
209
218
|
status = Specwrk::CLIReporter.new.report
|
210
219
|
|
211
|
-
wait_for_pids_exit([web_pid, seed_pid] + @worker_pids)
|
220
|
+
Specwrk.wait_for_pids_exit([web_pid, seed_pid] + @worker_pids)
|
212
221
|
exit(status)
|
213
222
|
end
|
214
223
|
|
215
|
-
def wait_for_pids_exit(pids)
|
216
|
-
exited_pids = {}
|
217
|
-
|
218
|
-
loop do
|
219
|
-
pids.each do |pid|
|
220
|
-
next if exited_pids.key? pid
|
221
|
-
|
222
|
-
_, status = Process.waitpid2(pid, Process::WNOHANG)
|
223
|
-
exited_pids[pid] = status.exitstatus if status&.exitstatus
|
224
|
-
rescue Errno::ECHILD
|
225
|
-
exited_pids[pid] = 0
|
226
|
-
end
|
227
|
-
|
228
|
-
break if exited_pids.keys.length == pids.length
|
229
|
-
sleep 0.1
|
230
|
-
end
|
231
|
-
|
232
|
-
exited_pids
|
233
|
-
end
|
234
|
-
|
235
224
|
def status(msg)
|
236
225
|
print "\e[2K\r#{msg}"
|
237
226
|
$stdout.flush
|
data/lib/specwrk/client.rb
CHANGED
@@ -4,6 +4,12 @@ require "uri"
|
|
4
4
|
require "net/http"
|
5
5
|
require "json"
|
6
6
|
|
7
|
+
require "specwrk"
|
8
|
+
|
9
|
+
# Some rspec setups might use webmock, which intercepts specwrk server calls
|
10
|
+
# Let's capture the OG HTTP before that happens
|
11
|
+
Specwrk.net_http = Net::HTTP
|
12
|
+
|
7
13
|
module Specwrk
|
8
14
|
class Client
|
9
15
|
def self.connect?
|
@@ -18,7 +24,8 @@ module Specwrk
|
|
18
24
|
|
19
25
|
def self.build_http
|
20
26
|
uri = URI(ENV.fetch("SPECWRK_SRV_URI", "http://localhost:5138"))
|
21
|
-
|
27
|
+
Specwrk.net_http.new(uri.host, uri.port).tap do |http|
|
28
|
+
http.use_ssl = uri.scheme == "https"
|
22
29
|
http.open_timeout = ENV.fetch("SPECWRK_TIMEOUT", "5").to_i
|
23
30
|
http.read_timeout = ENV.fetch("SPECWRK_TIMEOUT", "5").to_i
|
24
31
|
http.keep_alive_timeout = 300
|
@@ -105,28 +112,28 @@ module Specwrk
|
|
105
112
|
private
|
106
113
|
|
107
114
|
def get(path, headers: default_headers, body: nil)
|
108
|
-
request =
|
115
|
+
request = Specwrk.net_http::Get.new(path, headers)
|
109
116
|
request.body = body if body
|
110
117
|
|
111
118
|
make_request(request)
|
112
119
|
end
|
113
120
|
|
114
121
|
def post(path, headers: default_headers, body: nil)
|
115
|
-
request =
|
122
|
+
request = Specwrk.net_http::Post.new(path, headers)
|
116
123
|
request.body = body if body
|
117
124
|
|
118
125
|
make_request(request)
|
119
126
|
end
|
120
127
|
|
121
128
|
def put(path, headers: default_headers, body: nil)
|
122
|
-
request =
|
129
|
+
request = Specwrk.net_http::Put.new(path, headers)
|
123
130
|
request.body = body if body
|
124
131
|
|
125
132
|
make_request(request)
|
126
133
|
end
|
127
134
|
|
128
135
|
def delete(path, headers: default_headers, body: nil)
|
129
|
-
request =
|
136
|
+
request = Specwrk.net_http::Delete.new(path, headers)
|
130
137
|
request.body = body if body
|
131
138
|
|
132
139
|
make_request(request)
|
data/lib/specwrk/version.rb
CHANGED
@@ -5,23 +5,28 @@ module Specwrk
|
|
5
5
|
class CompletionFormatter
|
6
6
|
RSpec::Core::Formatters.register self, :stop
|
7
7
|
|
8
|
-
attr_reader :examples
|
8
|
+
attr_reader :examples, :failure
|
9
9
|
|
10
10
|
def initialize
|
11
11
|
@examples = []
|
12
|
+
@failure = false
|
12
13
|
end
|
13
14
|
|
14
15
|
def stop(group_notification)
|
15
16
|
group_notification.notifications.map do |notification|
|
17
|
+
unless failure
|
18
|
+
@failure = notification.example.execution_result.status == :failed
|
19
|
+
end
|
20
|
+
|
16
21
|
examples << {
|
17
22
|
id: notification.example.id,
|
18
23
|
full_description: notification.example.full_description,
|
19
|
-
status: notification.example.
|
24
|
+
status: notification.example.execution_result.status,
|
20
25
|
file_path: notification.example.metadata[:file_path],
|
21
26
|
line_number: notification.example.metadata[:line_number],
|
22
|
-
started_at: notification.example.
|
23
|
-
finished_at: notification.example.
|
24
|
-
run_time: notification.example.
|
27
|
+
started_at: notification.example.execution_result.started_at.iso8601(6),
|
28
|
+
finished_at: notification.example.execution_result.finished_at.iso8601(6),
|
29
|
+
run_time: notification.example.execution_result.run_time
|
25
30
|
}
|
26
31
|
end
|
27
32
|
end
|
data/lib/specwrk/worker.rb
CHANGED
@@ -42,10 +42,14 @@ module Specwrk
|
|
42
42
|
|
43
43
|
@heartbeat_thread.kill
|
44
44
|
client.close
|
45
|
+
|
46
|
+
status
|
45
47
|
rescue Errno::ECONNREFUSED
|
46
48
|
warn "\nServer at #{ENV.fetch("SPECWRK_SRV_URI", "http://localhost:5138")} is refusing connections, exiting..."
|
49
|
+
1
|
47
50
|
rescue Errno::ECONNRESET
|
48
51
|
warn "\nServer at #{ENV.fetch("SPECWRK_SRV_URI", "http://localhost:5138")} stopped responding to connections, exiting..."
|
52
|
+
1
|
49
53
|
end
|
50
54
|
|
51
55
|
def execute
|
@@ -83,6 +87,13 @@ module Specwrk
|
|
83
87
|
|
84
88
|
attr_reader :running, :client, :executor
|
85
89
|
|
90
|
+
def status
|
91
|
+
return 1 if executor.failure
|
92
|
+
return 1 if Specwrk.force_quit
|
93
|
+
|
94
|
+
0
|
95
|
+
end
|
96
|
+
|
86
97
|
def warn(msg)
|
87
98
|
super("#{ENV.fetch("SPECWRK_ID", "specwrk-worker")}: #{msg}")
|
88
99
|
end
|
data/lib/specwrk.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "specwrk/version"
|
4
4
|
|
5
5
|
module Specwrk
|
6
6
|
Error = Class.new(StandardError)
|
@@ -15,7 +15,27 @@ module Specwrk
|
|
15
15
|
@starting_pid = Process.pid
|
16
16
|
|
17
17
|
class << self
|
18
|
-
attr_accessor :force_quit
|
18
|
+
attr_accessor :force_quit, :net_http
|
19
19
|
attr_reader :starting_pid
|
20
|
+
|
21
|
+
def wait_for_pids_exit(pids)
|
22
|
+
exited_pids = {}
|
23
|
+
|
24
|
+
loop do
|
25
|
+
pids.each do |pid|
|
26
|
+
next if exited_pids.key? pid
|
27
|
+
|
28
|
+
_, status = Process.waitpid2(pid, Process::WNOHANG)
|
29
|
+
exited_pids[pid] = status.exitstatus if status&.exitstatus
|
30
|
+
rescue Errno::ECHILD
|
31
|
+
exited_pids[pid] = 1
|
32
|
+
end
|
33
|
+
|
34
|
+
break if exited_pids.keys.length == pids.length
|
35
|
+
sleep 0.1
|
36
|
+
end
|
37
|
+
|
38
|
+
exited_pids
|
39
|
+
end
|
20
40
|
end
|
21
41
|
end
|