zold 0.11.10 → 0.11.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zold/http.rb +4 -1
- data/lib/zold/node/entrance.rb +4 -2
- data/lib/zold/node/farm.rb +1 -0
- data/lib/zold/node/front.rb +5 -3
- data/lib/zold/remotes.rb +1 -2
- data/lib/zold/version.rb +1 -1
- data/test/node/fake_node.rb +1 -1
- data/test/node/test_front.rb +15 -8
- data/test/test_http.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8166417b26ad8c5745a7c83ddec0f463bc641d1e
|
4
|
+
data.tar.gz: 8d8747d23ab292070a3fd1d5b86efd3fa27bb4ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b86e8bcb2f3f79e072f6c33b769089c1711ce8d4ef6cfb855c88b5a130964146d5a5e5a184d604ead24d2fee82a2cc6c519a0c0ce09e403b3802edc23b15ec8a
|
7
|
+
data.tar.gz: 41bc7348572a88dcf9d7951f9f8f21ad9b54f35cd3430df64587e2e50567b124fae6719e96aaf17608efb29af4a88a8552dd2143fd29a2c99975cb2b87059fbc
|
data/lib/zold/http.rb
CHANGED
@@ -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
|
-
|
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
|
|
data/lib/zold/node/entrance.rb
CHANGED
@@ -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
|
-
|
132
|
-
|
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
|
|
data/lib/zold/node/farm.rb
CHANGED
data/lib/zold/node/front.rb
CHANGED
@@ -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
|
-
|
151
|
-
|
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.
|
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
|
data/lib/zold/remotes.rb
CHANGED
data/lib/zold/version.rb
CHANGED
data/test/node/fake_node.rb
CHANGED
data/test/node/test_front.rb
CHANGED
@@ -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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
|
data/test/test_http.rb
CHANGED
@@ -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(
|
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(
|
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(
|
48
|
+
res = Zold::Http.new('http://good-host/').get
|
49
49
|
assert_equal('200', res.code)
|
50
50
|
end
|
51
51
|
end
|