zold 0.11.10 → 0.11.11

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
  SHA1:
3
- metadata.gz: 7ca413080aece7a7df0ad64a62f79d05a374b7a1
4
- data.tar.gz: 59a587c153a051be1245f8403d85807638afbef9
3
+ metadata.gz: 8166417b26ad8c5745a7c83ddec0f463bc641d1e
4
+ data.tar.gz: 8d8747d23ab292070a3fd1d5b86efd3fa27bb4ad
5
5
  SHA512:
6
- metadata.gz: 5d34fdc3e75b98dc53cd34323278911fc8f7a1c0a49c5a9fe46fb12785f8ca7d65ff7a69023067a185afe1a249a6f9951103c054e6f214150972756b3c9dd528
7
- data.tar.gz: a9e5f068362f53f591305c90931dba01842644c6a6b369433fa6c2a44b53887ab24de6d44a2c4c51a4d89badb32506a821ab63246b03f5f325b30e2cf5533407
6
+ metadata.gz: b86e8bcb2f3f79e072f6c33b769089c1711ce8d4ef6cfb855c88b5a130964146d5a5e5a184d604ead24d2fee82a2cc6c519a0c0ce09e403b3802edc23b15ec8a
7
+ data.tar.gz: 41bc7348572a88dcf9d7951f9f8f21ad9b54f35cd3430df64587e2e50567b124fae6719e96aaf17608efb29af4a88a8552dd2143fd29a2c99975cb2b87059fbc
@@ -19,6 +19,7 @@
19
19
  # SOFTWARE.
20
20
 
21
21
  require 'rainbow'
22
+ require 'uri'
22
23
  require 'net/http'
23
24
  require_relative 'version'
24
25
  require_relative 'score'
@@ -41,7 +42,9 @@ module Zold
41
42
  VERSION_HEADER = 'X-Zold-Version'.freeze
42
43
 
43
44
  def initialize(uri, score = Score::ZERO)
44
- @uri = uri
45
+ raise 'URI can\'t be nil' if uri.nil?
46
+ @uri = uri.is_a?(String) ? URI(uri) : uri
47
+ raise 'Score can\'t be nil' if score.nil?
45
48
  @score = score
46
49
  end
47
50
 
@@ -128,8 +128,10 @@ and modified nothing (this is most likely a bug!)")
128
128
  ).run(['merge', id.to_s])
129
129
  Clean.new(wallets: @wallets, copies: copies.root, log: @log).run(['clean', id.to_s])
130
130
  copies.remove(localhost, Remotes::PORT)
131
- @push_mutex.synchronize { @modified += modified }
132
- @pushes.post { push_one } if @pushes.length < 2
131
+ unless modified.empty?
132
+ @push_mutex.synchronize { @modified += modified }
133
+ @pushes.post { push_one } if @pushes.length < 2
134
+ end
133
135
  modified
134
136
  end
135
137
 
@@ -115,6 +115,7 @@ module Zold
115
115
  .split(/\n/)
116
116
  .map { |t| Score.parse(t) }
117
117
  .reject(&:expired?)
118
+ .select(&:valid?)
118
119
  .sort_by(&:value)
119
120
  .reverse
120
121
  .take(max)
@@ -147,12 +147,14 @@ module Zold
147
147
  id = Id.new(params[:id])
148
148
  wallet = settings.wallets.find(id)
149
149
  request.body.rewind
150
- body = request.body.read
151
- if wallet.exists? && AtomicFile.new(wallet.path).read == body
150
+ after = request.body.read
151
+ before = wallet.exists? ? AtomicFile.new(wallet.path).read : ''
152
+ if before == after
152
153
  status 304
153
154
  return
154
155
  end
