diff --git a/.gitignore b/.gitignore index 6e4415c..cfca7bb 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ coverage/ rdoc/ Gemfile.lock .zoldata/ +home/ diff --git a/bin/zold-stress b/bin/zold-stress index 086b799..3fd95b3 100755 --- a/bin/zold-stress +++ b/bin/zold-stress @@ -35,6 +35,8 @@ require 'zold/sync_wallets' require 'zold/cached_wallets' require 'zold/remotes' require_relative '../lib/zold/stress/round' +require_relative '../lib/zold/stress/stats' +require_relative '../lib/zold/stress/air' Thread.current.name = 'main' @@ -47,17 +49,22 @@ begin opts = Slop.parse(ARGV, strict: false, suppress_errors: true) do |o| o.banner = "Usage: zold-stress [options] Available options:" - o.string '--wallet', - 'Wallet ID where we start from', - required: true + o.integer '-r', '--rounds', + 'Total amount of paying rounds to complete (default: 16)', + default: 16 + o.integer '-p', '--pool', + 'From how many wallets to send payments (default: 8)', + default: 8 + o.integer '-t', '--threads', + "How many threads to use for each operation (default: #{Concurrent.processor_count * 8})", + default: Concurrent.processor_count * 8 + o.integer '-b', '--batch', + "How many transactions to send in each round (default: 64)", + default: 64 o.string '--private-key', 'The location of RSA private key (default: ~/.ssh/id_rsa)', require: true, default: File.expand_path('~/.ssh/id_rsa') - o.string '--public-key', - 'The location of RSA public key (default: ~/.ssh/id_rsa.pub)', - require: true, - default: File.expand_path('~/.ssh/id_rsa.pub') o.string '--home', "Home directory (default: #{Dir.pwd})", default: Dir.pwd @@ -69,9 +76,6 @@ Available options:" o.on '--no-colors', 'Disable colors in the ouput' do Rainbow.enabled = false end - o.on '--verbose', 'Enable extra logging information' do - log = Zold::Log::Verbose.new - end end log = Zold::Log::Sync.new(log) @@ -84,7 +88,6 @@ Available options:" home = File.expand_path(opts[:home]) FileUtils.mkdir_p(home) Dir.chdir(home) - log.debug("Home directory: #{home}") zoldata = File.join(home, '.zoldata') @@ -96,21 +99,24 @@ Available options:" remotes.defaults copies = File.join(zoldata, 'copies') - log.debug("Network: #{opts['network']} (#{opts['network'] == Zold::Wallet::MAIN_NETWORK ? 'main' : 'test'} net)") - - Zold::Stress::Round.new( - id: Zold::Id.new(opts['wallet']), - pub: Zold::Key.new(file: opts['public-key']), + stats = Zold::Stress::Stats.new + air = Zold::Stress::Air.new + round = Zold::Stress::Round.new( pvt: Zold::Key.new(file: opts['private-key']), - wallets: wallets, - remotes: remotes, - copies: copies, - log: log - ).run + wallets: wallets, remotes: remotes, copies: copies, + stats: stats, air: air, log: log, opts: opts + ) + opts['rounds'].times do |r| + round.update + round.prepare + # round.send + # round.pull + # round.match + log.info(stats.to_console) + end rescue StandardError => ex - log.error("#{ex.message} (#{ex.class.name})") - puts(ex.backtrace) + log.error(Backtrace.new(ex)) exit(-1) end -log.debug("Successfully finished in #{Zold::Age.new(start)}") +log.info("Successfully finished in #{Zold::Age.new(start)}") diff --git a/lib/zold/stress/air.rb b/lib/zold/stress/air.rb index 6a1b226..e1a64c8 100644 --- a/lib/zold/stress/air.rb +++ b/lib/zold/stress/air.rb @@ -32,12 +32,6 @@ def initialize @all = [] end - def to_json - { - 'total': @all.count - } - end - def fetch @all end diff --git a/lib/zold/stress/pmnts.rb b/lib/zold/stress/pmnts.rb index 2712a6b..7c86e80 100644 --- a/lib/zold/stress/pmnts.rb +++ b/lib/zold/stress/pmnts.rb @@ -34,15 +34,14 @@ module Zold::Stress # Payments to send in a batch. class Pmnts - def initialize(pvt:, wallets:, remotes:, stats:, log: Zold::Log::Quiet.new) - raise 'Private RSA key can\'t be nil' if pvt.nil? - raise 'Private RSA key must be of type Key' unless pvt.is_a?(Zold::Key) + def initialize(pvt:, wallets:, remotes:, stats:, opts:, + vlog: Zold::Log::Quiet.new, log: Zold::Log::Quiet.new) @pvt = pvt - raise 'Wallets can\'t be nil' if wallets.nil? @wallets = wallets @remotes = remotes - raise 'Log can\'t be nil' if log.nil? @log = log + @vlog = vlog + @opts = opts @stats = stats end @@ -51,15 +50,19 @@ def send paid = [] Tempfile.open do |f| File.write(f, @pvt.to_s) - @wallets.all.each do |source| + loop do + source = @wallets.all.sample balance = @wallets.find(source, &:balance) next if balance.negative? || balance.zero? amount = balance / @wallets.all.count next if amount < Zold::Amount.new(zld: 0.0001) - @wallets.all.each do |target| + loop do + target = @wallets.all.sample next if source == target paid << pay_one(source, target, amount, f.path) + break end + break if paid.count >= @opts['batch'] end end paid @@ -68,20 +71,26 @@ def send private def pay_one(source, target, amount, pvt) - Zold::Taxes.new(wallets: @wallets, remotes: @remotes, log: @log).run( - ['taxes', 'pay', source.to_s, "--network=#{@network}", "--private-key=#{pvt}", '--ignore-nodes-absence'] + Zold::Taxes.new(wallets: @wallets, remotes: @remotes, log: @vlog).run( + [ + 'taxes', 'pay', source.to_s, "--network=#{@opts['network']}", + "--private-key=#{pvt}", '--ignore-nodes-absence' + ] ) if @wallets.find(source) { |w| Zold::Tax.new(w).in_debt? } - @log.error("The wallet #{source} is still in debt and we can't pay taxes") + @log.error("The wallet #{source} is in debt and we can't pay taxes") return end details = SecureRandom.uuid @stats.exec('paid', swallow: false) do - Zold::Pay.new(wallets: @wallets, remotes: @remotes, log: @log).run( - ['pay', source.to_s, target.to_s, amount.to_zld(4), details, "--network=#{@network}", "--private-key=#{pvt}"] + Zold::Pay.new(wallets: @wallets, remotes: @remotes, log: @vlog).run( + [ + 'pay', source.to_s, target.to_s, amount.to_zld(6), details, + "--network=#{@opts['network']}", "--private-key=#{pvt}" + ] ) end - { start: Time.now, source: source, target: target, details: details } + { start: Time.now, source: source, target: target, amount: amount, details: details } end end end diff --git a/lib/zold/stress/pool.rb b/lib/zold/stress/pool.rb index 28cb4d4..b818eb0 100644 --- a/lib/zold/stress/pool.rb +++ b/lib/zold/stress/pool.rb @@ -37,46 +37,37 @@ module Zold::Stress # Pool of wallets. class Pool - def initialize(id:, pub:, wallets:, remotes:, copies:, stats:, log: Zold::Log::Quiet.new) - @id = id - @pub = pub + def initialize(wallets:, remotes:, copies:, stats:, opts:, + log: Zold::Log::Quiet.new, vlog: Zold::Log::Quiet.new) @wallets = wallets @remotes = remotes @copies = copies @log = log + @vlog = vlog + @opts = opts @stats = stats end - def rebuild(size, opts = []) - candidates = [@id] - @wallets.all.each do |id| - @wallets.find(id, &:txns).each do |t| - next unless t.amount.negative? - candidates << t.bnf - end - end - candidates.uniq.shuffle.each do |id| - @wallets.all.each do |w| - next if @wallets.find(w, &:balance) > Zold::Amount.new(zld: 0.01) - Zold::Remove.new(wallets: @wallets, log: @log).run( - ['remove', w.to_s] - ) - end - break if @wallets.all.count > size - @stats.exec('pull') do - Zold::Pull.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @log).run( - ['pull', id.to_s] + opts - ) - end + def rebuild + raise "There are no wallets in the pool at #{@wallets.path}, at least one is needed" if @wallets.all.empty? + balances = @wallets.all + .map { |id| {id: id, balance: @wallets.find(id, &:balance)} } + .sort_by { |h| h[:balance] } + .reverse + balances.last([balances.count - @opts['pool'], 0].max).each do |h| + Zold::Remove.new(wallets: @wallets, log: @vlog).run( + ['remove', h[:id].to_s] + ) end Tempfile.open do |f| - File.write(f, @pub.to_s) - while @wallets.all.count < size - Zold::Create.new(wallets: @wallets, log: @log).run( - ['create', "--public-key=#{f.path}"] + opts + File.write(f, @wallets.find(balances[0][:id], &:key).to_s) + while @wallets.all.count < @opts['pool'] + Zold::Create.new(wallets: @wallets, log: @vlog).run( + ['create', "--public-key=#{f.path}", "--network=#{@opts['network']}"] + @opts.arguments ) end end + raise "There is no money in the pool of #{balances.count} wallets at #{@wallets.path}" if balances[0][:balance].zero? end end end diff --git a/lib/zold/stress/round.rb b/lib/zold/stress/round.rb index 503ef15..ccaedd1 100644 --- a/lib/zold/stress/round.rb +++ b/lib/zold/stress/round.rb @@ -38,107 +38,104 @@ module Zold::Stress # Full round of stress test class Round - # Number of wallets to work with - POOL_SIZE = 8 - - def initialize(id:, pub:, pvt:, wallets:, remotes:, copies:, log: Zold::Log::Quiet.new) - @id = id - @pub = pub + def initialize(pvt:, wallets:, remotes:, copies:, + stats:, air:, opts:, log: Zold::Log::Quiet.new, vlog: Zold::Log::Quiet.new) @pvt = pvt @wallets = wallets @remotes = remotes @copies = copies + @opts = opts @log = log - @stats = Zold::Stress::Stats.new(log: log) - @air = Zold::Stress::Air.new + @stats = stats + @air = air + @vlog = vlog end - def to_json - { - 'version': Zold::VERSION, - 'remotes': @remotes.all.count, - 'wallets': @wallets.all.map do |id| - @wallets.find(id) do |w| - { - 'id': w.id, - 'txns': w.txns.count, - 'balance': w.balance.to_zld(4) - } - end - end, - 'thread': @thread ? @thread.status : '-', - 'air': @air.to_json - }.merge(@stats.to_json) + def update + start = Time.now + cmd = Zold::Remote.new(remotes: @remotes, log: @vlog) + args = ['remote'] + @opts.arguments + cmd.run(args + ['trim']) + cmd.run(args + ['reset']) if @remotes.all.empty? + @stats.exec('update') do + cmd.run(args + ['update']) + end + cmd.run(args + ['select']) + @log.info("List of remotes updated in #{Zold::Age.new(start)}, #{@remotes.all.count} nodes in the list") end - def run(opts: []) - @stats.exec('cycle') do - update(opts) - pool = Zold::Stress::Pool.new( - id: @id, pub: @pub, wallets: @wallets, - remotes: @remotes, copies: @copies, stats: @stats, - log: @log - ) - pool.rebuild(POOL_SIZE, opts) - @log.info("There are #{@wallets.all.count} wallets in the pool after rebuild") - @wallets.all.peach(Concurrent.processor_count * 8) do |id| - Zold::Push.new(wallets: @wallets, remotes: @remotes, log: @log).run( - ['push', id.to_s] + opts + def prepare + start = Time.now + pool = Zold::Stress::Pool.new( + wallets: @wallets, + remotes: @remotes, copies: @copies, stats: @stats, + log: @log, opts: @opts, vlog: @vlog + ) + pool.rebuild + @wallets.all.peach(@opts['threads']) do |id| + @stats.exec('push') do + Zold::Push.new(wallets: @wallets, remotes: @remotes, log: @vlog).run( + ['push', id.to_s, "--network=#{@opts['network']}"] + @opts.arguments ) end - sent = Zold::Stress::Pmnts.new( - pvt: @pvt, wallets: @wallets, - remotes: @remotes, stats: @stats, - log: @log - ).send - @log.info("#{sent.count} payments have been sent") - mutex = Mutex.new - sent.group_by { |p| p[:source] }.peach(Concurrent.processor_count * 8) do |a| - @stats.exec('push') do - Zold::Push.new(wallets: @wallets, remotes: @remotes, log: @log).run( - ['push', a[0].to_s] + opts - ) - mutex.synchronize do - a[1].each { |p| @air.add(p) } - end + end + @log.info("There are #{@wallets.all.count} wallets in the pool \ +with #{@wallets.all.map { |id| @wallets.find(id, &:balance) }.inject(&:+)} \ +in #{Zold::Age.new(start)}") + end + + def send + start = Time.now + sent = Zold::Stress::Pmnts.new( + pvt: @pvt, wallets: @wallets, + remotes: @remotes, stats: @stats, + log: @log, opts: @opts, vlog: @vlog + ).send + mutex = Mutex.new + sources = sent.group_by { |p| p[:source] } + sources.peach(@opts['threads']) do |a| + @stats.exec('push') do + Zold::Push.new(wallets: @wallets, remotes: @remotes, log: @vlog).run( + ['push', a[0].to_s, "--network=#{@opts['network']}"] + @opts.arguments + ) + mutex.synchronize do + a[1].each { |p| @air.add(p) } end end - @log.info("#{@air.fetch.count} payments are now in the air") - @air.fetch.group_by { |p| p[:target] }.each do |a| - if @wallets.find(a[0], &:exists?) - Zold::Remove.new(wallets: @wallets, log: @log).run( - ['remove', a[0].to_s] - ) - end - @stats.exec('pull') do - Zold::Pull.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @log).run( - ['pull', a[0].to_s] + opts - ) - end + end + @log.info("#{sent.count} payments sent from #{sources.count} wallets, \ +in #{Zold::Age.new(start)}, #{@air.fetch.count} are now in the air: + #{sent.map { |p| "#{p[:source]} -> #{p[:target]} #{p[:amount]}" }.join("\n ")}") + end + + def pull + start = Time.now + @air.fetch.group_by { |p| p[:target] }.each do |a| + if @wallets.find(a[0], &:exists?) + Zold::Remove.new(wallets: @wallets, log: @vlog).run( + ['remove', a[0].to_s] + ) end - @log.info("There are #{@wallets.all.count} wallets in the pool after re-pull") - @air.fetch.each do |p| - next unless @wallets.find(p[:target], &:exists?) - t = @wallets.find(p[:target], &:txns).find { |x| x.details == p[:details] && x.bnf == p[:source] } - next if t.nil? - @stats.put('arrived', Time.now - p[:start]) - @log.info("Payment arrived to #{p[:target]} at ##{t.id} in #{Zold::Age.new(p[:start])}: #{t.details}") - @air.delete(p) + @stats.exec('pull') do + Zold::Pull.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @vlog).run( + ['pull', a[0].to_s, "--network=#{@opts['network']}"] + @opts.arguments + ) end - @log.info("#{@air.fetch.count} payments are still in the air") end + @log.info("There are #{@wallets.all.count} wallets left, after the pull in #{Zold::Age.new(start)}") end - private - - def update(opts) - return if opts.include?('--network=test') - cmd = Zold::Remote.new(remotes: @remotes, log: @log) - args = ['remote'] + opts - cmd.run(args + ['trim']) - cmd.run(args + ['reset']) if @remotes.all.empty? - cmd.run(args + ['update']) - cmd.run(args + ['select']) + def match + @air.fetch.each do |p| + next unless @wallets.find(p[:target], &:exists?) + t = @wallets.find(p[:target], &:txns).find { |x| x.details == p[:details] && x.bnf == p[:source] } + next if t.nil? + @stats.put('arrived', Time.now - p[:start]) + @log.info("#{p[:amount]} arrived from #{p[:source]} to #{p[:target]} \ +in txn ##{t.id} in #{Zold::Age.new(p[:start])}: #{t.details}") + @air.delete(p) + end + @log.info("#{@air.fetch.count} payments are still in the air") end end end diff --git a/lib/zold/stress/stats.rb b/lib/zold/stress/stats.rb index 76b457b..d6cb9d2 100644 --- a/lib/zold/stress/stats.rb +++ b/lib/zold/stress/stats.rb @@ -21,8 +21,10 @@ # SOFTWARE. require 'time' +require 'rainbow' require 'backtrace' require 'zold/log' +require 'zold/age' # Pool of wallets. # Author:: Yegor Bugayenko (yegor256@gmail.com) @@ -31,11 +33,33 @@ module Zold::Stress # Stats class Stats - def initialize(age: 24 * 60 * 60, log: Zold::Log::Quiet.new) - @age = age + def initialize @history = {} @mutex = Mutex.new - @log = log + end + + def to_console + ['update', 'push', 'pull', 'paid'].map do |m| + if @history[m] + t = "#{m}: #{total(m)}/#{Zold::Age.new(Time.now - avg(m), limit: 1)}" + errors = total(m + '_error') + t += errors.zero? ? '' : '/' + Rainbow(errors.to_s).green + t + else + "#{m}: none" + end + end.join('; ') + end + + def total(metric) + (@history[metric] || []).count + end + + def avg(metric) + array = @history[metric].map { |a| a[:value] } || [] + sum = array.inject(&:+) || 0 + count = [array.count, 1].max + sum.to_f / count end def to_json @@ -61,9 +85,10 @@ def exec(metric, swallow: true) yield put(metric + '_ok', Time.now - start) rescue StandardError => ex - @log.error(Backtrace.new(ex)) put(metric + '_error', Time.now - start) raise ex unless swallow + ensure + put(metric, Time.now - start) end def put(metric, value) @@ -71,7 +96,6 @@ def put(metric, value) @mutex.synchronize do @history[metric] = [] unless @history[metric] @history[metric] << { time: Time.now, value: value } - @history[metric].reject! { |a| a[:time] < Time.now - @age } end end end diff --git a/test/zold/stress/test_pmnts.rb b/test/zold/stress/test_pmnts.rb index e7d73bd..9c49fdb 100644 --- a/test/zold/stress/test_pmnts.rb +++ b/test/zold/stress/test_pmnts.rb @@ -29,6 +29,7 @@ require 'zold/remotes' require 'zold/commands/create' require 'tmpdir' +require 'slop' require_relative '../test__helper' require_relative 'fake_node' require_relative '../../../lib/zold/stress/pmnts' @@ -52,8 +53,9 @@ def test_pays_one_on_one pvt: Zold::Key.new(file: 'fixtures/id_rsa'), wallets: wallets, remotes: remotes, - stats: Zold::Stress::Stats.new(log: test_log), - log: test_log + stats: Zold::Stress::Stats.new, + opts: test_opts('--batch=1'), + log: test_log, vlog: test_log ).send assert_equal(1, sent.count) assert_equal(id, sent[0][:source]) @@ -70,9 +72,8 @@ def test_pays Zold::Create.new(wallets: wallets, log: test_log).run( ['create', '--public-key=fixtures/id_rsa.pub', Zold::Id::ROOT.to_s, '--network=test'] ) - total = 6 ids = [] - total.times do + 5.times do id = Zold::Create.new(wallets: wallets, log: test_log).run( ['create', '--public-key=fixtures/id_rsa.pub', '--network=test'] ) @@ -85,10 +86,11 @@ def test_pays pvt: Zold::Key.new(file: 'fixtures/id_rsa'), wallets: wallets, remotes: remotes, - stats: Zold::Stress::Stats.new(log: test_log), - log: test_log + stats: Zold::Stress::Stats.new, + opts: test_opts('--batch=20'), + log: test_log, vlog: test_log ).send - assert_equal(total * total, sent.count) + assert_equal(20, sent.count) assert_equal(ids.sort, sent.map { |s| s[:source] }.sort.uniq) end end diff --git a/test/zold/stress/test_pool.rb b/test/zold/stress/test_pool.rb index e499e3f..55a7e2e 100644 --- a/test/zold/stress/test_pool.rb +++ b/test/zold/stress/test_pool.rb @@ -28,6 +28,7 @@ require 'zold/sync_wallets' require 'zold/remotes' require 'tmpdir' +require 'slop' require_relative '../test__helper' require_relative 'fake_node' require_relative '../../../lib/zold/stress/pool' @@ -38,19 +39,24 @@ def test_reloads_wallets Zold::Stress::FakeNode.new(test_log).exec do |port| Dir.mktmpdir do |home| wallets = Zold::SyncWallets.new(Zold::Wallets.new(home)) + Zold::Create.new(wallets: wallets, log: test_log).run( + ['create', '--public-key=fixtures/id_rsa.pub', Zold::Id::ROOT.to_s, '--network=test'] + ) + wallets.find(Zold::Id::ROOT) do |w| + w.add(Zold::Txn.new(1, Time.now, Zold::Amount.new(zld: 1.0), 'NOPREFIX', Zold::Id.new, '-')) + end remotes = Zold::Remotes.new(file: File.join(home, 'remotes'), network: 'test') remotes.clean remotes.add('localhost', port) size = 3 Zold::Stress::Pool.new( - id: Zold::Id.new('0123456701234567'), - pub: Zold::Key.new(file: 'fixtures/id_rsa.pub'), wallets: wallets, remotes: remotes, copies: File.join(home, 'copies'), - stats: Zold::Stress::Stats.new(log: test_log), - log: test_log - ).rebuild(size, ['--ignore-score-weakness', '--network=test']) + stats: Zold::Stress::Stats.new, + opts: test_opts("--pool=#{size}"), + log: test_log, vlog: test_log + ).rebuild assert_equal(size, wallets.all.count) end end diff --git a/test/zold/stress/test_round.rb b/test/zold/stress/test_round.rb index 28209ce..52b068f 100644 --- a/test/zold/stress/test_round.rb +++ b/test/zold/stress/test_round.rb @@ -21,6 +21,7 @@ # SOFTWARE. require 'minitest/autorun' +require 'slop' require 'zold/key' require 'zold/id' require 'zold/log' @@ -41,54 +42,44 @@ class StressTest < Minitest::Test def test_runs_a_few_full_cycles - skip - exec do |stress| - stress.run(delay: 0, cycles: 5, opts: ['--ignore-score-weakness', '--network=test']) - json = stress.to_json - assert(json['arrived'][:total] > 30) - assert_equal(5, json['cycle_ok'][:total]) - end - end - - def test_renders_json - exec do |stress| - json = stress.to_json - assert(json[:wallets]) - assert(json[:thread]) - assert(json[:air]) - end - end - - private - - def exec Zold::Stress::FakeNode.new(Zold::Log::Quiet.new).exec do |port| - Dir.mktmpdir do |dir| - wallets = Zold::CachedWallets.new(Zold::SyncWallets.new(Zold::Wallets.new(dir))) - remotes = Zold::Remotes.new(file: File.join(dir, 'remotes'), network: 'test') + Dir.mktmpdir do |home| + wallets = Zold::CachedWallets.new(Zold::SyncWallets.new(Zold::Wallets.new(home))) + remotes = Zold::Remotes.new(file: File.join(home, 'remotes'), network: 'test') remotes.clean remotes.add('localhost', port) + wallets = Zold::SyncWallets.new(Zold::Wallets.new(home)) Zold::Create.new(wallets: wallets, log: test_log).run( - ['create', '--public-key=fixtures/id_rsa.pub', '0000000000000000', '--network=test'] - ) - id = Zold::Create.new(wallets: wallets, log: test_log).run( - ['create', '--public-key=fixtures/id_rsa.pub', '--network=test'] - ) - Zold::Pay.new(wallets: wallets, remotes: remotes, log: test_log).run( - ['pay', '0000000000000000', id.to_s, '1.00', 'start', '--private-key=fixtures/id_rsa'] - ) - Zold::Push.new(wallets: wallets, remotes: remotes, log: test_log).run( - ['push', '0000000000000000', id.to_s, '--ignore-score-weakness'] + ['create', '--public-key=fixtures/id_rsa.pub', Zold::Id::ROOT.to_s, '--network=test'] ) - yield Zold::Stress::Round.new( - id: id, - pub: Zold::Key.new(file: 'fixtures/id_rsa.pub'), + wallets.find(Zold::Id::ROOT) do |w| + w.add(Zold::Txn.new(1, Time.now, Zold::Amount.new(zld: 1.0), 'NOPREFIX', Zold::Id.new, '-')) + end + stats = Zold::Stress::Stats.new + air = Zold::Stress::Air.new + round = Zold::Stress::Round.new( pvt: Zold::Key.new(file: 'fixtures/id_rsa'), - wallets: wallets, - remotes: remotes, - copies: File.join(dir, 'copies'), - log: Zold::Log::Sync.new(Zold::Log::Regular.new) + wallets: wallets, remotes: remotes, + air: air, stats: stats, + opts: test_opts('--pool=3', '--batch=4'), + copies: File.join(home, 'copies'), + log: test_log, vlog: test_log ) + round.update + round.prepare + round.send + attempt = 0 + loop do + break if air.fetch.empty? + break if attempt > 10 + round.pull + round.match + test_log.info(stats.to_console) + attempt += 1 + sleep 0.2 + end + assert(air.fetch.empty?) + assert_equal(4, stats.total('arrived')) end end end diff --git a/test/zold/stress/test_stats.rb b/test/zold/stress/test_stats.rb index a4c396f..fe50d1b 100644 --- a/test/zold/stress/test_stats.rb +++ b/test/zold/stress/test_stats.rb @@ -33,15 +33,4 @@ def test_aggregates_metrics assert(stats.to_json[m]) assert_equal(1.55, stats.to_json[m][:avg]) end - - def test_filters_out_too_old_values - stats = Zold::Stress::Stats.new(age: 0.1) - m = 'metric-1' - stats.put(m, 1) - stats.put(m, 2) - assert_equal(2, stats.to_json[m][:total]) - sleep 0.2 - stats.put(m, 2) - assert_equal(1, stats.to_json[m][:total]) - end end diff --git a/test/zold/test__helper.rb b/test/zold/test__helper.rb index 4007918..55555f1 100644 --- a/test/zold/test__helper.rb +++ b/test/zold/test__helper.rb @@ -38,5 +38,16 @@ def test_log require 'zold/log' @test_log ||= Zold::Log::Sync.new(Zold::Log::Verbose.new) end + + def test_opts(*argv) + Slop.parse(argv + ['--ignore-score-weakness', '--network=test'], suppress_errors: true) do |o| + o.integer '--pool', default: 3 + o.integer '--rounds', default: 1 + o.integer '--threads', default: 4 + o.integer '--batch', default: 4 + o.string '--private-key', default: 'fixtures/id_rsa.pub' + o.string '--network', default: 'test' + end + end end end