baza.rb 0.0.8 → 0.0.9

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: a4854042d95be4cff78c5fa7d534c754025b0fea372586f6f782c755df332432
4
- data.tar.gz: bffcee29566e8959085d7948365eebd8cfb399c248644f494b73e82de0c65734
3
+ metadata.gz: f06c63d179589bfc28c89fb3d60d4df8232fca069fdf1b225c830091765cef74
4
+ data.tar.gz: de1e9b335a7b34f702f3367980400d0667b08e78817ecef533eef0f81a38e1a5
5
5
  SHA512:
6
- metadata.gz: d7e0c79a6f30febc5a408c7d63bab7606cdb9881c0bfc708fbd4ca7e5a60df14fe0d3677ec35c6fcf38210a23292fbe873bf51befd600040cfa42148170a8038
7
- data.tar.gz: 027042ba55cd31a9ddea329efb085499deb342ba117a6a42782d1f328e74efb1164d12ae3329e7af0b4562705703f8af52b8057fa1012f0a8c2f9e488d3ad383
6
+ metadata.gz: 80c39feaf4cd305ba697f38225203f7a6917899cdc89a0ecf0735196b9f54691ebcac0b3742659e546e083d7d7e472f54c1d7648c9722ab478968e5b8a3bfcb4
7
+ data.tar.gz: 2f37dce17730366ae52e4a4cdd1e69651038402b2a2ab9e806829c275a9140fa0164bbdc31b550a4d809235615d976bd7705ab00e5e7a9186f29898ebece114b
@@ -28,7 +28,7 @@ name: actionlint
28
28
  - master
29
29
  jobs:
30
30
  actionlint:
31
- runs-on: ubuntu-22.04
31
+ runs-on: ubuntu-24.04
32
32
  steps:
33
33
  - uses: actions/checkout@v4
34
34
  - name: Download actionlint
@@ -25,7 +25,7 @@ name: codecov
25
25
  - master
26
26
  jobs:
27
27
  codecov:
28
- runs-on: ubuntu-22.04
28
+ runs-on: ubuntu-24.04
29
29
  steps:
30
30
  - uses: actions/checkout@v4
31
31
  - uses: ruby/setup-ruby@v1
@@ -24,7 +24,7 @@ name: copyrights
24
24
  pull_request:
25
25
  jobs:
26
26
  copyrights:
27
- runs-on: ubuntu-22.04
27
+ runs-on: ubuntu-24.04
28
28
  steps:
29
29
  - uses: actions/checkout@v4
30
30
  - uses: yegor256/copyrights-action@0.0.5
@@ -32,7 +32,7 @@ concurrency:
32
32
  cancel-in-progress: true
33
33
  jobs:
34
34
  markdown-lint:
35
- runs-on: ubuntu-22.04
35
+ runs-on: ubuntu-24.04
36
36
  steps:
37
37
  - uses: actions/checkout@v4
38
38
  - uses: articulate/actions-markdownlint@v1
@@ -28,7 +28,7 @@ name: pdd
28
28
  - master
29
29
  jobs:
30
30
  pdd:
31
- runs-on: ubuntu-22.04
31
+ runs-on: ubuntu-24.04
32
32
  steps:
33
33
  - uses: actions/checkout@v4
34
34
  - uses: volodya-lombrozo/pdd-action@master
@@ -24,7 +24,7 @@ name: xcop
24
24
  pull_request:
25
25
  jobs:
26
26
  xcop:
27
- runs-on: ubuntu-22.04
27
+ runs-on: ubuntu-24.04
28
28
  steps:
29
29
  - uses: actions/checkout@v4
30
30
  - uses: g4s8/xcop-action@master
@@ -28,7 +28,7 @@ name: yamllint
28
28
  - master
29
29
  jobs:
30
30
  yamllint:
31
- runs-on: ubuntu-22.04
31
+ runs-on: ubuntu-24.04
32
32
  steps:
33
33
  - uses: actions/checkout@v4
34
34
  - uses: ibiqlik/action-yamllint@v3