155
- settings.entrance.push(id, body, sync: !params[:sync].nil?)
156
+ settings.log.info("Wallet #{id} is new: #{before.length}b != #{after.length}b")
157
+ settings.entrance.push(id, after, sync: !params[:sync].nil?)
156
158
  JSON.pretty_generate(
157
159
  version: VERSION,
158
160
  score: score.to_h
@@ -61,8 +61,7 @@ module Zold
61
61
  end
62
62
 
63
63
  def http(path = '/')
64
- uri = URI("http://#{@host}:#{@port}#{path}")
65
- Http.new(uri, @score)
64
+ Http.new("http://#{@host}:#{@port}#{path}", @score)
66
65
  end
67
66
 
68
67
  def to_s
@@ -23,5 +23,5 @@
23
23
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Zold
26
- VERSION = '0.11.10'.freeze
26
+ VERSION = '0.11.11'.freeze
27
27
  end
@@ -56,7 +56,7 @@ class FakeNode
56
56
  )
57
57
  end
58
58
  end
59
- home = URI("http://localhost:#{port}/")
59
+ home = "http://localhost:#{port}/"
60
60
  while Zold::Http.new(home).get.code == '599' && node.alive?
61
61
  sleep 1
62
62
  @log.debug("Waiting for #{home}...")
@@ -22,6 +22,7 @@ require 'minitest/autorun'
22
22
  require 'json'
23
23
  require_relative '../test__helper'
24
24
  require_relative 'fake_node'
25
+ require_relative '../fake_home'
25
26
  require_relative '../../lib/zold/http'
26
27
  require_relative '../../lib/zold/score'
27
28
 
@@ -50,14 +51,20 @@ class FrontTest < Minitest::Test
50
51
  )
51
52
  end
52
53
  end
53
- score = Zold::Score.new(
54
- Time.now, 'localhost', 999,
55
- 'NOPREFIX@ffffffffffffffff',
56
- strength: 1
57
- ).next.next.next.next
58
- Zold::Http.new(URI("http://localhost:#{port}/"), score).get
59
- json = JSON.parse(Zold::Http.new(URI("http://localhost:#{port}/remotes"), score).get.body)
60
- assert(json['all'].find { |r| r['host'] == 'localhost' })
54
+ end
55
+ end
56
+
57
+ def test_pushes_twice
58
+ FakeNode.new(log: test_log).run do |port|
59
+ FakeHome.new.run do |home|
60
+ wallet = home.create_wallet
61
+ response = Zold::Http.new("http://localhost:#{port}/wallet/#{wallet.id}?sync=true").put(File.read(wallet.path))
62
+ assert_equal('200', response.code, response.body)
63
+ 3.times do
64
+ r = Zold::Http.new("http://localhost:#{port}/wallet/#{wallet.id}?sync=true").put(File.read(wallet.path))
65
+ assert_equal('304', r.code, r.body)
66
+ end
67
+ end
61
68
  end
62
69
  end
63
70
 
@@ -31,21 +31,21 @@ require_relative '../lib/zold/http'
31
31
  class TestHttp < Minitest::Test
32
32
  def test_pings_broken_uri
33
33
  stub_request(:get, 'http://bad-host/').to_return(status: 500)
34
- res = Zold::Http.new(URI('http://bad-host/')).get
34
+ res = Zold::Http.new('http://bad-host/').get
35
35
  assert_equal('500', res.code)
36
36
  assert_equal('', res.body)
37
37
  end
38
38
 
39
39
  def test_pings_with_exception
40
40
  stub_request(:get, 'http://exception/').to_return { raise 'Intentionally' }
41
- res = Zold::Http.new(URI('http://exception/')).get
41
+ res = Zold::Http.new('http://exception/').get
42
42
  assert_equal('599', res.code)
43
43
  assert(res.body.include?('Intentionally'))
44
44
  end
45
45
 
46
46
  def test_pings_live_uri
47
47
  stub_request(:get, 'http://good-host/').to_return(status: 200)
48
- res = Zold::Http.new(URI('http://good-host/')).get
48
+ res = Zold::Http.new('http://good-host/').get
49
49
  assert_equal('200', res.code)
50
50
  end
51
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.10
4
+ version: 0.11.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko