bin/zold-stress in zold-stress-0.1.0 vs bin/zold-stress in zold-stress-0.2.0

- old
+ new

@@ -21,39 +21,43 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. STDOUT.sync = true -start = Time.now - require 'slop' require 'rainbow' require 'zold/log' require 'zold/age' require 'zold/wallet' require 'zold/wallets' require 'zold/sync_wallets' require 'zold/cached_wallets' require 'zold/remotes' +require 'zold/commands/list' require_relative '../lib/zold/stress/round' require_relative '../lib/zold/stress/stats' +require_relative '../lib/zold/stress/summary' require_relative '../lib/zold/stress/air' Thread.current.name = 'main' Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = Encoding::UTF_8 log = Zold::Log::Regular.new +vlog = Zold::Log::Quiet.new begin opts = Slop.parse(ARGV, strict: false, suppress_errors: true) do |o| o.banner = "Usage: zold-stress [options] Available options:" o.integer '-r', '--rounds', 'Total amount of paying rounds to complete (default: 16)', default: 16 + o.integer '-w', '--wait', + 'For how to long to wait for all payments to arrive (default: 600 seconds)', + default: 600 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})", @@ -71,16 +75,21 @@ o.string '--network', "The name of the network we work in (default: #{Zold::Wallet::MAIN_NETWORK}", required: true, default: Zold::Wallet::MAIN_NETWORK o.bool '-h', '--help', 'Show these instructions' + o.on '--verbose', 'Enable extra logging information' do + log = Zold::Log::Verbose.new + vlog = Zold::Log::Regular.new + end o.on '--no-colors', 'Disable colors in the ouput' do Rainbow.enabled = false end end log = Zold::Log::Sync.new(log) + vlog = Zold::Log::Sync.new(vlog) if opts.help? log.info(opts.to_s) exit end @@ -94,29 +103,47 @@ wallets = Zold::SyncWallets.new( Zold::CachedWallets.new(Zold::Wallets.new(home)), log: log ) remotes = Zold::Remotes.new(file: File.join(zoldata, 'remotes'), network: opts['network']) - remotes.defaults + if remotes.all.empty? + remotes.defaults + log.info("The list of remotes has got default nodes, there are #{remotes.all.count} total") + end copies = File.join(zoldata, 'copies') stats = Zold::Stress::Stats.new + summary = Zold::Stress::Summary.new(stats, opts['batch']) air = Zold::Stress::Air.new round = Zold::Stress::Round.new( pvt: Zold::Key.new(file: opts['private-key']), wallets: wallets, remotes: remotes, copies: copies, - stats: stats, air: air, log: log, opts: opts + stats: stats, air: air, log: log, vlog: vlog, opts: opts ) - opts['rounds'].times do - round.update - round.prepare + + start = Time.now + round.update + round.prepare + opts['rounds'].times do |r| round.send round.pull round.match - log.info(stats.to_console) + log.info(summary) + Zold::List.new(wallets: wallets, log: log).run(['list'] + opts.arguments) if (r % 10).zero? end + s = Time.now + loop do + break if Time.now > s + opts['wait'] + break if air.fetch.empty? + round.pull + round.match + log.info(summary) + end + unless air.fetch.empty? + raise "#{air.fetch.count} payments out of #{stats.total('paid')} are still somewhere, we lost them :(" + end + log.info("Successfully sent and received #{Rainbow(stats.total('arrived')).green} transactions \ +in #{Zold::Age.new(start)}") rescue StandardError => ex log.error(Backtrace.new(ex)) exit(-1) end - -log.info("Successfully finished in #{Zold::Age.new(start)}")