data/Gemfile CHANGED
@@ -29,12 +29,12 @@ gem 'minitest-reporters', '1.7.1', require: false
29
29
  gem 'net-ping', '2.0.8', require: false
30
30
  gem 'rake', '13.2.1', require: false
31
31
  gem 'random-port', '>0', require: false
32
- gem 'rspec-rails', '6.1.4', require: false
33
- gem 'rubocop', '1.65.1', require: false
34
- gem 'rubocop-performance', '1.21.1', require: false
35
- gem 'rubocop-rspec', '3.0.4', require: false
32
+ gem 'rspec-rails', '7.0.1', require: false
33
+ gem 'rubocop', '1.66.1', require: false
34
+ gem 'rubocop-performance', '1.22.1', require: false
35
+ gem 'rubocop-rspec', '3.1.0', require: false
36
36
  gem 'simplecov', '0.22.0', require: false
37
37
  gem 'simplecov-cobertura', '2.1.0', require: false
38
38
  gem 'wait_for', '~>0', require: false
39
- gem 'webmock', '3.23.1', require: false
40
- gem 'yard', '0.9.36', require: false
39
+ gem 'webmock', '3.24.0', require: false
40
+ gem 'yard', '0.9.37', require: false
data/Gemfile.lock CHANGED
@@ -78,8 +78,9 @@ GEM
78
78
  others (> 0)
79
79
  tago (> 0)
80
80
  yaml (~> 0.3)
81
- faraday (2.11.0)
81
+ faraday (2.12.0)
82
82
  faraday-net_http (>= 2.0, < 3.4)
83
+ json
83
84
  logger
84
85
  faraday-http-cache (2.5.1)
85
86
  faraday (>= 0.8)
@@ -94,16 +95,16 @@ GEM
94
95
  ffi (1.17.0-x86_64-darwin)
95
96
  ffi (1.17.0-x86_64-linux-gnu)
96
97
  hashdiff (1.1.1)
97
- i18n (1.14.5)
98
+ i18n (1.14.6)
98
99
  concurrent-ruby (~> 1.0)
99
100
  io-console (0.7.2)
100
- irb (1.14.0)
101
+ irb (1.14.1)
101
102
  rdoc (>= 4.0.0)
102
103
  reline (>= 0.4.2)
103
104
  iri (0.8.0)
104
105
  json (2.7.2)
105
106
  language_server-protocol (3.17.0.3)
106
- logger (1.6.0)
107
+ logger (1.6.1)
107
108
  loofah (2.22.0)
108
109
  crass (~> 1.0.2)
109
110
  nokogiri (>= 1.12.0)
@@ -128,14 +129,14 @@ GEM
128
129
  racc (~> 1.4)
129
130
  others (0.0.3)
130
131
  parallel (1.26.3)
131
- parser (3.3.4.2)
132
+ parser (3.3.5.0)
132
133
  ast (~> 2.4.1)
133
134
  racc
134
135
  psych (5.1.2)
135
136
  stringio
136
137
  public_suffix (6.0.1)
137
138
  racc (1.8.1)
138
- rack (3.1.7)
139
+ rack (3.1.8)
139
140
  rack-session (2.0.0)
140
141
  rack (>= 3.0.0)
141
142
  rack-test (2.1.0)
@@ -164,45 +165,43 @@ GEM
164
165
  rdoc (6.7.0)
165
166
  psych (>= 4.0.0)
166
167
  regexp_parser (2.9.2)
167
- reline (0.5.9)
168
+ reline (0.5.10)
168
169
  io-console (~> 0.5)
169
170
  retries (0.0.5)
170
- rexml (3.3.6)
171
- strscan
172
- rspec-core (3.13.0)
171
+ rexml (3.3.8)
172
+ rspec-core (3.13.1)
173
173
  rspec-support (~> 3.13.0)
174
- rspec-expectations (3.13.2)
174
+ rspec-expectations (3.13.3)
175
175
  diff-lcs (>= 1.2.0, < 2.0)
