specwrk 0.11.0 → 0.12.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_reporter.rb +2 -2
- data/lib/specwrk/store/file_adapter.rb +8 -28
- data/lib/specwrk/store.rb +38 -0
- data/lib/specwrk/version.rb +1 -1
- data/lib/specwrk/web/auth.rb +6 -2
- data/lib/specwrk/web/endpoints.rb +0 -5
- data/lib/specwrk/worker/executor.rb +1 -0
- data/lib/specwrk.rb +16 -0
- 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: d642db71c542c4b2dbf17038db546a34f713ffccb010dc903e4e7a96c8071016
|
4
|
+
data.tar.gz: 00fd8258a2441acd31c4a484c2e039ad5e83028e8c10eef509cdca070daab1c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c88c00baa4d0455e8b928e276e6c66cf66fd881f7e9193a4e19f665a93d7b177b18e5f2cd00a8605ef4613e9607634791527898836f85f99bec0d3faf17e3d7
|
7
|
+
data.tar.gz: 7370d6c27e8b052a17bcc93d84fdbea18efab35792ec6f010cc21d05a45ed8aad4cc29e1c24e4b5e10aca65787f8fb08bc7bf94fa4e928293e41405a300259d6
|
data/lib/specwrk/cli_reporter.rb
CHANGED
@@ -16,8 +16,8 @@ module Specwrk
|
|
16
16
|
return 1
|
17
17
|
end
|
18
18
|
|
19
|
-
puts "\nFinished in #{total_duration} " \
|
20
|
-
"(total execution time of #{total_run_time})\n"
|
19
|
+
puts "\nFinished in #{Specwrk.human_readable_duration total_duration} " \
|
20
|
+
"(total execution time of #{Specwrk.human_readable_duration total_run_time})\n"
|
21
21
|
|
22
22
|
client.shutdown
|
23
23
|
|
@@ -60,7 +60,6 @@ module Specwrk
|
|
60
60
|
else
|
61
61
|
filename = filename_for_key(key_string)
|
62
62
|
write(filename, JSON.generate(value))
|
63
|
-
known_key_pairs[key_string] = filename
|
64
63
|
end
|
65
64
|
end
|
66
65
|
|
@@ -71,16 +70,12 @@ module Specwrk
|
|
71
70
|
def clear
|
72
71
|
FileUtils.rm_rf(path)
|
73
72
|
FileUtils.mkdir_p(path)
|
74
|
-
|
75
|
-
@known_key_pairs = nil
|
76
73
|
end
|
77
74
|
|
78
75
|
def delete(*keys)
|
79
|
-
filenames = keys.map { |key|
|
76
|
+
filenames = keys.map { |key| filename_for_key key }.compact
|
80
77
|
|
81
78
|
FileUtils.rm_f(filenames)
|
82
|
-
|
83
|
-
keys.each { |key| known_key_pairs.delete(key) }
|
84
79
|
end
|
85
80
|
|
86
81
|
def merge!(h2)
|
@@ -88,8 +83,6 @@ module Specwrk
|
|
88
83
|
end
|
89
84
|
|
90
85
|
def multi_read(*read_keys)
|
91
|
-
known_key_pairs # precache before each thread tries to look them up
|
92
|
-
|
93
86
|
result_queue = Queue.new
|
94
87
|
|
95
88
|
read_keys.each do |key|
|
@@ -112,8 +105,6 @@ module Specwrk
|
|
112
105
|
end
|
113
106
|
|
114
107
|
def multi_write(hash)
|
115
|
-
known_key_pairs # precache before each thread tries to look them up
|
116
|
-
|
117
108
|
result_queue = Queue.new
|
118
109
|
|
119
110
|
hash_with_filenames = hash.map { |key, value| [key.to_s, [filename_for_key(key.to_s), value]] }.to_h
|
@@ -126,7 +117,6 @@ module Specwrk
|
|
126
117
|
end
|
127
118
|
|
128
119
|
Thread.pass until result_queue.length == hash.length
|
129
|
-
hash_with_filenames.each { |key, (filename, _value)| known_key_pairs[key] = filename }
|
130
120
|
end
|
131
121
|
|
132
122
|
def empty?
|
@@ -145,29 +135,19 @@ module Specwrk
|
|
145
135
|
end
|
146
136
|
|
147
137
|
def read(key)
|
148
|
-
|
138
|
+
filename = filename_for_key key
|
139
|
+
File.read(filename)
|
140
|
+
rescue Errno::ENOENT
|
141
|
+
nil
|
149
142
|
end
|
150
143
|
|
151
144
|
def filename_for_key(key)
|
152
145
|
File.join(
|
153
146
|
path,
|
154
|
-
|
155
|
-
counter_prefix(key),
|
156
|
-
encode_key(key)
|
157
|
-
].join("_")
|
147
|
+
encode_key(key)
|
158
148
|
) + EXT
|
159
149
|
end
|
160
150
|
|
161
|
-
def counter_prefix(key)
|
162
|
-
count = keys.index(key) || counter.tap { @counter += 1 }
|
163
|
-
|
164
|
-
"%012d" % count
|
165
|
-
end
|
166
|
-
|
167
|
-
def counter
|
168
|
-
@counter ||= keys.length
|
169
|
-
end
|
170
|
-
|
171
151
|
def path
|
172
152
|
@path ||= File.join(uri.path, scope).tap do |full_path|
|
173
153
|
FileUtils.mkdir_p(full_path)
|
@@ -179,14 +159,14 @@ module Specwrk
|
|
179
159
|
end
|
180
160
|
|
181
161
|
def decode_key(key)
|
182
|
-
encoded_key_part = File.basename(key).delete_suffix(EXT)
|
162
|
+
encoded_key_part = File.basename(key).delete_suffix(EXT)
|
183
163
|
padding_count = (4 - encoded_key_part.length % 4) % 4
|
184
164
|
|
185
165
|
Base64.urlsafe_decode64(encoded_key_part + ("=" * padding_count))
|
186
166
|
end
|
187
167
|
|
188
168
|
def known_key_pairs
|
189
|
-
|
169
|
+
Dir.entries(path).sort.map do |filename|
|
190
170
|
next if filename.start_with? "."
|
191
171
|
next unless filename.end_with? EXT
|
192
172
|
|
data/lib/specwrk/store.rb
CHANGED
@@ -98,6 +98,7 @@ module Specwrk
|
|
98
98
|
|
99
99
|
class PendingStore < Store
|
100
100
|
RUN_TIME_BUCKET_MAXIMUM_KEY = :____run_time_bucket_maximum
|
101
|
+
ORDER_KEY = :____order
|
101
102
|
|
102
103
|
def run_time_bucket_maximum=(val)
|
103
104
|
@run_time_bucket_maximum = self[RUN_TIME_BUCKET_MAXIMUM_KEY] = val
|
@@ -107,6 +108,41 @@ module Specwrk
|
|
107
108
|
@run_time_bucket_maximum ||= self[RUN_TIME_BUCKET_MAXIMUM_KEY]
|
108
109
|
end
|
109
110
|
|
111
|
+
def order=(val)
|
112
|
+
@order = nil
|
113
|
+
|
114
|
+
self[ORDER_KEY] = if val.nil? || val.length.zero?
|
115
|
+
nil
|
116
|
+
else
|
117
|
+
val
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def order
|
122
|
+
@order ||= self[ORDER_KEY] || []
|
123
|
+
end
|
124
|
+
|
125
|
+
def keys
|
126
|
+
return super if order.length.zero?
|
127
|
+
|
128
|
+
order
|
129
|
+
end
|
130
|
+
|
131
|
+
def merge!(hash)
|
132
|
+
super
|
133
|
+
self.order = hash.keys
|
134
|
+
end
|
135
|
+
|
136
|
+
def clear
|
137
|
+
@order = nil
|
138
|
+
super
|
139
|
+
end
|
140
|
+
|
141
|
+
def reload
|
142
|
+
@order = nil
|
143
|
+
super
|
144
|
+
end
|
145
|
+
|
110
146
|
def shift_bucket
|
111
147
|
return bucket_by_file unless run_time_bucket_maximum&.positive?
|
112
148
|
|
@@ -146,6 +182,7 @@ module Specwrk
|
|
146
182
|
end
|
147
183
|
|
148
184
|
delete(*consumed_keys)
|
185
|
+
self.order = order - consumed_keys
|
149
186
|
bucket
|
150
187
|
end
|
151
188
|
|
@@ -171,6 +208,7 @@ module Specwrk
|
|
171
208
|
end
|
172
209
|
|
173
210
|
delete(*consumed_keys)
|
211
|
+
self.order = order - consumed_keys
|
174
212
|
bucket
|
175
213
|
end
|
176
214
|
end
|
data/lib/specwrk/version.rb
CHANGED
data/lib/specwrk/web/auth.rb
CHANGED
@@ -11,7 +11,7 @@ module Specwrk
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def call(env)
|
14
|
-
env[:request] ||= Rack::Request.new(env)
|
14
|
+
@request = env[:request] ||= Rack::Request.new(env)
|
15
15
|
|
16
16
|
return @app.call(env) if [nil, ""].include? ENV["SPECWRK_SRV_KEY"]
|
17
17
|
return @app.call(env) if @excluded_paths.include? env[:request].path_info
|
@@ -28,7 +28,11 @@ module Specwrk
|
|
28
28
|
private
|
29
29
|
|
30
30
|
def unauthorized
|
31
|
-
|
31
|
+
if @request.head?
|
32
|
+
[401, {}, []]
|
33
|
+
else
|
34
|
+
[401, {"content-type" => "application/json"}, ["Unauthorized"]]
|
35
|
+
end
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
@@ -270,11 +270,6 @@ module Specwrk
|
|
270
270
|
|
271
271
|
private
|
272
272
|
|
273
|
-
def before_lock
|
274
|
-
completed_examples
|
275
|
-
run_time_data
|
276
|
-
end
|
277
|
-
|
278
273
|
def completed_examples
|
279
274
|
@completed_data ||= payload.map { |example| [example[:id], example] if processing[example[:id]] }.compact.to_h
|
280
275
|
end
|
@@ -40,6 +40,7 @@ module Specwrk
|
|
40
40
|
completion_formatter.examples.clear
|
41
41
|
|
42
42
|
RSpec.clear_examples
|
43
|
+
RSpec.configuration.backtrace_formatter.filter_gem "specwrk"
|
43
44
|
|
44
45
|
# see https://github.com/rspec/rspec-core/pull/2723
|
45
46
|
if Gem::Version.new(RSpec::Core::Version::STRING) <= Gem::Version.new("3.9.1")
|
data/lib/specwrk.rb
CHANGED
@@ -38,5 +38,21 @@ module Specwrk
|
|
38
38
|
|
39
39
|
exited_pids
|
40
40
|
end
|
41
|
+
|
42
|
+
def human_readable_duration(total_seconds, precision: 2)
|
43
|
+
secs = total_seconds.to_f
|
44
|
+
hours = (secs / 3600).to_i
|
45
|
+
mins = ((secs % 3600) / 60).to_i
|
46
|
+
seconds = secs % 60
|
47
|
+
|
48
|
+
parts = []
|
49
|
+
parts << "#{hours}h" if hours.positive?
|
50
|
+
parts << "#{mins}m" if mins.positive?
|
51
|
+
if seconds.positive?
|
52
|
+
sec_str = format("%0.#{precision}f", seconds).sub(/\.?0+$/, "")
|
53
|
+
parts << "#{sec_str}s"
|
54
|
+
end
|
55
|
+
parts.join(" ")
|
56
|
+
end
|
41
57
|
end
|
42
58
|
end
|