zold 0.14.17 → 0.14.18

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.
@@ -74,6 +74,7 @@ class FakeNode
74
74
  @log.debug("Waiting for #{uri}...")
75
75
  sleep 1
76
76
  end
77
+ raise 'The node is dead' unless node.alive?
77
78
  begin
78
79
  yield port
79
80
  ensure
@@ -38,7 +38,7 @@ class FarmTest < Minitest::Test
38
38
  end
39
39
 
40
40
  def test_renders_in_json
41
- Dir.mktmpdir 'test' do |dir|
41
+ Dir.mktmpdir do |dir|
42
42
  farm = Zold::Farm.new('NOPREFIX@ffffffffffffffff', File.join(dir, 'f'), log: test_log)
43
43
  farm.start('localhost', 80, threads: 4, strength: 2) do
44
44
  sleep 0.1 while farm.best.empty? || farm.best[0].value.zero?
@@ -50,7 +50,7 @@ class FarmTest < Minitest::Test
50
50
  end
51
51
 
52
52
  def test_renders_in_text
53
- Dir.mktmpdir 'test' do |dir|
53
+ Dir.mktmpdir do |dir|
54
54
  farm = Zold::Farm.new('NOPREFIX@ffffffffffffffff', File.join(dir, 'f'), log: test_log)
55
55
  farm.start('localhost', 80, threads: 2, strength: 1) do
56
56
  assert(!farm.to_text.nil?)
@@ -59,19 +59,19 @@ class FarmTest < Minitest::Test
59
59
  end
60
60
 
61
61
  def test_makes_best_score_in_background
62
- Dir.mktmpdir 'test' do |dir|
62
+ Dir.mktmpdir do |dir|
63
63
  farm = Zold::Farm.new('NOPREFIX@ffffffffffffffff', File.join(dir, 'f'), log: test_log)
64
- farm.start('localhost', 80, threads: 4, strength: 2) do
65
- sleep 0.1 while farm.best.empty? || farm.best[0].value.zero?
64
+ farm.start('localhost', 80, threads: 4, strength: 3) do
65
+ sleep 0.1 while farm.best.empty? || farm.best[0].value < 3
66
66
  score = farm.best[0]
67
67
  assert(!score.expired?)
68
- assert(score.value.positive?)
68
+ assert(score.value >= 3)
69
69
  end
70
70
  end
71
71
  end
72
72
 
73
73
  def test_correct_score_from_empty_farm
74
- Dir.mktmpdir 'test' do |dir|
74
+ Dir.mktmpdir do |dir|
75
75
  farm = Zold::Farm.new('NOPREFIX@cccccccccccccccc', File.join(dir, 'f'), log: test_log)
76
76
  farm.start('example.com', 8080, threads: 0, strength: 1) do
77
77
  score = farm.best[0]
@@ -84,7 +84,7 @@ class FarmTest < Minitest::Test
84
84
  end
85
85
 
86
86
  def test_pre_loads_history
87
- Dir.mktmpdir 'test' do |dir|
87
+ Dir.mktmpdir do |dir|
88
88
  cache = File.join(dir, 'cache')
89
89
  farm = Zold::Farm.new('NOPREFIX@cccccccccccccccc', cache, log: test_log)
90
90
  farm.start('example.com', 8080, threads: 0, strength: 1) do
@@ -98,7 +98,7 @@ class FarmTest < Minitest::Test
98
98
  end
99
99
 
100
100
  def test_drops_expired_scores_from_history
101
- Dir.mktmpdir 'test' do |dir|
101
+ Dir.mktmpdir do |dir|
102
102
  cache = File.join(dir, 'cache')
