baza.rb 0.5.0 → 0.5.1

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: a4fb6929da01d8ec60b802d9bd8c3300456ff66144723496bbe60a11b1f67fad
4
- data.tar.gz: 29db7120d95c442fcb529e9f1f1d8f3c7145baca1cf829cd011bdf6b6d6918bd
3
+ metadata.gz: 44a77b9084f7de4be77127285ca1b33ab3966a7d984b50c3c84dfaa72e98a36c
4
+ data.tar.gz: 8d8e3368ff7ee202b794c88195842183b92982e4d816ba3a83a688a870bd9cda
5
5
  SHA512:
6
- metadata.gz: 0212eb14782da74ea7ecbfa855e3a075e4639577f512ea12f98549451a7000a820a0bbb918f909f0eacde8c62593bc62910b7829a759ee989a2844e5def8fb20
7
- data.tar.gz: 883fb08a189555e8abdb1800c2ab2d08229833945b11809930412d5da82890b23856122c9e2fe6c44f369db007a0dee4ebb3b51991a7ba4eedca261ec135b934
6
+ metadata.gz: 6f7f2c3dc38e59b28eb9cbc57099544f4762119eb66b2af45c5e2b17205e67121a5a96629a71b38d53b07517face93dce74b73bf270fc4d38fa0a69a5a4e5d2a
7
+ data.tar.gz: be736e44829b1384a724e31f026d8e1f7568de5867da240c0c27feec74ab1eb2a8148f3657035a4fcf0ee39376774637a44e60238a48255ca56b179d06675cf8
@@ -16,4 +16,4 @@ jobs:
16
16
  runs-on: ubuntu-24.04
17
17
  steps:
18
18
  - uses: actions/checkout@v4
19
- - uses: yegor256/copyrights-action@0.0.10
19
+ - uses: yegor256/copyrights-action@0.0.12
@@ -12,6 +12,7 @@ name: rake
12
12
  - master
13
13
  jobs:
14
14
  rake:
15
+ timeout-minutes: 15
15
16
  strategy:
16
17
  matrix:
17
18
  os: [ubuntu-24.04, macos-15]
@@ -16,4 +16,4 @@ jobs:
16
16
  runs-on: ubuntu-24.04
17
17
  steps:
18
18
  - uses: actions/checkout@v4
19
- - uses: crate-ci/typos@v1.32.0
19
+ - uses: crate-ci/typos@v1.33.1
data/.gitignore CHANGED
@@ -8,4 +8,4 @@ doc/
8
8
  node_modules/
9
9
  rdoc/
10
10
  vendor/
11
- .claude
11
+ .claude/
data/Gemfile.lock CHANGED
@@ -22,8 +22,8 @@ GEM
22
22
  ansi (1.5.0)
23
23
  ast (2.4.3)
24
24
  backtrace (0.4.0)
25
- base64 (0.2.0)
26
- bigdecimal (3.1.9)
25
+ base64 (0.3.0)
26
+ bigdecimal (3.2.1)
27
27
  builder (3.3.0)
28
28
  crack (1.0.0)
29
29
  bigdecimal
@@ -62,7 +62,7 @@ GEM
62
62
  ffi (1.17.2-x86_64-darwin)
63
63
  ffi (1.17.2-x86_64-linux-gnu)
64
64
  hashdiff (1.2.0)
65
- iri (0.10.0)
65
+ iri (0.11.2)
66
66
  json (2.12.2)
67
67
  language_server-protocol (3.17.0.5)
68
68
  lint_roller (1.1.0)
@@ -101,13 +101,13 @@ GEM
101
101
  tago (> 0)
102
102
  racc (1.8.1)
103
103
  rainbow (3.1.1)
104
- rake (13.2.1)
104
+ rake (13.3.0)
105
105
  random-port (0.7.5)
106
106
  tago (> 0)
107
107
  regexp_parser (2.10.0)
108
108
  retries (0.0.5)
109
109
  rexml (3.4.1)
110
- rubocop (1.75.7)
110
+ rubocop (1.75.8)
111
111
  json (~> 2.3)
112
112
  language_server-protocol (~> 3.17.0.2)
113
113
  lint_roller (~> 1.1.0)
