zold 0.11.5 → 0.11.6

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: 6c22d25b0575aa403b58457dc738b232a14e40c8
4
- data.tar.gz: 40726c037b816bd370b41b2cd46c1dfd23d834d7
3
+ metadata.gz: d4b85a4409d351be25bfa99d529cb7805474c413
4
+ data.tar.gz: 17c7832d676da4213cccf791dc38a175d2a45667
5
5
  SHA512:
6
- metadata.gz: cdbfb12a088dbfc45ea613d5274c7bf1baf64d1864f939264bdd832cceb0c41988ba003fd27b3819a55a71ed4a599c847f65b676cc8e1052a6e27431cd053aa7
7
- data.tar.gz: 2ea2de44216e0ef5f69f27b1c065fd2ec4570c0488a76d567572403cb284a72e72a872cccc4906e2528fc211e400143c9e04e94d973882be4d7c30a4223c3c67
6
+ metadata.gz: 214f26718d2dcf269e355bb574edb51c4b2d15dc6b0679ef8a721e77595751b551d4e48c3fe83d65889b612453a2a7e7cea45be8a22f063629ffa33ab663d0dc
7
+ data.tar.gz: f488b84aa410a24cf9c73e3acfebe7943378889a183fa923937856bbdb8ee27ec11e8bdd3a00cc75bbf4ad5b5cbe431abeb3ea291581161a0bff63abb3b0a0f8
@@ -23,6 +23,7 @@ done
23
23
 
24
24
  zold remote clean
25
25
  zold remote add localhost ${port}
26
+ zold remote trim
26
27
  zold remote show
27
28
 
28
29
  zold --public-key=id_rsa.pub create 0000000000000000
@@ -77,7 +77,7 @@ Available options:"
77
77
  def fetch_one(id, r, cps, opts)
78
78
  start = Time.now
79
79
  if opts['ignore-node'].include?(r.to_s)
80
- @log.info("#{r} ignored because of --ignore-node")
80
+ @log.debug("#{r} ignored because of --ignore-node")
81
81
  return false
82
82
  end
83
83
  res = r.http("/wallet/#{id}").get
@@ -92,7 +92,7 @@ Available options:"
92
92
  File.write(f, body)
93
93
  wallet = Wallet.new(f.path)
94
94
  cps.add(body, score.host, score.port, score.value)