103
103
  score = Zold::Score.new(
104
104
  time: Time.parse('2017-07-19T21:24:51Z'),
@@ -121,7 +121,7 @@ class FarmTest < Minitest::Test
121
121
 
122
122
  def test_garbage_farm_file
123
123
  log = SaveLastMessageLogger.new
124
- Dir.mktmpdir 'test' do |dir|
124
+ Dir.mktmpdir do |dir|
125
125
  file = File.join(dir, 'corrupted_farm')
126
126
  [
127
127
  '0/6: 2018-06-26ABCT00:32:43Z 178.128.165.12 4096 MIRhypo1@c13620484b46caa4',
@@ -35,7 +35,7 @@ require_relative '../lib/zold/verbose_thread'
35
35
  # License:: MIT
36
36
  class TestAtomicFile < Minitest::Test
37
37
  def test_writes_and_reads
38
- Dir.mktmpdir 'test' do |dir|
38
+ Dir.mktmpdir do |dir|
39
39
  file = Zold::AtomicFile.new(File.join(dir, 'test.txt'))
40
40
  ['', 'hello, dude!'].each do |t|
41
41
  file.write(t)
@@ -45,7 +45,7 @@ class TestAtomicFile < Minitest::Test
45
45
  end
46
46
 
47
47
  def test_writes_from_many_threads
48
- Dir.mktmpdir 'test' do |dir|
48
+ Dir.mktmpdir do |dir|
49
49
  file = Zold::AtomicFile.new(File.join(dir, 'a.txt'))
50
50
  threads = 10
51
51
  pool = Concurrent::FixedThreadPool.new(threads)
@@ -35,7 +35,7 @@ require_relative '../lib/zold/wallet'
35
35
  # License:: MIT
36
36
  class TestCopies < Minitest::Test
37
37
  def test_adds_and_removes_copies
38
- Dir.mktmpdir 'test' do |dir|
38
+ Dir.mktmpdir do |dir|
39
39
  copies = Zold::Copies.new(File.join(dir, 'my/a/copies'), log: test_log)
40
40
  copies.add(content('alpha'), '192.168.0.1', 80, 1)
41
41
  copies.add(content('beta'), '192.168.0.2', 80, 3)
@@ -50,14 +50,14 @@ class TestCopies < Minitest::Test
50
50
  end
51
51
 
52
52
  def test_lists_empty_dir
53
- Dir.mktmpdir 'test' do |dir|
53
+ Dir.mktmpdir do |dir|
54
54
  copies = Zold::Copies.new(File.join(dir, 'xxx'), log: test_log)
55
55
  assert(copies.all.empty?, "#{copies.all.count} is not zero")
56
56
  end
57
57
  end
58
58
 
59
59
  def test_overwrites_host
60
- Dir.mktmpdir 'test' do |dir|
60
+ Dir.mktmpdir do |dir|
61
61
  copies = Zold::Copies.new(File.join(dir, 'my/a/copies-2'), log: test_log)
62
62
  host = 'b1.zold.io'
63
63
  copies.add(content('z1'), host, 80, 5)
@@ -69,7 +69,7 @@ class TestCopies < Minitest::Test
69
69
  end
70
70
 
71
71
  def test_cleans_copies
72
- Dir.mktmpdir 'test' do |dir|
72
+ Dir.mktmpdir do |dir|
73
73
  copies = Zold::Copies.new(dir, log: test_log)
74
74
  copies.add(content('h1'), 'zold.io', 4096, 10, Time.now - 25 * 60 * 60)
75
75
  copies.add(content('h1'), 'zold.io', 4097, 20, Time.now - 26 * 60 * 60)
@@ -81,7 +81,7 @@ class TestCopies < Minitest::Test
81
81
  end
82
82
 
83
83
  def test_cleans_broken_copies
84
- Dir.mktmpdir 'test' do |dir|
84
+ Dir.mktmpdir do |dir|
85
85
  copies = Zold::Copies.new(dir, log: test_log)
86
86
  copies.add('broken wallet content', 'zold.io', 4096, 10, Time.now)
87
87
  copies.clean
@@ -90,7 +90,7 @@ class TestCopies < Minitest::Test
90
90
  end
91
91
 
92
92
  def test_ignores_garbage
93
- Dir.mktmpdir 'test' do |dir|
93
+ Dir.mktmpdir do |dir|
94
94
  copies = Zold::Copies.new(dir, log: test_log)
95
95
  copies.add(content('h1'), 'zold.io', 50, 80, Time.now - 25 * 60 * 60)
96
96
  FileUtils.mkdir(File.join(dir, '55'))
@@ -99,7 +99,7 @@ class TestCopies < Minitest::Test
99
99
  end
100
100
 
101
101
  def test_sorts_them_by_score
102
- Dir.mktmpdir 'test' do |dir|
102
+ Dir.mktmpdir do |dir|
103
103
  copies = Zold::Copies.new(dir, log: test_log)
104
104
  copies.add(content('content-1'), '1.zold.io', 80, 1)
105
105
  copies.add(content('content-2'), '2.zold.io', 80, 2)
@@ -110,7 +110,7 @@ class TestCopies < Minitest::Test
110
110
  end
111
111
 
112
112
  def test_ignores_too_old_scores
113
- Dir.mktmpdir 'test' do |dir|
113
+ Dir.mktmpdir do |dir|
114
114
  copies = Zold::Copies.new(dir, log: test_log)
115
115
  copies.add(content('h1'), 'zold.io', 50, 80, Time.now - 1000 * 60 * 60)
116
116
  assert_equal(0, copies.all[0][:score])
@@ -53,7 +53,7 @@ class TestKey < Minitest::Test
53
53
  end
54
54
 
55
55
  def test_signs_and_verifies_with_random_key
56
- Dir.mktmpdir 'test' do |dir|
56
+ Dir.mktmpdir do |dir|
57
57
  key = OpenSSL::PKey::RSA.new(2048)
58
58
  file = File.join(dir, 'temp')
59
59
  File.write(file, key.public_key.to_s)
@@ -44,17 +44,17 @@ class TestRemotes < Minitest::Test
44
44
  end
45
45
 
46
46
  def test_adds_remotes
47
- Dir.mktmpdir 'test' do |dir|
47
+ Dir.mktmpdir do |dir|
48
48
  file = File.join(dir, 'remotes')
49
49
  FileUtils.touch(file)
50
- remotes = Zold::Remotes.new(file)
50
+ remotes = Zold::Remotes.new(file: file)
51
51
  remotes.add('127.0.0.1')
52
52
  assert(1, remotes.all.count)
53
53
  end
54
54
  end
55
55
 
56
56
  def test_reads_broken_file
57
- Dir.mktmpdir 'test' do |dir|
57
+ Dir.mktmpdir do |dir|
58
58
  file = File.join(dir, 'remotes')
59
59
  [
60
60
  ',0,0,0',
@@ -63,17 +63,17 @@ class TestRemotes < Minitest::Test
63
63
  "\n\n\n\n"
64
64
  ].each do |t|
65
65
  File.write(file, t)
66
- remotes = Zold::Remotes.new(file)
66
+ remotes = Zold::Remotes.new(file: file)
67
67
  assert(remotes.all.empty?, remotes.all)
68
68
  end
69
69
  end
70
70
  end
71
71
 
72
72
  def test_iterates_and_fails
73
- Dir.mktmpdir 'test' do |dir|
73
+ Dir.mktmpdir do |dir|
74
74
  file = File.join(dir, 'remotes')
75
75
  FileUtils.touch(file)
76
- remotes = Zold::Remotes.new(file)
76
+ remotes = Zold::Remotes.new(file: file)
77
77
  ips = (0..50)
78
78
  ips.each { |i| remotes.add("0.0.0.#{i}", 9999) }
79
79
  remotes.iterate(Zold::Log::Quiet.new) { raise 'Intended' }
@@ -81,11 +81,22 @@ class TestRemotes < Minitest::Test
81
81
  end
82
82
  end
83
83
 
84
+ def test_iterates_them_all
85
+ Dir.mktmpdir do |dir|
86
+ remotes = Zold::Remotes.new(file: File.join(dir, 'rrr.csv'))
87
+ remotes.clean
88
+ 5.times { |i| remotes.add("0.0.0.#{i}", 8080) }
89
+ total = 0
90
+ remotes.iterate(test_log) { total += 1 }
91
+ assert_equal(5, total)
92
+ end
93
+ end
94
+
84
95
  def test_log_msg_of_iterates_when_fail
85
- Dir.mktmpdir 'test' do |dir|
96
+ Dir.mktmpdir do |dir|
86
97
  file = File.join(dir, 'remotes')
87
98
  FileUtils.touch(file)
88
- remotes = Zold::Remotes.new(file)
99
+ remotes = Zold::Remotes.new(file: file)
89
100
  remotes.add('0.0.0.1', 9999)
90
101
  log = TestLogger.new
91
102
  remotes.iterate(log) { raise 'Intended' }
@@ -94,22 +105,22 @@ class TestRemotes < Minitest::Test
94
105
  end
95
106
 
96
107
  def test_log_msg_of_iterates_when_take_too_long
97
- Dir.mktmpdir 'test' do |dir|
108
+ Dir.mktmpdir do |dir|
98
109
  file = File.join(dir, 'remotes')
99
110
  FileUtils.touch(file)
100
- remotes = Zold::Remotes.new(file)
111
+ remotes = Zold::Remotes.new(file: file, timeout: 1)
101
112
  remotes.add('127.0.0.1')
102
113
  log = TestLogger.new
103
- remotes.iterate(log) { sleep(17) }
114
+ remotes.iterate(log) { sleep(2) }
104
115
  assert(log.msg.include?('Took too long to execute'))
105
116
  end
106
117
  end
107
118
 
108
119
  def test_removes_remotes
109
- Dir.mktmpdir 'test' do |dir|
120
+ Dir.mktmpdir do |dir|
110
121
  file = File.join(dir, 'remotes')
111
122
  FileUtils.touch(file)
112
- remotes = Zold::Remotes.new(file)
123
+ remotes = Zold::Remotes.new(file: file)
113
124
  remotes.add('127.0.0.1')
114
125
  remotes.add('LOCALHOST', 433)
115
126
  remotes.remove('localhost', 433)
@@ -118,8 +129,8 @@ class TestRemotes < Minitest::Test
118
129
  end
119
130
 
120
131
  def test_resets_remotes
121
- Dir.mktmpdir 'test' do |dir|
122
- remotes = Zold::Remotes.new(File.join(dir, 'remotes'))
132
+ Dir.mktmpdir do |dir|
133
+ remotes = Zold::Remotes.new(file: File.join(dir, 'remotes'))
123
134
  remotes.clean
124
135
  remotes.reset
125
136
  remotes.reset
@@ -128,10 +139,10 @@ class TestRemotes < Minitest::Test
128
139
  end
129
140
 
130
141
  def test_modifies_score
131
- Dir.mktmpdir 'test' do |dir|
142
+ Dir.mktmpdir do |dir|
132
143
  file = File.join(dir, 'remotes')
133
144
  FileUtils.touch(file)
134
- remotes = Zold::Remotes.new(file)
145
+ remotes = Zold::Remotes.new(file: file)
135
146
  remotes.add('127.0.0.1', 1024)
136
147
  remotes.rescore('127.0.0.1', 1024, 15)
137
148
  remotes.all.each do |r|
@@ -142,17 +153,17 @@ class TestRemotes < Minitest::Test
142
153
  end
143
154
 
144
155
  def test_tolerates_invalid_requests
145
- Dir.mktmpdir 'test' do |dir|
156
+ Dir.mktmpdir do |dir|
146
157
  file = File.join(dir, 'remotes')
147
- remotes = Zold::Remotes.new(file)
158
+ remotes = Zold::Remotes.new(file: file)
148
159
  remotes.error('127.0.0.1', 1024)
149
160
  remotes.rescore('127.0.0.1', 1024, 15)
150
161
  end
151
162
  end
152
163
 
153
164
  def test_modifies_from_many_threads
154
- Dir.mktmpdir 'test' do |dir|
155
- remotes = Zold::Remotes.new(File.join(dir, 'a.csv'))
165
+ Dir.mktmpdir do |dir|
166
+ remotes = Zold::Remotes.new(file: File.join(dir, 'a.csv'))
156
167
  remotes.clean
157
168
  threads = 5
158
169
  pool = Concurrent::FixedThreadPool.new(threads)
@@ -180,4 +191,32 @@ class TestRemotes < Minitest::Test
180
191
  assert_equal(0, remotes.all.reject { |r| r[:host] == host }.size)
181
192
  end
182
193
  end
194
+
195
+ def test_adds_from_many_threads
196
+ Dir.mktmpdir do |dir|
197
+ remotes = Zold::Remotes.new(file: File.join(dir, 'xx.csv'))
198
+ remotes.clean
199
+ threads = 5
200
+ pool = Concurrent::FixedThreadPool.new(threads)
201
+ done = Concurrent::AtomicFixnum.new
202
+ latch = Concurrent::CountDownLatch.new(1)
203
+ threads.times do |i|
204
+ pool.post do
205
+ Zold::VerboseThread.new(test_log).run(true) do
206
+ latch.wait(10)
207
+ remotes.add('127.0.0.1', 8080 + i)
208
+ done.increment
209
+ end
210
+ end
211
+ end
212
+ latch.count_down
213
+ sleep 0.1 until done.value == threads
214
+ assert_equal(threads, remotes.all.count)
215
+ end
216
+ end
217
+
218
+ def test_empty_remotes
219
+ remotes = Zold::Remotes::Empty.new(file: '/tmp/empty')
220
+ assert(remotes.is_a?(Zold::Remotes))
221
+ end
183
222
  end
@@ -34,7 +34,8 @@ require_relative '../lib/zold/version'
34
34
  class TestZold < Minitest::Test
35
35
  def test_all_scripts
36
36
  Dir.new('fixtures/scripts').select { |f| f =~ /\.sh$/ && !f.start_with?('_') }.each do |f|
37
- Dir.mktmpdir 'test' do |dir|
37
+ # next unless f == 'redeploy-on-upgrade.sh'
38
+ Dir.mktmpdir do |dir|
38
39
  FileUtils.cp('fixtures/id_rsa.pub', dir)
39
40
  FileUtils.cp('fixtures/id_rsa', dir)
40
41
  script = File.join(dir, f)
@@ -68,7 +69,7 @@ class TestZold < Minitest::Test
68
69
  end
69
70
 
70
71
  def test_create_new_wallet
71
- Dir.mktmpdir 'test' do |dir|
72
+ Dir.mktmpdir do |dir|
72
73
  FileUtils.cp('fixtures/id_rsa.pub', dir)
73
74
  FileUtils.cp('fixtures/id_rsa', dir)
74
75
  stdout = exec(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.17
4
+ version: 0.14.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-18 00:00:00.000000000 Z
11
+ date: 2018-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -335,7 +335,6 @@ files:
335
335
  - ".rultor.yml"
336
336
  - ".simplecov"
337
337
  - ".travis.yml"
338
- - ".zoldata/remotes"
339
338
  - Gemfile
340
339
  - INSTALL.md
341
340
  - LICENSE.txt
@@ -346,7 +345,6 @@ files:
346
345
  - bin/zold
347
346
  - cucumber.yml
348
347
  - deploy.sh
349
- - farm
350
348
  - features/cli.feature
351
349
  - features/gem_package.feature
352
350
  - features/step_definitions/steps.rb
@@ -401,6 +399,7 @@ files:
401
399
  - lib/zold/commands/invoice.rb
402
400
  - lib/zold/commands/list.rb
403
401
  - lib/zold/commands/merge.rb
402
+ - lib/zold/commands/next.rb
404
403
  - lib/zold/commands/node.rb
405
404
  - lib/zold/commands/pay.rb
406
405
  - lib/zold/commands/propagate.rb
@@ -457,6 +456,7 @@ files:
457
456
  - test/commands/test_node.rb
458
457
  - test/commands/test_pay.rb
459
458
  - test/commands/test_propagate.rb
459
+ - test/commands/test_pull.rb
460
460
  - test/commands/test_push.rb
461
461
  - test/commands/test_remote.rb
462
462
  - test/commands/test_show.rb
@@ -544,6 +544,7 @@ test_files:
544
544
  - test/commands/test_node.rb
545
545
  - test/commands/test_pay.rb
546
546
  - test/commands/test_propagate.rb
547
+ - test/commands/test_pull.rb
547
548
  - test/commands/test_push.rb
548
549
  - test/commands/test_remote.rb
549
550
  - test/commands/test_show.rb
@@ -1 +0,0 @@
1
- b1.zold.io,80,0,0
data/farm DELETED
@@ -1 +0,0 @@
1
- 0/6: 2018-07-18T09:06:07Z b1.zold.io 80 ML5Ern7m@912ecc24b32dbe74