@@ -121,7 +121,7 @@ GEM
121
121
  rubocop-ast (1.44.1)
122
122
  parser (>= 3.3.7.2)
123
123
  prism (~> 1.4)
124
- rubocop-minitest (0.38.0)
124
+ rubocop-minitest (0.38.1)
125
125
  lint_roller (~> 1.1)
126
126
  rubocop (>= 1.75.0, < 2.0)
127
127
  rubocop-ast (>= 1.38.0, < 2.0)
data/baza.rb.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.license = 'MIT'
15
15
  s.summary = 'Zerocracy API Ruby Client'
16
16
  s.description =
17
- 'It is a Ruby client for Zerocracy API, allowing you to check your jobs ' \
17
+ 'It is a Ruby client for Zerocracy API, allowing you to check your job ' \
18
18
  'statuses, upload and download binaries, lock/unlock them, manage durables, ' \
19
19
  'and do everything else that is possible to do via the HTTP API.'
20
20
  s.authors = ['Yegor Bugayenko']
@@ -13,5 +13,5 @@
13
13
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
14
14
  # License:: MIT
15
15
  class BazaRb
16
- VERSION = '0.5.0'
16
+ VERSION = '0.5.1'
17
17
  end
data/lib/baza-rb.rb CHANGED
@@ -69,7 +69,7 @@ class BazaRb
69
69
  nick = nil
70
70
  elapsed(@loog) do
71
71
  ret =