176
176
  rspec-support (~> 3.13.0)
177
- rspec-mocks (3.13.1)
177
+ rspec-mocks (3.13.2)
178
178
  diff-lcs (>= 1.2.0, < 2.0)
179
179
  rspec-support (~> 3.13.0)
180
- rspec-rails (6.1.4)
181
- actionpack (>= 6.1)
182
- activesupport (>= 6.1)
183
- railties (>= 6.1)
180
+ rspec-rails (7.0.1)
181
+ actionpack (>= 7.0)
182
+ activesupport (>= 7.0)
183
+ railties (>= 7.0)
184
184
  rspec-core (~> 3.13)
185
185
  rspec-expectations (~> 3.13)
186
186
  rspec-mocks (~> 3.13)
187
187
  rspec-support (~> 3.13)
188
188
  rspec-support (3.13.1)
189
- rubocop (1.65.1)
189
+ rubocop (1.66.1)
190
190
  json (~> 2.3)
191
191
  language_server-protocol (>= 3.17.0)
192
192
  parallel (~> 1.10)
193
193
  parser (>= 3.3.0.2)
194
194
  rainbow (>= 2.2.2, < 4.0)
195
195
  regexp_parser (>= 2.4, < 3.0)
196
- rexml (>= 3.2.5, < 4.0)
197
- rubocop-ast (>= 1.31.1, < 2.0)
196
+ rubocop-ast (>= 1.32.2, < 2.0)
198
197
  ruby-progressbar (~> 1.7)
199
198
  unicode-display_width (>= 2.4.0, < 3.0)
200
- rubocop-ast (1.32.1)
199
+ rubocop-ast (1.32.3)
201
200
  parser (>= 3.3.1.0)
202
- rubocop-performance (1.21.1)
201
+ rubocop-performance (1.22.1)
203
202
  rubocop (>= 1.48.1, < 2.0)
204
203
  rubocop-ast (>= 1.31.1, < 2.0)
205
- rubocop-rspec (3.0.4)
204
+ rubocop-rspec (3.1.0)
206
205
  rubocop (~> 1.61)
207
206
  ruby-progressbar (1.13.0)
208
207
  securerandom (0.3.1)
@@ -213,28 +212,27 @@ GEM
213
212
  simplecov-cobertura (2.1.0)
214
213
  rexml
215
214
  simplecov (~> 0.19)
216
- simplecov-html (0.12.3)
215
+ simplecov-html (0.13.1)
217
216
  simplecov_json_formatter (0.1.4)
218
217
  stringio (3.1.1)
219
- strscan (3.1.0)
220
218
  tago (0.0.2)
221
219
  thor (1.3.2)
222
220
  typhoeus (1.4.1)
223
221
  ethon (>= 0.9.0)
224
222
  tzinfo (2.0.6)
225
223
  concurrent-ruby (~> 1.0)
226
- unicode-display_width (2.5.0)
224
+ unicode-display_width (2.6.0)
227
225
  uri (0.13.1)
228
226
  useragent (0.16.10)
229
227
  wait_for (0.1.1)
230
- webmock (3.23.1)
228
+ webmock (3.24.0)
231
229
  addressable (>= 2.8.0)
232
230
  crack (>= 0.3.2)
233
231
  hashdiff (>= 0.4.0, < 2.0.0)
234
- webrick (1.8.1)
232
+ webrick (1.8.2)
235
233
  yaml (0.3.0)
236
- yard (0.9.36)
237
- zeitwerk (2.6.17)
234
+ yard (0.9.37)
235
+ zeitwerk (2.7.0)
238
236
 
239
237
  PLATFORMS
240
238
  arm64-darwin-22
@@ -251,15 +249,15 @@ DEPENDENCIES
251
249
  net-ping (= 2.0.8)
252
250
  rake (= 13.2.1)
253
251
  random-port (> 0)