95
- @log.info("#{r} returned #{body.length}b/#{wallet.txns.count} \
95
+ @log.info("#{r} returned #{body.length}b/#{wallet.txns.count}t \
96
96
  of #{id} in #{(Time.now - start).round(2)}s: #{Rainbow(score.value).green} (#{json['version']})")
97
97
  end
98
98
  end
@@ -119,11 +119,12 @@ module Zold
119
119
  )
120
120
  Front.set(:farm, farm)
121
121
  update = Thread.start do
122
- VerboseThread.new(@log).run do
122
+ VerboseThread.new(@log).run(true) do
123
123
  loop do
124
124
  sleep(60)
125
125
  require_relative 'remote'
126
126
  Remote.new(remotes: remotes, log: @log, farm: farm).run(%w[remote update --reboot])
127
+ Remote.new(remotes: remotes, log: @log).run(%w[remote trim])
127
128
  @log.debug('Regular update of remote nodes succeeded')
128
129
  end
129
130
  end
@@ -73,7 +73,7 @@ Available options:"
73
73
 
74
74
  def push_one(wallet, r, opts)
75
75
  if opts['ignore-node'].include?(r.to_s)
76
- @log.info("#{r} ignored because of --ignore-node")
76
+ @log.debug("#{r} ignored because of --ignore-node")
77
77
  return 0
78
78
  end
79
79
  start = Time.now
@@ -84,11 +84,11 @@ Available options:"
84
84
  return 0
85
85
  end
86
86
  r.assert_code(200, response)
87
- json = JSON.parse(response.body)['score']
88
- score = Score.parse_json(json)
87
+ json = JSON.parse(response.body)
88
+ score = Score.parse_json(json['score'])
89
89
  r.assert_valid_score(score)
90
90
  raise "Score is too weak #{score}" if score.strength < Score::STRENGTH
91
- @log.info("#{r} accepted #{content.length}b/#{wallet.txns.count}txns of #{wallet.id} \
91
+ @log.info("#{r} accepted #{content.length}b/#{wallet.txns.count}t of #{wallet.id} \
92
92
  in #{(Time.now - start).round(2)}s: #{Rainbow(score.value).green} (#{json['version']})")
93
93
  score.value
94
94
  end
@@ -58,6 +58,8 @@ Available commands:
58
58
  Add a new remote node
59
59
  #{Rainbow('remote remove').green} host [port]
60
60
  Remove the remote node
61
+ #{Rainbow('remote trim').green}
62
+ Remote the least reliable nodes
61
63
  #{Rainbow('remote update').green}
62
64
  Check each registered remote node for availability
63
65
  Available options:"
@@ -86,6 +88,8 @@ Available options:"
86
88
  add(mine[1], mine[2] ? mine[2].to_i : Remotes::PORT, opts)
87
89
  when 'remove'
88
90
  remove(mine[1], mine[2] ? mine[2].to_i : Remotes::PORT, opts)
91
+ when 'trim'
92
+ trim(opts)
89
93
  when 'update'
90
94
  update(opts)
91
95
  update(opts, false)
@@ -135,6 +139,12 @@ Available options:"
135
139
  @log.info("There are #{@remotes.all.count} remote nodes in the list")
136
140
  end
137
141
 
142
+ def trim(opts)
143
+ @remotes.all.each do |r|
144
+ remove(r[:host], r[:port], opts) if r[:errors] > 20
145
+ end
146
+ end
147
+
138
148
  def update(opts, deep = true)
139
149
  capacity = []
140
150
  @remotes.iterate(@log, farm: @farm) do |r|
data/lib/zold/http.rb CHANGED
@@ -57,7 +57,7 @@ module Zold
57
57
 
58
58
  def put(body)
59
59
  http = Net::HTTP.new(@uri.host, @uri.port)
60
- http.read_timeout = 60
60
+ http.read_timeout = 10
61
61
  path = @uri.path
62
62
  path += '?' + @uri.query if @uri.query
63
63
  http.request_put(
@@ -44,7 +44,7 @@ module Zold
44
44
  @address = address
45
45
  @log = log
46
46
  @semaphores = Concurrent::Map.new
47
- @pool = Concurrent::FixedThreadPool.new(16)
47
+ @pool = Concurrent::FixedThreadPool.new(16, max_queue: 64, fallback_policy: :abort)
48
48
  end
49
49
 
50
50
  def push(id, body, sync: true)
@@ -78,8 +78,9 @@ module Zold
78
78
  def push_sync(id, body)
79
79
  @semaphores.put_if_absent(id, Mutex.new)
80
80
  @semaphores.get(id).synchronize do
81
+ start = Time.now
81
82
  modified = push_unsafe(id, body)
82
- @log.info("Accepted #{id} and modified: #{modified.join(', ')}")
83
+ @log.info("Accepted #{id} in #{(Time.now - start) / 60}s and modified #{modified.join(', ')}")
83
84
  modified
84
85
  end
85
86
  end
@@ -58,10 +58,11 @@ module Zold
58
58
 
59
59
  def start(host, port, strength: 8, threads: 8)
60
60
  @log.debug('Zero-threads farm won\'t score anything!') if threads.zero?
61
- @best << Score.new(Time.now, host, port, @invoice, strength: strength)
62
61
  @scores = Queue.new
63
- history.each { |s| @scores << s }
64
- @log.debug("#{@scores.size} scores pre-loaded") unless @scores.size.zero?
62
+ h = history(threads)
63
+ h.each { |s| @scores << s }
64
+ @best << (h[0] || Score.new(Time.now, host, port, @invoice, strength: strength))
65
+ @log.info("#{@scores.size} scores pre-loaded, the best is: #{@best[0]}")
65
66
  @threads = (1..threads).map do |t|
66
67
  Thread.new do
67
68
  VerboseThread.new(@log).run do
@@ -107,9 +108,14 @@ module Zold
107
108
  File.write(@cache, (history + [score]).map(&:to_s).join("\n"))
108
109
  end
109
110
 
110
- def history
111
+ def history(max = 16)
111
112
  if File.exist?(@cache)
112
- File.readlines(@cache).map { |t| Score.parse(t) }.reject(&:expired?)
113
+ File.readlines(@cache)
114
+ .map { |t| Score.parse(t) }
115
+ .reject(&:expired?)
116
+ .sort_by(&:value)
117
+ .reverse
118
+ .take(max)
113
119
  else
114
120
  []
115
121
  end
@@ -90,6 +90,10 @@ module Zold
90
90
  'User-agent: *'
91
91
  end
92
92
 
93
+ get '/v' do
94
+ VERSION
95
+ end
96
+
93
97
  get '/favicon.ico' do
94
98
  if score.value >= 16
95
99
  redirect 'https://www.zold.io/images/logo-green.png'
@@ -108,7 +112,7 @@ module Zold
108
112
  pid: Process.pid,
109
113
  cpus: Concurrent.processor_count,
110
114
  uptime: `uptime`.strip,
111
- threads: Thread.list.select { |t| t.status == 'run' }.count,
115
+ threads: "#{Thread.list.select { |t| t.status == 'run' }.count}/#{Thread.list.count}",
112
116
  wallets: settings.wallets.all.count,
113
117
  remotes: settings.remotes.all.count,
114
118
  farm: settings.farm.to_json,
data/lib/zold/remotes.rb CHANGED
@@ -64,9 +64,9 @@ module Zold
64
64
  end
65
65
 
66
66
  def assert_code(code, response)
67
- @log.debug("#{response.code} \"#{response.message}\" at \"#{response.body}\"")
68
67
  msg = response.message
69
68
  return if response.code.to_i == code
69
+ @log.debug("#{response.code} \"#{response.message}\" at \"#{response.body}\"")
70
70
  raise "Unexpected HTTP code #{response.code}, instead of #{code}" if msg.empty?
71
71
  raise "#{msg} (HTTP code #{response.code}, instead of #{code})"
72
72
  end
@@ -31,11 +31,11 @@ module Zold
31
31
  @log = log
32
32
  end
33
33
 
34
- def run
34
+ def run(safe = false)
35
35
  yield
36
36
  rescue StandardError => e
37
37
  @log.error("#{e.class.name}: #{e.message} #{e.backtrace.join("\n\t")}")
38
- raise e
38
+ raise e unless safe
39
39
  end
40
40
  end
41
41
  end
data/lib/zold/version.rb CHANGED
@@ -23,5 +23,5 @@
23
23
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Zold
26
- VERSION = '0.11.5'.freeze
26
+ VERSION = '0.11.6'.freeze
27
27
  end
@@ -29,7 +29,7 @@ require_relative '../../lib/zold/commands/calculate'
29
29
  # License:: MIT
30
30
  class TestCalculate < Minitest::Test
31
31
  def test_calculates_score
32
- score = Zold::Calculate.new(log: log).run(
32
+ score = Zold::Calculate.new(log: test_log).run(
33
33
  ['score', '--strength=2', '--max=8', '--invoice=NOSUFFIX@ffffffffffffffff']
34
34
  )
35
35
  assert(score.valid?)
@@ -36,7 +36,7 @@ class TestClean < Minitest::Test
36
36
  copies = home.copies(wallet)
37
37
  copies.add('a1', 'host-1', 80, 1, Time.now - 26 * 60 * 60)
38
38
  copies.add('a2', 'host-2', 80, 2, Time.now - 26 * 60 * 60)
39
- Zold::Clean.new(wallets: home.wallets, copies: copies.root, log: log).run(['clean', wallet.id.to_s])
39
+ Zold::Clean.new(wallets: home.wallets, copies: copies.root, log: test_log).run(['clean', wallet.id.to_s])
40
40
  assert(copies.all.empty?)
41
41
  end
42
42
  end
@@ -32,7 +32,7 @@ require_relative '../../lib/zold/commands/create'
32
32
  class TestCreate < Minitest::Test
33
33
  def test_creates_wallet
34
34
  Dir.mktmpdir 'test' do |dir|
35
- wallet = Zold::Create.new(wallets: Zold::Wallets.new(dir), log: log).run(
35
+ wallet = Zold::Create.new(wallets: Zold::Wallets.new(dir), log: test_log).run(
36
36
  ['create', '--public-key=fixtures/id_rsa.pub']
37
37
  )
38
38
  assert wallet.balance.zero?
@@ -44,13 +44,13 @@ class TestDiff < Minitest::Test
44
44
  File.write(first.path, File.read(wallet.path))
45
45
  second = home.create_wallet
46
46
  File.write(second.path, File.read(wallet.path))
47
- Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: log).run(
47
+ Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
48
48
  ['pay', wallet.id.to_s, second.id.to_s, '14.95', '--force', '--private-key=fixtures/id_rsa']
49
49
  )
50
50
  copies = home.copies(wallet)
51
51
  copies.add(File.read(first.path), 'host-1', 80, 5)
52
52
  copies.add(File.read(second.path), 'host-2', 80, 5)
53
- diff = Zold::Diff.new(wallets: home.wallets, copies: copies.root, log: log).run(
53
+ diff = Zold::Diff.new(wallets: home.wallets, copies: copies.root, log: test_log).run(
54
54
  ['diff', wallet.id.to_s]
55
55
  )
56
56
  assert(diff.include?('-0001;'))
@@ -59,7 +59,7 @@ class TestFetch < Minitest::Test
59
59
  remotes.add('fake-1', 80)
60
60
  remotes.add('fake-2', 80)
61
61
  copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
62
- Zold::Fetch.new(wallets: wallets, copies: copies.root, remotes: remotes, log: log).run(
62
+ Zold::Fetch.new(wallets: wallets, copies: copies.root, remotes: remotes, log: test_log).run(
63
63
  ['fetch', '--ignore-score-weakness', id.to_s]
64
64
  )
65
65
  assert_equal(copies.all[0][:name], '1')
@@ -83,7 +83,7 @@ class TestFetch < Minitest::Test
83
83
  remotes.add('fake-1', 80)
84
84
  copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
85
85
  Zold::Fetch.new(
86
- wallets: wallets, copies: copies.root, remotes: remotes, log: log
86
+ wallets: wallets, copies: copies.root, remotes: remotes, log: test_log
87
87
  ).run(['fetch', id.to_s])
88
88
  assert_equal(copies.all[0][:name], '1')
89
89
  assert_equal(copies.all[0][:score], 0)
@@ -38,7 +38,7 @@ class TestInvoice < Minitest::Test
38
38
  wallets = Zold::Wallets.new(dir)
39
39
  source = wallets.find(id)
40
40
  source.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
41
- invoice = Zold::Invoice.new(wallets: wallets, log: log).run(
41
+ invoice = Zold::Invoice.new(wallets: wallets, log: test_log).run(
42
42
  ['invoice', id.to_s, '--length=16']
43
43
  )
44
44
  assert_equal(33, invoice.length)
@@ -37,7 +37,7 @@ class TestList < Minitest::Test
37
37
  wallets = Zold::Wallets.new(dir)
38
38
  wallet = wallets.find(id)
39
39
  wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
40
- Zold::List.new(wallets: wallets, log: log).run
40
+ Zold::List.new(wallets: wallets, log: test_log).run
41
41
  end
42
42
  end
43
43
  end
@@ -45,13 +45,13 @@ class TestMerge < Minitest::Test
45
45
  File.write(first.path, File.read(wallet.path))
46
46
  second = home.create_wallet
47
47
  File.write(second.path, File.read(wallet.path))
48
- Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: log).run(
48
+ Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
49
49
  ['pay', wallet.id.to_s, second.id.to_s, '14.95', '--force', '--private-key=fixtures/id_rsa']
50
50
  )
51
51
  copies = home.copies(wallet)
52
52
  copies.add(File.read(first.path), 'host-1', 80, 5)
53
53
  copies.add(File.read(second.path), 'host-2', 80, 5)
54
- modified = Zold::Merge.new(wallets: home.wallets, copies: copies.root, log: log).run(
54
+ modified = Zold::Merge.new(wallets: home.wallets, copies: copies.root, log: test_log).run(
55
55
  ['merge', wallet.id.to_s]
56
56
  )
57
57
  assert(1, modified.count)
@@ -66,13 +66,13 @@ class TestMerge < Minitest::Test
66
66
  File.write(first.path, File.read(wallet.path))
67
67
  second = home.create_wallet
68
68
  File.write(second.path, File.read(wallet.path))
69
- Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: log).run(
69
+ Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
70
70
  ['pay', wallet.id.to_s, second.id.to_s, '14.95', '--force', '--private-key=fixtures/id_rsa']
71
71
  )
72
72
  copies = home.copies(wallet)
73
73
  copies.add(File.read(first.path), 'host-1', 80, 5)
74
74
  copies.add(File.read(second.path), 'host-2', 80, 5)
75
- modified = Zold::Merge.new(wallets: home.wallets, copies: copies.root, log: log).run(
75
+ modified = Zold::Merge.new(wallets: home.wallets, copies: copies.root, log: test_log).run(
76
76
  ['merge', wallet.id.to_s]
77
77
  )
78
78
  assert(1, modified.count)
@@ -38,7 +38,7 @@ require_relative '../node/fake_node'
38
38
  # License:: MIT
39
39
  class TestNode < Minitest::Test
40
40
  def test_push_and_fetch
41
- FakeNode.new(log: log).run do |port|
41
+ FakeNode.new(log: test_log).run do |port|
42
42
  Dir.mktmpdir 'test' do |dir|
43
43
  id = Zold::Id.new
44
44
  wallets = Zold::Wallets.new(dir)
@@ -47,10 +47,10 @@ class TestNode < Minitest::Test
47
47
  remotes = Zold::Remotes.new(File.join(dir, 'remotes.csv'))
48
48
  remotes.clean
49
49
  remotes.add('localhost', port)
50
- Zold::Push.new(wallets: wallets, remotes: remotes, log: log).run(['push', '--sync'])
50
+ Zold::Push.new(wallets: wallets, remotes: remotes, log: test_log).run(['push', '--sync'])
51
51
  Zold::Fetch.new(
52
52
  wallets: wallets, copies: File.join(dir, 'copies'),
53
- remotes: remotes, log: log
53
+ remotes: remotes, log: test_log
54
54
  ).run(['fetch'])
55
55
  copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
56
56
  assert_equal(1, copies.all.count)
@@ -37,7 +37,7 @@ class TestPay < Minitest::Test
37
37
  source = home.create_wallet
38
38
  target = home.create_wallet
39
39
  amount = Zold::Amount.new(zld: 14.95)
40
- Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: log).run(
40
+ Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
41
41
  [
42
42
  'pay', '--force', '--private-key=fixtures/id_rsa',
43
43
  source.id.to_s, target.id.to_s, amount.to_zld, 'For the car'
@@ -52,7 +52,7 @@ class TestPay < Minitest::Test
52
52
  source = home.create_wallet(Zold::Id::ROOT)
53
53
  target = home.create_wallet
54
54
  amount = Zold::Amount.new(zld: 14.95)
55
- Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: log).run(
55
+ Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
56
56
  [
57
57
  'pay', '--private-key=fixtures/id_rsa',
58
58
  source.id.to_s, target.id.to_s, amount.to_zld, 'For the car'
@@ -73,7 +73,7 @@ class TestPay < Minitest::Test
73
73
  'NOPREFIX', Zold::Id.new, '-'
74
74
  )
75
75
  )
76
- Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: log).run(
76
+ Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
77
77
  [
78
78
  'pay', '--private-key=fixtures/id_rsa',
79
79
  source.id.to_s, target.id.to_s, amount.to_zld, 'here is the refund'
@@ -38,7 +38,7 @@ class TestPush < Minitest::Test
38
38
  FakeHome.new.run do |home|
39
39
  wallet = home.create_wallet
40
40
  stub_request(:put, "http://fake-1/wallet/#{wallet.id}").to_return(status: 304)
41
- Zold::Push.new(wallets: home.wallets, remotes: home.remotes, log: log).run(
41
+ Zold::Push.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
42
42
  ['--ignore-this-stupid-option', 'push', wallet.id.to_s]
43
43
  )
44
44
  end
@@ -59,7 +59,7 @@ class TestRemote < Minitest::Test
59
59
  stub_request(:get, 'http://localhost:999/remotes').to_return(
60
60
  status: 404
61
61
  )
62
- cmd = Zold::Remote.new(remotes: remotes, log: log)
62
+ cmd = Zold::Remote.new(remotes: remotes, log: test_log)
63
63
  cmd.run(%w[remote clean])
64
64
  cmd.run(['remote', 'add', zero.host, zero.port.to_s])
65
65
  cmd.run(%w[remote add localhost 2])
@@ -38,7 +38,7 @@ class TestShow < Minitest::Test
38
38
  wallets = Zold::Wallets.new(dir)
39
39
  wallet = wallets.find(id)
40
40
  wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
41
- balance = Zold::Show.new(wallets: wallets, log: log).run(['show', id.to_s])
41
+ balance = Zold::Show.new(wallets: wallets, log: test_log).run(['show', id.to_s])
42
42
  assert_equal(Zold::Amount::ZERO, balance)
43
43
  end
44
44
  end
@@ -59,7 +59,7 @@ class TestTaxes < Minitest::Test
59
59
  }.to_json
60
60
  )
61
61
  Zold::Taxes.new(
62
- wallets: wallets, remotes: remotes, log: log
62
+ wallets: wallets, remotes: remotes, log: test_log
63
63
  ).run(['taxes', '--private-key=fixtures/id_rsa', id.to_s])
64
64
  assert_equal(Zold::Amount.new(coins: 85_856_396_247), wallet.balance)
65
65
  end
@@ -36,7 +36,7 @@ class EmissionTest < Minitest::Test
36
36
  'NOPREFIX', Zold::Id::ROOT, '-'
37
37
  )
38
38
  )
39
- log.info("Year: #{year}, Quota: #{(Zold::Emission.new(wallet).quota * 100).round(2)}%, \
39
+ test_log.info("Year: #{year}, Quota: #{(Zold::Emission.new(wallet).quota * 100).round(2)}%, \
40
40
  Limit: #{Zold::Emission.new(wallet).limit}")
41
41
  end
42
42
  end
@@ -40,7 +40,7 @@ class TestEntrance < Minitest::Test
40
40
  body = FakeHome.new.run do |home|
41
41
  source = home.create_wallet(sid)
42
42
  target = home.create_wallet(tid)
43
- Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: log).run(
43
+ Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
44
44
  [
45
45
  'pay', '--force', '--private-key=fixtures/id_rsa',
46
46
  source.id.to_s, target.id.to_s, '19.99', 'testing'
@@ -51,7 +51,7 @@ class TestEntrance < Minitest::Test
51
51
  FakeHome.new.run do |home|
52
52
  source = home.create_wallet(sid)
53
53
  home.create_wallet(tid)
54
- modified = Zold::Entrance.new(home.wallets, home.remotes, home.copies(source).root, 'x', log: log).push(
54
+ modified = Zold::Entrance.new(home.wallets, home.remotes, home.copies(source).root, 'x', log: test_log).push(
55
55
  source.id, body
56
56
  )
57
57
  assert_equal(2, modified.count)
@@ -28,7 +28,7 @@ require_relative '../../lib/zold/node/farm'
28
28
  class FarmTest < Minitest::Test
29
29
  def test_makes_best_score_in_background
30
30
  Dir.mktmpdir 'test' do |dir|
31
- farm = Zold::Farm.new('NOPREFIX@ffffffffffffffff', File.join(dir, 'f'), log: log)
31
+ farm = Zold::Farm.new('NOPREFIX@ffffffffffffffff', File.join(dir, 'f'), log: test_log)
32
32
  farm.start('localhost', 80, threads: 4, strength: 2)
33
33
  sleep 0.1 while farm.best.empty? || farm.best[0].value.zero?
34
34
  assert(farm.best[0].value > 0)
@@ -38,7 +38,20 @@ class FarmTest < Minitest::Test
38
38
 
39
39
  def test_correct_score_from_empty_farm
40
40
  Dir.mktmpdir 'test' do |dir|
41
- farm = Zold::Farm.new('NOPREFIX@cccccccccccccccc', File.join(dir, 'f'), log: log)
41
+ farm = Zold::Farm.new('NOPREFIX@cccccccccccccccc', File.join(dir, 'f'), log: test_log)
42
+ farm.start('example.com', 8080, threads: 0, strength: 1)
43
+ score = farm.best[0]
44
+ assert_equal(0, score.value)
45
+ assert_equal('example.com', score.host)
46
+ assert_equal(8080, score.port)
47
+ farm.stop
48
+ end
49
+ end
50
+
51
+ def test_pre_loads_history
52
+ Dir.mktmpdir 'test' do |dir|
53
+ cache = File.join(dir, 'cache')
54
+ farm = Zold::Farm.new('NOPREFIX@cccccccccccccccc', cache, log: test_log)
42
55
  farm.start('example.com', 8080, threads: 0, strength: 1)
43
56
  score = farm.best[0]
44
57
  assert_equal(0, score.value)
@@ -27,12 +27,13 @@ require_relative '../../lib/zold/score'
27
27
 
28
28
  class FrontTest < Minitest::Test
29
29
  def test_renders_public_pages
30
- FakeNode.new(log: log).run(['--ignore-score-weakness']) do |port|
30
+ FakeNode.new(log: test_log).run(['--ignore-score-weakness']) do |port|
31
31
  {
32
32
  '200' => [
33
33
  '/robots.txt',
34
34
  '/',
35
- '/remotes'
35
+ '/remotes',
36
+ '/v'
36
37
  ],
37
38
  '404' => [
38
39
  '/this-is-absent',
@@ -65,7 +66,7 @@ class FrontTest < Minitest::Test
65
66
  '4' => 'https://www.zold.io/images/logo-orange.png',
66
67
  '16' => 'https://www.zold.io/images/logo-green.png'
67
68
  }.each do |num, path|
68
- log.info("Calculating score #{num}...")
69
+ test_log.info("Calculating score #{num}...")
69
70
  score = Zold::Score.new(
70
71
  Time.now, 'localhost', 999,
71
72
  'NOPREFIX@ffffffffffffffff',
@@ -74,7 +75,7 @@ class FrontTest < Minitest::Test
74
75
  num.to_i.times do
75
76
  score = score.next
76
77
  end
77
- log.info("Score #{num} calculated.")
78
+ test_log.info("Score #{num} calculated.")
78
79
  if score.value >= 16
79
80
  assert_equal(
80
81
  path, 'https://www.zold.io/images/logo-green.png',
data/test/test__helper.rb CHANGED
@@ -29,18 +29,18 @@ if ENV['CI'] == 'true'
29
29
  SimpleCov.formatter = SimpleCov::Formatter::Codecov
30
30
  end
31
31
 
32
- require_relative '../lib/zold/log'
33
-
34
32
  require 'minitest/autorun'
35
33
  require_relative '../lib/zold'
36
34
 
37
35
  gem 'openssl'
38
36
  require 'openssl'
39
37
 
40
- require_relative 'support/logs'
41
-
42
38
  module Minitest
43
39
  class Test
44
- include Logs
40
+ def test_log
41
+ require_relative '../lib/zold/log'
42
+ # @test_log = Zold::Log::Quiet.new
43
+ @test_log ||= Zold::Log::Verbose.new
44
+ end
45
45
  end
46
46
  end
data/test/test_zold.rb CHANGED
@@ -38,7 +38,7 @@ class TestZold < Minitest::Test
38
38
  bin = File.join(Dir.pwd, 'bin/zold')
39
39
  Dir.chdir(dir) do
40
40
  stdout = `/bin/bash #{f} #{bin} 2>&1`
41
- log.info(stdout)
41
+ test_log.info(stdout)
42
42
  assert_equal(0, $CHILD_STATUS.exitstatus)
43
43
  end
44
44
  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.5
4
+ version: 0.11.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -379,7 +379,6 @@ files:
379
379
  - test/node/test_entrance.rb
380
380
  - test/node/test_farm.rb
381
381
  - test/node/test_front.rb
382
- - test/support/logs.rb
383
382
  - test/test__helper.rb
384
383
  - test/test_amount.rb
385
384
  - test/test_copies.rb
@@ -449,7 +448,6 @@ test_files:
449
448
  - test/node/test_entrance.rb
450
449
  - test/node/test_farm.rb
451
450
  - test/node/test_front.rb
452
- - test/support/logs.rb
453
451
  - test/test__helper.rb
454
452
  - test/test_amount.rb
455
453
  - test/test_copies.rb
data/test/support/logs.rb DELETED
@@ -1,6 +0,0 @@
1
- module Logs
2
- def log
3
- # $log = Zold::Log::Quiet.new
4
- @log ||= Zold::Log::Verbose.new
5
- end
6
- end