72
- with_retries(max_tries: @retries, rescue: TimedOut) do
72
+ retry_it do
73
73
  checked(
74
74
  Typhoeus::Request.get(
75
75
  home.append('whoami').to_s,
@@ -91,7 +91,7 @@ class BazaRb
91
91
  z = nil
92
92
  elapsed(@loog) do
93
93
  ret =
94
- with_retries(max_tries: @retries, rescue: TimedOut) do
94
+ retry_it do
95
95
  checked(
96
96
  Typhoeus::Request.get(
97
97
  home.append('account').append('balance').to_s,
@@ -120,7 +120,7 @@ class BazaRb
120
120
  id = 0
121
121
  hdrs = headers.merge(
122
122
  'Content-Type' => 'application/octet-stream',
123
- 'Content-Length' => data.size
123
+ 'Content-Length' => data.bytesize
124
124
  )
125
125
  unless meta.empty?
126
126
  hdrs = hdrs.merge('X-Zerocracy-Meta' => meta.map { |v| Base64.encode64(v).delete("\n") }.join(' '))
@@ -133,7 +133,7 @@ class BazaRb
133
133
  }
134
134
  elapsed(@loog) do
135
135
  ret =
136
- with_retries(max_tries: @retries, rescue: TimedOut) do
136
+ retry_it do
137
137
  checked(
138
138
  Typhoeus::Request.put(
139
139
  home.append('push').append(name).to_s,
@@ -142,7 +142,7 @@ class BazaRb
142
142
  )
143
143
  end
144
144
  id = ret.body.to_i
145
- throw :"Pushed #{data.size} bytes to #{@host}, job ID is ##{id}"
145
+ throw :"Pushed #{data.bytesize} bytes to #{@host}, job ID is ##{id}"
146
146
  end
147
147
  id
148
148
  end
@@ -172,13 +172,13 @@ class BazaRb
172
172
  request.on_body do |chunk|
173
173
  f.write(chunk)
174
174
  end
175
- with_retries(max_tries: @retries, rescue: TimedOut) do
175
+ retry_it do
176
176
  request.run
177
177
  end
178
178
  checked(request.response)
179
179
  end
180
180
  data = File.binread(file)
181
- throw :"Pulled #{data.size} bytes of job ##{id} factbase at #{@host}"
181
+ throw :"Pulled #{data.bytesize} bytes of job ##{id} factbase at #{@host}"
182
182
  end
183
183
  end
184
184
  data
@@ -192,10 +192,10 @@ class BazaRb
192
192
  def finished?(id)
193
193
  raise 'The ID of the job is nil' if id.nil?
194
194
  raise 'The ID of the job must be a positive integer' unless id.positive?
195
- finished = false
195
+ fin = false
196
196
  elapsed(@loog) do
197
197
  ret =
198
- with_retries(max_tries: @retries, rescue: TimedOut) do
198
+ retry_it do
199
199
  checked(
200
200
  Typhoeus::Request.get(
201
201
  home.append('finished').append(id).to_s,
@@ -203,10 +203,10 @@ class BazaRb
203
203
  )
204
204
  )
205
205
  end
206
- finished = ret.body == 'yes'
207
- throw :"The job ##{id} is #{finished ? '' : 'not yet '}finished at #{@host}"
206
+ fin = ret.body == 'yes'
207
+ throw :"The job ##{id} is #{'not yet ' unless fin}finished at #{@host}#{" (#{ret.body.inspect})" unless fin}"
208
208
  end
209
- finished
209
+ fin
210
210
  end
211
211
 
212
212
  # Read and return the stdout of the job.
@@ -219,7 +219,7 @@ class BazaRb
219
219
  stdout = ''
220
220
  elapsed(@loog) do
221
221
  ret =
222
- with_retries(max_tries: @retries, rescue: TimedOut) do
222
+ retry_it do
223
223
  checked(
224
224
  Typhoeus::Request.get(
225
225
  home.append('stdout').append("#{id}.txt").to_s,
@@ -243,7 +243,7 @@ class BazaRb
243
243
  code = 0
244
244
  elapsed(@loog) do
245
245
  ret =
246
- with_retries(max_tries: @retries, rescue: TimedOut) do
246
+ retry_it do
247
247
  checked(
248
248
  Typhoeus::Request.get(
249
249
  home.append('exit').append("#{id}.txt").to_s,
@@ -267,7 +267,7 @@ class BazaRb
267
267
  verdict = ''
268
268
  elapsed(@loog) do
269
269
  ret =
270
- with_retries(max_tries: @retries, rescue: TimedOut) do
270
+ retry_it do
271
271
  checked(
272
272
  Typhoeus::Request.get(
273
273
  home.append('jobs').append(id).append('verified.txt').to_s,
@@ -291,7 +291,7 @@ class BazaRb
291
291
  raise 'The "owner" of the lock is nil' if owner.nil?
292
292
  elapsed(@loog) do
293
293
  ret =
294
- with_retries(max_tries: @retries, rescue: TimedOut) do
294
+ retry_it do
295
295
  checked(
296
296
  Typhoeus::Request.get(
297
297
  home.append('lock').append(name).add(owner:).to_s,
@@ -315,7 +315,7 @@ class BazaRb
315
315
  raise 'The "owner" of the lock is nil' if owner.nil?
316
316
  raise 'The "owner" of the lock may not be empty' if owner.empty?
317
317
  elapsed(@loog) do
318
- with_retries(max_tries: @retries, rescue: TimedOut) do
318
+ retry_it do
319
319
  checked(
320
320
  Typhoeus::Request.get(
321
321
  home.append('unlock').append(name).add(owner:).to_s,
@@ -338,7 +338,7 @@ class BazaRb
338
338
  job = nil
339
339
  elapsed(@loog) do
340
340
  ret =
341
- with_retries(max_tries: @retries, rescue: TimedOut) do
341
+ retry_it do
342
342
  checked(
343
343
  Typhoeus::Request.get(
344
344
  home.append('recent').append("#{name}.txt").to_s,
@@ -362,7 +362,7 @@ class BazaRb
362
362
  exists = false
363
363
  elapsed(@loog) do
364
364
  ret =
365
- with_retries(max_tries: @retries, rescue: TimedOut) do
365
+ retry_it do
366
366
  checked(
367
367
  Typhoeus::Request.get(
368
368
  home.append('exists').append(name).to_s,
@@ -390,7 +390,7 @@ class BazaRb
390
390
  id = nil
391
391
  elapsed(@loog) do
392
392
  ret =
393
- with_retries(max_tries: @retries, rescue: TimedOut) do
393
+ retry_it do
394
394
  checked(
395
395
  Typhoeus::Request.post(
396
396
  home.append('durables').append('place').to_s,
@@ -423,7 +423,7 @@ class BazaRb
423
423
  raise 'The "file" of the durable is nil' if file.nil?
424
424
  raise "The file '#{file}' is absent" unless File.exist?(file)
425
425
  elapsed(@loog) do
426
- with_retries(max_tries: @retries, rescue: TimedOut) do
426
+ retry_it do
427
427
  checked(
428
428
  Typhoeus::Request.put(
429
429
  home.append('durables').append(id).to_s,
@@ -461,7 +461,7 @@ class BazaRb
461
461
  request.on_body do |chunk|
462
462
  f.write(chunk)
463
463
  end
464
- with_retries(max_tries: @retries, rescue: TimedOut) do
464
+ retry_it do
465
465
  request.run
466
466
  end
467
467
  checked(request.response)
@@ -480,7 +480,7 @@ class BazaRb
480
480
  raise 'The "owner" of the lock is nil' if owner.nil?
481
481
  raise 'The "owner" of the lock may not be empty' if owner.empty?
482
482
  elapsed(@loog) do
483
- with_retries(max_tries: @retries, rescue: TimedOut) do
483
+ retry_it do
484
484
  checked(
485
485
  Typhoeus::Request.get(
486
486
  home.append('durables').append(id).append('lock').add(owner:).to_s,
@@ -503,7 +503,7 @@ class BazaRb
503
503
  raise 'The "owner" of the lock is nil' if owner.nil?
504
504
  raise 'The "owner" of the lock may not be empty' if owner.empty?
505
505
  elapsed(@loog) do
506
- with_retries(max_tries: @retries, rescue: TimedOut) do
506
+ retry_it do
507
507
  checked(
508
508
  Typhoeus::Request.get(
509
509
  home.append('durables').append(id).append('unlock').add(owner:).to_s,
@@ -539,7 +539,7 @@ class BazaRb
539
539
  body['job'] = job unless job.nil?
540
540
  elapsed(@loog) do
541
541
  ret =
542
- with_retries(max_tries: @retries, rescue: TimedOut) do
542
+ retry_it do
543
543
  checked(
544
544
  Typhoeus::Request.post(
545
545
  home.append('account').append('transfer').to_s,
@@ -582,7 +582,7 @@ class BazaRb
582
582
  }
583
583
  elapsed(@loog) do
584
584
  ret =
585
- with_retries(max_tries: @retries, rescue: TimedOut) do
585
+ retry_it do
586
586
  checked(
587
587
  Typhoeus::Request.post(
588
588
  home.append('account').append('fee').to_s,
@@ -629,7 +629,7 @@ class BazaRb
629
629
  request.on_body do |chunk|
630
630
  f.write(chunk)
631
631
  end
632
- with_retries(max_tries: @retries, rescue: TimedOut) do
632
+ retry_it do
633
633
  request.run
634
634
  end
635
635
  ret = request.response
@@ -672,7 +672,7 @@ class BazaRb
672
672
  raise 'The "zip" of the job is nil' if zip.nil?
673
673
  raise "The 'zip' file is absent: #{zip}" unless File.exist?(zip)
674
674
  elapsed(@loog) do
675
- with_retries(max_tries: @retries, rescue: TimedOut) do
675
+ retry_it do
676
676
  checked(
677
677
  Typhoeus::Request.put(
678
678
  home.append('finish').add(id:).to_s,
@@ -705,7 +705,7 @@ class BazaRb
705
705
  # @raise [ServerFailure] If the valve operation fails
706
706
  def enter(name, badge, why, job)
707
707
  elapsed(@loog, intro: "Entered valve #{badge} to #{name}") do
708
- with_retries(max_tries: @retries, rescue: TimedOut) do
708
+ retry_it do
709
709
  ret = checked(
710
710
  Typhoeus::Request.get(
711
711
  home.append('valves').append('result').add(badge:).to_s,
@@ -746,7 +746,7 @@ class BazaRb
746
746
  def csrf
747
747
  token = nil
748
748
  elapsed(@loog) do
749
- with_retries(max_tries: @retries, rescue: TimedOut) do
749
+ retry_it do
750
750
  token = checked(
751
751
  Typhoeus::Request.get(
752
752
  home.append('csrf').to_s,
@@ -778,7 +778,7 @@ class BazaRb
778
778
  {
779
779
  'Content-Type' => 'application/zip',
780
780
  'Content-Encoding' => 'gzip',
781
- 'Content-Length' => body.size
781
+ 'Content-Length' => body.bytesize
782
782
  }
783
783
  )
784
784
  params.merge(body:, headers:)
@@ -800,6 +800,10 @@ class BazaRb
800
800
  .scheme(@ssl ? 'https' : 'http')
801
801
  end
802
802
 
803
+ def retry_it(&)
804
+ with_retries(max_tries: @retries, rescue: TimedOut, &)
805
+ end
806
+
803
807
  # Check the HTTP response and return it.
804
808
  #
805
809
  # @param [Typhoeus::Response] ret The response
@@ -840,7 +844,9 @@ class BazaRb
840
844
  ", most probably you are trying to reach a wrong server, which doesn't " \
841
845
  'have the URL that it is expected to have'
842
846
  when 0
843
- msg += ', most likely an internal error'
847
+ msg +=
848
+ ', most likely a connection failure, timeout, or SSL error ' \
849
+ "(r:#{ret.return_code}, m:#{ret.return_message})"
844
850
  end
845
851
  @loog.error(msg)
846
852
  raise ServerFailure, msg
data/test/test_baza-rb.rb CHANGED
@@ -31,9 +31,9 @@ class TestBazaRb < Minitest::Test
31
31
  PORT = 443
32
32
 
33
33
  # Live agent:
34
- LIVE = BazaRb.new(HOST, PORT, TOKEN, loog: Loog::NULL)
34
+ LIVE = BazaRb.new(HOST, PORT, TOKEN, loog: Loog::VERBOSE)
35
35
 
36
- def test_live_push
36
+ def test_live_full_cycle
37
37
  WebMock.enable_net_connect!
38
38
  skip('We are offline') unless we_are_online
39
39
  fb = Factbase.new
@@ -44,7 +44,12 @@ class TestBazaRb < Minitest::Test
44
44
  assert(LIVE.name_exists?(n))
45
45
  assert_predicate(LIVE.recent(n), :positive?)
46
46
  id = LIVE.recent(n)
47
- assert(wait_for(200) { LIVE.finished?(id) })
47
+ assert(
48
+ wait_for(8 * 60) do
49
+ sleep(5)
50
+ LIVE.finished?(id)
51
+ end
52
+ )
48
53
  refute_nil(LIVE.pull(id))
49
54
  refute_nil(LIVE.stdout(id))
50
55
  refute_nil(LIVE.exit_code(id))
@@ -371,30 +376,32 @@ class TestBazaRb < Minitest::Test
371
376
  def test_push_compressed_content
372
377
  WebMock.enable_net_connect!
373
378
  skip('We are offline') unless we_are_online
379
+ fb = Factbase.new
380
+ fb.insert.foo = 'test-' * 10_000
374
381
  req =
375
382
  with_http_server(200, 'yes') do |baza|
376
- baza.push('simple', 'hello, world!', %w[meta1 meta2 meta3])
383
+ baza.push('simple', fb.export, %w[meta1 meta2 meta3])
377
384
  end
378
385
  assert_equal('application/zip', req.content_type)
379
386
  assert_equal('gzip', req['content-encoding'])
380
387
  body = Zlib::GzipReader.zcat(StringIO.new(req.body))
381
- assert_equal('hello, world!', body)
388
+ assert_equal(fb.export, body)
382
389
  end
383
390
 
384
391
  def test_push_compression_disabled
385
392
  WebMock.enable_net_connect!
386
- skip('We are offline') unless we_are_online
393
+ fb = Factbase.new
394
+ fb.insert.foo = 'test-' * 10_000
387
395
  req =
388
396
  with_http_server(200, 'yes', compress: false) do |baza|
389
- baza.push('simple', 'hello, world!', %w[meta1 meta2 meta3])
397
+ baza.push('simple', fb.export, %w[meta1 meta2 meta3])
390
398
  end
391
399
  assert_equal('application/octet-stream', req.content_type)
392
- assert_equal('hello, world!', req.body)
400
+ assert_equal(fb.export, req.body)
393
401
  end
394
402
 
395
403
  def test_with_very_short_timeout
396
404
  WebMock.enable_net_connect!
397
- skip('We are offline') unless we_are_online
398
405
  host = '127.0.0.1'
399
406
  RandomPort::Pool::SINGLETON.acquire do |port|
400
407
  server = TCPServer.new(host, port)
@@ -413,11 +420,13 @@ class TestBazaRb < Minitest::Test
413
420
  BazaRb.new(host, port, '0000', ssl: false, timeout: 0.01).push('x', 'y', [])
414
421
  end.message, 'timed out in'
415
422
  )
416
- t.join
423
+ t.terminate
424
+ assert(t.join(1))
417
425
  end
418
426
  end
419
427
 
420
428
  def test_durable_save
429
+ WebMock.disable_net_connect!
421
430
  Dir.mktmpdir do |dir|
422
431
  file = File.join(dir, 'test.txt')
423
432
  File.write(file, 'test content')
@@ -429,6 +438,7 @@ class TestBazaRb < Minitest::Test
429
438
  end
430
439
 
431
440
  def test_durable_load
441
+ WebMock.disable_net_connect!
432
442
  Dir.mktmpdir do |dir|
433
443
  file = File.join(dir, 'loaded.txt')
434
444
  stub_request(:get, 'https://example.org:443/durables/42')
@@ -440,6 +450,7 @@ class TestBazaRb < Minitest::Test
440
450
  end
441
451
 
442
452
  def test_durable_lock
453
+ WebMock.disable_net_connect!
443
454
  stub_request(:get, 'https://example.org:443/durables/42/lock?owner=test-owner')
444
455
  .with(headers: { 'X-Zerocracy-Token' => '000' })
445
456
  .to_return(status: 302)
@@ -447,6 +458,7 @@ class TestBazaRb < Minitest::Test
447
458
  end
448
459
 
449
460
  def test_durable_unlock
461
+ WebMock.disable_net_connect!
450
462
  stub_request(:get, 'https://example.org:443/durables/42/unlock?owner=test-owner')
451
463
  .with(headers: { 'X-Zerocracy-Token' => '000' })
452
464
  .to_return(status: 302)
@@ -454,6 +466,7 @@ class TestBazaRb < Minitest::Test
454
466
  end
455
467
 
456
468
  def test_fee
469
+ WebMock.disable_net_connect!
457
470
  stub_request(:get, 'https://example.org:443/csrf')
458
471
  .with(headers: { 'X-Zerocracy-Token' => '000' })
459
472
  .to_return(status: 200, body: 'csrf-token')
@@ -474,6 +487,7 @@ class TestBazaRb < Minitest::Test
474
487
  end
475
488
 
476
489
  def test_enter
490
+ WebMock.disable_net_connect!
477
491
  stub_request(:get, 'https://example.org:443/valves/result?badge=test-badge')
478
492
  .with(headers: { 'X-Zerocracy-Token' => '000' })
479
493
  .to_return(status: 200, body: 'cached result')
@@ -482,6 +496,7 @@ class TestBazaRb < Minitest::Test
482
496
  end
483
497
 
484
498
  def test_enter_not_cached
499
+ WebMock.disable_net_connect!
485
500
  stub_request(:get, 'https://example.org:443/valves/result?badge=test-badge')
486
501
  .with(headers: { 'X-Zerocracy-Token' => '000' })
487
502
  .to_return(status: 204)
@@ -505,26 +520,32 @@ class TestBazaRb < Minitest::Test
505
520
  end
506
521
 
507
522
  def test_checked_with_500_error
523
+ WebMock.disable_net_connect!
508
524
  stub_request(:get, 'https://example.org:443/test')
509
525
  .with(headers: { 'X-Zerocracy-Token' => '000' })
510
526
  .to_return(status: 500)
511
527
  error =
512
528
  assert_raises(BazaRb::ServerFailure) do
513
- fake_baza.send(:checked,
514
- Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' }))
529
+ fake_baza.send(
530
+ :checked,
531
+ Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' })
532
+ )
515
533
  end
516
534
  assert_includes(error.message, 'Invalid response code #500')
517
535
  assert_includes(error.message, "most probably it's an internal error on the server")
518
536
  end
519
537
 
520
538
  def test_checked_with_503_error
539
+ WebMock.disable_net_connect!
521
540
  stub_request(:get, 'https://example.org:443/test')
522
541
  .with(headers: { 'X-Zerocracy-Token' => '000' })
523
542
  .to_return(status: 503, headers: { 'X-Zerocracy-Failure' => 'Service unavailable' })
524
543
  error =
525
544
  assert_raises(BazaRb::ServerFailure) do
526
- fake_baza.send(:checked,
527
- Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' }))
545
+ fake_baza.send(
546
+ :checked,
547
+ Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' })
548
+ )
528
549
  end
529
550
  assert_includes(error.message, 'Invalid response code #503')
530
551
  assert_includes(error.message, "most probably it's an internal error on the server")
@@ -532,32 +553,39 @@ class TestBazaRb < Minitest::Test
532
553
  end
533
554
 
534
555
  def test_checked_with_404_error
556
+ WebMock.disable_net_connect!
535
557
  stub_request(:get, 'https://example.org:443/test')
536
558
  .with(headers: { 'X-Zerocracy-Token' => '000' })
537
559
  .to_return(status: 404)
538
560
  error =
539
561
  assert_raises(BazaRb::ServerFailure) do
540
- fake_baza.send(:checked,
541
- Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' }))
562
+ fake_baza.send(
563
+ :checked,
564
+ Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' })
565
+ )
542
566
  end
543
567
  assert_includes(error.message, 'Invalid response code #404')
544
568
  assert_includes(error.message, 'most probably you are trying to reach a wrong server')
545
569
  end
546
570
 
547
571
  def test_checked_with_0_error
572
+ WebMock.disable_net_connect!
548
573
  stub_request(:get, 'https://example.org:443/test')
549
574
  .with(headers: { 'X-Zerocracy-Token' => '000' })
550
575
  .to_return(status: 0)
551
576
  error =
552
577
  assert_raises(BazaRb::ServerFailure) do
553
- fake_baza.send(:checked,
554
- Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' }))
578
+ fake_baza.send(
579
+ :checked,
580
+ Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' })
581
+ )
555
582
  end
556
583
  assert_includes(error.message, 'Invalid response code #0')
557
- assert_includes(error.message, 'most likely an internal error')
584
+ assert_includes(error.message, 'most likely a connection failure')
558
585
  end
559
586
 
560
587
  def test_push_without_compression
588
+ WebMock.disable_net_connect!
561
589
  baza = BazaRb.new('example.org', 443, '000', loog: Loog::NULL, compress: false)
562
590
  stub_request(:put, 'https://example.org:443/push/test')
563
591
  .with(
@@ -578,7 +606,6 @@ class TestBazaRb < Minitest::Test
578
606
  def with_http_server(code, response, opts = {})
579
607
  opts = { ssl: false, timeout: 1 }.merge(opts)
580
608
  WebMock.enable_net_connect!
581
- skip('We are offline') unless we_are_online
582
609
  req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
583
610
  host = '127.0.0.1'
584
611
  RandomPort::Pool::SINGLETON.acquire do |port|
@@ -587,12 +614,18 @@ class TestBazaRb < Minitest::Test
587
614
  Thread.new do
588
615
  socket = server.accept
589
616
  req.parse(socket)
590
- req.body
591
- socket.puts "HTTP/1.1 #{code} OK\r\nContent-Length: #{response.length}\r\n\r\n#{response}"
617
+ body = req.body
618
+ len = req.header['content-length'].first.to_i
619
+ if body.nil? || len == body.size
620
+ socket.puts "HTTP/1.1 #{code} OK\r\nContent-Length: #{response.length}\r\n\r\n#{response}"
621
+ else
622
+ socket.puts "HTTP/1.1 400 Bad Request\r\n"
623
+ end
592
624
  socket.close
593
625
  end
594
626
  yield BazaRb.new(host, port, '0000', **opts)
595
- t.join
627
+ t.terminate
628
+ assert(t.join(1))
596
629
  end
597
630
  req
598
631
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baza.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -163,7 +163,7 @@ dependencies:
163
163
  - - "~>"
164
164
  - !ruby/object:Gem::Version
165
165
  version: '1.3'
166
- description: It is a Ruby client for Zerocracy API, allowing you to check your jobs
166
+ description: It is a Ruby client for Zerocracy API, allowing you to check your job
167
167
  statuses, upload and download binaries, lock/unlock them, manage durables, and do
168
168
  everything else that is possible to do via the HTTP API.
169
169
  email: yegor256@gmail.com