254
- rspec-rails (= 6.1.4)
255
- rubocop (= 1.65.1)
256
- rubocop-performance (= 1.21.1)
257
- rubocop-rspec (= 3.0.4)
252
+ rspec-rails (= 7.0.1)
253
+ rubocop (= 1.66.1)
254
+ rubocop-performance (= 1.22.1)
255
+ rubocop-rspec (= 3.1.0)
258
256
  simplecov (= 0.22.0)
259
257
  simplecov-cobertura (= 2.1.0)
260
258
  wait_for (~> 0)
261
- webmock (= 3.23.1)
262
- yard (= 0.9.36)
259
+ webmock (= 3.24.0)
260
+ yard (= 0.9.37)
263
261
 
264
262
  BUNDLED WITH
265
263
  2.4.22
data/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  [![Hits-of-Code](https://hitsofcode.com/github/zerocracy/baza.rb)](https://hitsofcode.com/view/github/zerocracy/baza.rb)
11
11
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/zerocracy/baza.rb/blob/master/LICENSE.txt)
12
12
 
13
- It's an clinet for [Zerocracy API](https://www.zerocracy.com), in Ruby.
13
+ It's an client for [Zerocracy API](https://www.zerocracy.com), in Ruby.
14
14
 
15
15
  ## How to contribute
16
16
 
@@ -30,5 +30,5 @@
30
30
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
31
31
  # License:: MIT
32
32
  class BazaRb
33
- VERSION = '0.0.8'
33
+ VERSION = '0.0.9'
34
34
  end
data/lib/baza-rb.rb CHANGED
@@ -40,6 +40,15 @@ require_relative 'baza-rb/version'
40
40
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
41
41
  # License:: MIT
42
42
  class BazaRb
43
+ # When the server failed (503).
44
+ class ServerFailure < StandardError; end
45
+
46
+ # When request timeout.
47
+ class TimedOut < StandardError; end
48
+
49
+ # Unexpected response arrived from the server.
50
+ class BadResponse < StandardError; end
51
+
43
52
  # Ctor.
44
53
  #
45
54
  # @param [String] host Host name
@@ -88,7 +97,7 @@ class BazaRb
88
97
  }
89
98
  elapsed(@loog) do
90
99
  ret =
91
- with_retries(max_tries: @retries) do
100
+ with_retries(max_tries: @retries, rescue: TimedOut) do
92
101
  checked(
93
102
  Typhoeus::Request.put(
94
103
  home.append('push').append(name).to_s,
@@ -126,7 +135,7 @@ class BazaRb
126
135
  request.on_body do |chunk|
127
136
  f.write(chunk)
128
137
  end
129
- with_retries(max_tries: @retries) do
138
+ with_retries(max_tries: @retries, rescue: TimedOut) do
130
139
  request.run
131
140
  end
132
141
  checked(request.response)
@@ -148,7 +157,7 @@ class BazaRb
148
157
  finished = false
149
158
  elapsed(@loog) do
150
159
  ret =
151
- with_retries(max_tries: @retries) do
160
+ with_retries(max_tries: @retries, rescue: TimedOut) do
152
161
  checked(
153
162
  Typhoeus::Request.get(
154
163
  home.append('finished').append(id).to_s,
@@ -172,7 +181,7 @@ class BazaRb
172
181
  stdout = ''
173
182
  elapsed(@loog) do
174
183
  ret =
175
- with_retries(max_tries: @retries) do
184
+ with_retries(max_tries: @retries, rescue: TimedOut) do
176
185
  checked(
177
186
  Typhoeus::Request.get(
178
187
  home.append('stdout').append("#{id}.txt").to_s,
@@ -196,7 +205,7 @@ class BazaRb
196
205
  code = 0
197
206
  elapsed(@loog) do
198
207
  ret =
199
- with_retries(max_tries: @retries) do
208
+ with_retries(max_tries: @retries, rescue: TimedOut) do
200
209
  checked(
201
210
  Typhoeus::Request.get(
202
211
  home.append('exit').append("#{id}.txt").to_s,
@@ -220,7 +229,7 @@ class BazaRb
220
229
  verdict = 0
221
230
  elapsed(@loog) do
222
231
  ret =
223
- with_retries(max_tries: @retries) do
232
+ with_retries(max_tries: @retries, rescue: TimedOut) do
224
233
  checked(
225
234
  Typhoeus::Request.get(
226
235
  home.append('jobs').append(id).append('verified.txt').to_s,
@@ -243,7 +252,7 @@ class BazaRb
243
252
  raise 'The "name" of the job may not be empty' if name.empty?
244
253
  raise 'The "owner" of the lock is nil' if owner.nil?
245
254
  elapsed(@loog) do
246
- with_retries(max_tries: @retries) do
255
+ with_retries(max_tries: @retries, rescue: TimedOut) do
247
256
  checked(
248
257
  Typhoeus::Request.get(
249
258
  home.append('lock').append(name).add(owner:).to_s,
@@ -265,7 +274,7 @@ class BazaRb
265
274
  raise 'The "name" of the job may not be empty' if name.empty?
266
275
  raise 'The "owner" of the lock is nil' if owner.nil?
267
276
  elapsed(@loog) do
268
- with_retries(max_tries: @retries) do
277
+ with_retries(max_tries: @retries, rescue: TimedOut) do
269
278
  checked(
270
279
  Typhoeus::Request.get(
271
280
  home.append('unlock').append(name).add(owner:).to_s,
@@ -288,7 +297,7 @@ class BazaRb
288
297
  job = 0
289
298
  elapsed(@loog) do
290
299
  ret =
291
- with_retries(max_tries: @retries) do
300
+ with_retries(max_tries: @retries, rescue: TimedOut) do
292
301
  checked(
293
302
  Typhoeus::Request.get(
294
303
  home.append('recent').append("#{name}.txt").to_s,
@@ -312,7 +321,7 @@ class BazaRb
312
321
  exists = 0
313
322
  elapsed(@loog) do
314
323
  ret =
315
- with_retries(max_tries: @retries) do
324
+ with_retries(max_tries: @retries, rescue: TimedOut) do
316
325
  checked(
317
326
  Typhoeus::Request.get(
318
327
  home.append('exists').append(name).to_s,
@@ -338,7 +347,7 @@ class BazaRb
338
347
  id = nil
339
348
  elapsed(@loog) do
340
349
  ret =
341
- with_retries(max_tries: @retries) do
350
+ with_retries(max_tries: @retries, rescue: TimedOut) do
342
351
  checked(
343
352
  Typhoeus::Request.post(
344
353
  home.append('durables').append('place').to_s,
@@ -370,7 +379,7 @@ class BazaRb
370
379
  raise 'The "file" of the durable is nil' if file.nil?
371
380
  raise "The file '#{file}' is absent" unless File.exist?(file)
372
381
  elapsed(@loog) do
373
- with_retries(max_tries: @retries) do
382
+ with_retries(max_tries: @retries, rescue: TimedOut) do
374
383
  checked(
375
384
  Typhoeus::Request.put(
376
385
  home.append('durables').append(id).to_s,
@@ -408,7 +417,7 @@ class BazaRb
408
417
  request.on_body do |chunk|
409
418
  f.write(chunk)
410
419
  end
411
- with_retries(max_tries: @retries) do
420
+ with_retries(max_tries: @retries, rescue: TimedOut) do
412
421
  request.run
413
422
  end
414
423
  checked(request.response)
@@ -427,7 +436,7 @@ class BazaRb
427
436
  raise 'The "owner" of the lock is nil' if owner.nil?
428
437
  raise 'The "owner" of the lock may not be empty' if owner.empty?
429
438
  elapsed(@loog) do
430
- with_retries(max_tries: @retries) do
439
+ with_retries(max_tries: @retries, rescue: TimedOut) do
431
440
  checked(
432
441
  Typhoeus::Request.get(
433
442
  home.append('durables').append(id).append('lock').add(owner:).to_s,
@@ -450,7 +459,7 @@ class BazaRb
450
459
  raise 'The "owner" of the lock is nil' if owner.nil?
451
460
  raise 'The "owner" of the lock may not be empty' if owner.empty?
452
461
  elapsed(@loog) do
453
- with_retries(max_tries: @retries) do
462
+ with_retries(max_tries: @retries, rescue: TimedOut) do
454
463
  checked(
455
464
  Typhoeus::Request.get(
456
465
  home.append('durables').append(id).append('unlock').add(owner:).to_s,
@@ -470,7 +479,6 @@ class BazaRb
470
479
  # @return [Boolean] TRUE if job taken, otherwise false
471
480
  def pop(owner, zip)
472
481
  raise 'The "zip" of the job is nil' if zip.nil?
473
- raise "The 'zip' file is absent: #{zip}" unless File.exist?(zip)
474
482
  success = false
475
483
  FileUtils.rm_f(zip)
476
484
  elapsed(@loog) do
@@ -487,7 +495,7 @@ class BazaRb
487
495
  request.on_body do |chunk|
488
496
  f.write(chunk)
489
497
  end
490
- with_retries(max_tries: @retries) do
498
+ with_retries(max_tries: @retries, rescue: TimedOut) do
491
499
  request.run
492
500
  end
493
501
  ret = request.response
@@ -513,7 +521,7 @@ class BazaRb
513
521
  raise 'The "zip" of the job is nil' if zip.nil?
514
522
  raise "The 'zip' file is absent: #{zip}" unless File.exist?(zip)
515
523
  elapsed(@loog) do
516
- with_retries(max_tries: @retries) do
524
+ with_retries(max_tries: @retries, rescue: TimedOut) do
517
525
  checked(
518
526
  Typhoeus::Request.put(
519
527
  home.append('finish').add(id:).to_s,
@@ -531,6 +539,37 @@ class BazaRb
531
539
  end
532
540
  end
533
541
 
542
+ # Enter a valve.
543
+ #
544
+ # @param [String] name Name of the job
545
+ # @param [String] badge Unique badge of the valve
546
+ # @param [String] why The reason
547
+ # @param [nil|Integer] job The ID of the job
548
+ # @return [String] The result just calculated or retrieved
549
+ def enter(name, badge, why, job)
550
+ elapsed(@loog, intro: "Entered valve #{badge} to #{name}") do
551
+ with_retries(max_tries: @retries, rescue: TimedOut) do
552
+ ret = checked(
553
+ Typhoeus::Request.get(
554
+ home.append('valves').append('result').add(badge:).to_s,
555
+ headers:
556
+ ),
557
+ [200, 204]
558
+ )
559
+ return ret.body if ret.code == 200
560
+ r = yield
561
+ uri = home.append('valves').append('add')
562
+ .add(name:)
563
+ .add(badge:)
564
+ .add(why:)
565
+ .add(result: r.to_s)
566
+ uri = uri.add(job:) unless job.nil?
567
+ checked(Typhoeus::Request.post(uri.to_s, headers:), 302)
568
+ r
569
+ end
570
+ end
571
+ end
572
+
534
573
  private
535
574
 
536
575
  def headers
@@ -571,14 +610,19 @@ class BazaRb
571
610
  .scheme(@ssl ? 'https' : 'http')
572
611
  end
573
612
 
613
+ # Check the HTTP response and return it.
614
+ #
615
+ # @param [Typhoeus::Response] ret The response
616
+ # @param [Array<Integer>] allowed List of acceptable HTTP codes
617
+ # @return [Typhoeus::Response] The same response
574
618
  def checked(ret, allowed = [200])
575
619
  allowed = [allowed] unless allowed.is_a?(Array)
576
620
  mtd = (ret.request.original_options[:method] || '???').upcase
577
621
  url = ret.effective_url
578
622
  if ret.return_code == :operation_timedout
579
623
  msg = "#{mtd} #{url} timed out in #{ret.total_time}s"
580
- @loog.debug(msg)
581
- raise msg
624
+ @loog.error(msg)
625
+ raise TimedOut, msg
582
626
  end
583
627
  log = "#{mtd} #{url} -> #{ret.code} (#{format('%0.2f', ret.total_time)}s)"
584
628
  if allowed.include?(ret.code)
@@ -608,6 +652,7 @@ class BazaRb
608
652
  when 0
609
653
  msg += ', most likely an internal error'
610
654
  end
611
- raise msg
655
+ @loog.error(msg)
656
+ raise ServerFailure, msg
612
657
  end
613
658
  end
data/test/test_baza-rb.rb CHANGED
@@ -89,6 +89,16 @@ class TestBazaRb < Minitest::Test
89
89
  end
90
90
  end
91
91
 
92
+ def test_live_enter_valve
93
+ WebMock.enable_net_connect!
94
+ skip unless we_are_online
95
+ r = 'something'
96
+ n = fake_name
97
+ badge = fake_name
98
+ assert_equal(r, LIVE.enter(n, badge, 'no reason', nil) { r })
99
+ assert_equal(r, LIVE.enter(n, badge, 'no reason', nil) { nil })
100
+ end
101
+
92
102
  def test_durable_place
93
103
  WebMock.disable_net_connect!
94
104
  stub_request(:post, 'https://example.org/durables/place').to_return(
@@ -180,7 +190,20 @@ class TestBazaRb < Minitest::Test
180
190
  )
181
191
  end
182
192
 
193
+ def test_push_with_server_failure
194
+ WebMock.disable_net_connect!
195
+ stub_request(:put, 'https://example.org/push/foo')
196
+ .to_return(status: 503, body: 'oops', headers: { 'X-Zerocracy-Failure': 'the failure' })
197
+ .to_raise('why second time?')
198
+ e = assert_raises { BazaRb.new('example.org', 443, '000').push('foo', 'data', []) }
199
+ [
200
+ 'Invalid response code #503',
201
+ '"the failure"'
202
+ ].each { |t| assert(e.message.include?(t), "Can't find '#{t}' in #{e.message.inspect}") }
203
+ end
204
+
183
205
  def test_real_http
206
+ WebMock.enable_net_connect!
184
207
  req =
185
208
  with_http_server(200, 'yes') do |baza|
186
209
  baza.name_exists?('simple')
@@ -189,6 +212,7 @@ class TestBazaRb < Minitest::Test
189
212
  end
190
213
 
191
214
  def test_push_with_meta
215
+ WebMock.enable_net_connect!
192
216
  req =
193
217
  with_http_server(200, 'yes') do |baza|
194
218
  baza.push('simple', 'hello, world!', ['boom!', 'хей!'])
@@ -197,6 +221,7 @@ class TestBazaRb < Minitest::Test
197
221
  end
198
222
 
199
223
  def test_push_with_big_meta
224
+ WebMock.enable_net_connect!
200
225
  req =
201
226
  with_http_server(200, 'yes') do |baza|
202
227
  baza.push(
@@ -213,6 +238,7 @@ class TestBazaRb < Minitest::Test
213
238
  end
214
239
 
215
240
  def test_push_compressed_content
241
+ WebMock.enable_net_connect!
216
242
  req =
217
243
  with_http_server(200, 'yes') do |baza|
218
244
  baza.push('simple', 'hello, world!', %w[meta1 meta2 meta3])
@@ -224,6 +250,7 @@ class TestBazaRb < Minitest::Test
224
250
  end
225
251
 
226
252
  def test_push_compression_disabled
253
+ WebMock.enable_net_connect!
227
254
  req =
228
255
  with_http_server(200, 'yes', compress: false) do |baza|
229
256
  baza.push('simple', 'hello, world!', %w[meta1 meta2 meta3])
@@ -280,7 +307,7 @@ class TestBazaRb < Minitest::Test
280
307
  end
281
308
 
282
309
  def fake_name
283
- "fake-#{SecureRandom.hex(8)}"
310
+ "fake#{SecureRandom.hex(8)}"
284
311
  end
285
312
 
286
313
  def we_are_online
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baza.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-30 00:00:00.000000000 Z
11
+ date: 2024-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace