test/node/test_front.rb in zold-0.31.8 vs test/node/test_front.rb in zold-0.31.9

- old
+ new

@@ -1,8 +1,8 @@ # frozen_string_literal: true -# Copyright (c) 2018-2023 Zerocracy +# Copyright (c) 2018-2024 Zerocracy # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the 'Software'), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell @@ -43,21 +43,21 @@ # number of routine operations. There should be no suspicious information # in the report, which will be printed to the console. def test_memory_leakage skip report = MemoryProfiler.report(top: 10) do - FakeNode.new(log: test_log).run(opts('--network=foo')) do |port| + FakeNode.new(log: fake_log).run(opts('--network=foo')) do |port| 100.times do Zold::Http.new(uri: "http://localhost:#{port}/", network: 'foo').get end end end report.pretty_print end def test_renders_front_json - FakeNode.new(log: test_log).run(opts('--network=foo')) do |port| + FakeNode.new(log: fake_log).run(opts('--network=foo')) do |port| res = Zold::Http.new(uri: "http://localhost:#{port}/", network: 'foo').get json = JSON.parse(res.body) assert_equal(Zold::VERSION, json['version']) assert_equal(Zold::PROTOCOL, json['protocol']) assert_equal('foo', json['network']) @@ -72,11 +72,11 @@ assert(json['nscore'].zero?, json) end end def test_renders_public_pages - FakeNode.new(log: test_log).run(opts) do |port| + FakeNode.new(log: fake_log).run(opts) do |port| { 200 => [ '/robots.txt', '/', '/remotes', @@ -115,11 +115,11 @@ end end end def test_updates_list_of_remotes - FakeNode.new(log: test_log).run(['--no-metronome', '--ignore-score-weakness', '--no-cache']) do |port| + FakeNode.new(log: fake_log).run(['--no-metronome', '--ignore-score-weakness', '--no-cache']) do |port| (Zold::Remotes::MAX_NODES + 5).times do |i| score = Zold::Score.new( host: 'localhost', port: i + 1, invoice: 'NOPREFIX@ffffffffffffffff', strength: 1 ).next.next.next.next response = Zold::Http.new(uri: "http://localhost:#{port}/remotes", score: score).get @@ -136,13 +136,13 @@ end end end def test_increments_score - FakeNode.new(log: test_log).run(opts('--threads=1')) do |port| + FakeNode.new(log: fake_log).run(opts('--threads=1')) do |port| 3.times do |i| - assert_equal_wait(true, max: 60) do + assert_equal_wait(true, max: 120) do response = Zold::Http.new(uri: "http://localhost:#{port}/").get assert_equal(200, response.status, response.body) score = Zold::Score.parse_json(Zold::JsonPage.new(response.body).to_hash['score']) score.value >= i end @@ -157,12 +157,12 @@ '/age', '/mnemo', '/debt', '/txns', '/txns.json', '.bin', '/copies' ].each do |p| method = "test_wallet_page_#{p.gsub(/[^a-z]/, '_')}" define_method(method) do - FakeHome.new(log: test_log).run do |home| - FakeNode.new(log: test_log).run(opts) do |port| + FakeHome.new(log: fake_log).run do |home| + FakeNode.new(log: fake_log).run(opts) do |port| wallet = home.create_wallet(txns: 2) base = "http://localhost:#{port}" response = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path) assert_equal(200, response.status, response.body) assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status } @@ -171,12 +171,12 @@ end end end def test_renders_wallets_page - FakeHome.new(log: test_log).run do |home| - FakeNode.new(log: test_log).run(opts) do |port| + FakeHome.new(log: fake_log).run do |home| + FakeNode.new(log: fake_log).run(opts) do |port| wallet = home.create_wallet(txns: 2) base = "http://localhost:#{port}" response = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path) assert_equal(200, response.status, response.body) assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status } @@ -186,12 +186,12 @@ end end end def test_fetch_in_multiple_threads - FakeNode.new(log: test_log).run(opts) do |port| - FakeHome.new(log: test_log).run do |home| + FakeNode.new(log: fake_log).run(opts) do |port| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet base = "http://localhost:#{port}" Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path) assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status } threads = [] @@ -207,12 +207,12 @@ end end end def test_pushes_twice - FakeNode.new(log: test_log).run(opts) do |port| - FakeHome.new(log: test_log).run do |home| + FakeNode.new(log: fake_log).run(opts) do |port| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet base = "http://localhost:#{port}" assert_equal( 200, Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path).status @@ -225,13 +225,13 @@ end end end def test_pushes_many_wallets - FakeNode.new(log: test_log).run(opts) do |port| + FakeNode.new(log: fake_log).run(opts) do |port| base = "http://localhost:#{port}" - FakeHome.new(log: test_log).run do |home| + FakeHome.new(log: fake_log).run do |home| Threads.new(5).assert do wallet = home.create_wallet Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path) assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status } end @@ -271,37 +271,37 @@ end end end def test_gzip - FakeNode.new(log: test_log).run(opts) do |port| + FakeNode.new(log: fake_log).run(opts) do |port| response = Zold::Http.new(uri: URI("http://localhost:#{port}/version")).get assert_equal(200, response.status, response) assert_operator(300, :>, response.body.length.to_i, 'Expected the content to be small') end end def test_performance times = Queue.new - FakeNode.new(log: test_log).run(opts('--threads=4', '--strength=6')) do |port| + FakeNode.new(log: fake_log).run(opts('--threads=4', '--strength=6')) do |port| Threads.new(10).assert(100) do start = Time.now Zold::Http.new(uri: URI("http://localhost:#{port}/")).get times << (Time.now - start) end end all = [] all << times.pop(true) until times.empty? - test_log.info("Average response time is #{all.inject(&:+) / all.count}") + fake_log.info("Average response time is #{all.inject(&:+) / all.count}") end # The score exposed via the HTTP header must be reduced to the value of 16. # We need this in order to optimize the amount of data we transfer in each # HTTP request. This value is enough to identify a valueable node, and filter # out those that are too weak. def test_score_is_reduced - FakeNode.new(log: test_log).run(opts('--threads=1', '--strength=1', '--farmer=plain')) do |port| + FakeNode.new(log: fake_log).run(opts('--threads=1', '--strength=1', '--farmer=plain')) do |port| scores = [] 50.times do res = Zold::Http.new(uri: URI("http://localhost:#{port}/")).get scores << Zold::Score.parse(res.headers[Zold::Http::SCORE_HEADER]).value sleep(0.1) @@ -309,11 +309,11 @@ assert(scores.uniq.sort.reverse[0] <= Zold::Front::MIN_SCORE) end end def test_headers_are_being_set_correctly - FakeNode.new(log: test_log).run(opts('--expose-version=9.9.9')) do |port| + FakeNode.new(log: fake_log).run(opts('--expose-version=9.9.9')) do |port| response = Zold::Http.new(uri: URI("http://localhost:#{port}/")).get assert_equal('no-cache', response.headers['Cache-Control']) assert_equal('close', response.headers['Connection']) assert_equal('9.9.9', response.headers['X-Zold-Version']) assert_equal(app.settings.protocol.to_s, response.headers[Zold::Http::PROTOCOL_HEADER]) @@ -323,11 +323,11 @@ end end def test_alias_parameter name = SecureRandom.hex(4) - FakeNode.new(log: test_log).run(opts("--alias=#{name}")) do |port| + FakeNode.new(log: fake_log).run(opts("--alias=#{name}")) do |port| uri = URI("http://localhost:#{port}/") response = Zold::Http.new(uri: uri).get assert_match( name, Zold::JsonPage.new(response.body).to_hash['alias'].to_s, @@ -335,11 +335,11 @@ ) end end def test_default_alias_parameter - FakeNode.new(log: test_log).run(opts) do |port| + FakeNode.new(log: fake_log).run(opts) do |port| uri = URI("http://localhost:#{port}/") response = Zold::Http.new(uri: uri).get assert_match( "localhost:#{port}", Zold::JsonPage.new(response.body).to_hash['alias'].to_s, @@ -347,23 +347,24 @@ ) end end def test_invalid_alias + skip exception = assert_raises RuntimeError do - FakeNode.new(log: test_log).run(opts('--alias=invalid-alias')) do |port| + FakeNode.new(log: fake_log).run(opts('--alias=invalid-alias')) do |port| uri = URI("http://localhost:#{port}/") Zold::Http.new(uri: uri).get end end assert(exception.message.include?('should be a 4 to 16 char long'), exception.message) end def test_push_fetch_in_multiple_threads key = Zold::Key.new(text: File.read('fixtures/id_rsa')) - FakeNode.new(log: test_log).run(opts) do |port| - FakeHome.new(log: test_log).run do |home| + FakeNode.new(log: fake_log).run(opts) do |port| + FakeHome.new(log: fake_log).run do |home| wallet = home.create_wallet(Zold::Id::ROOT) base = "http://localhost:#{port}" Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path) assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status } cycles = 50 @@ -378,10 +379,10 @@ end end end def test_checksum_in_json - FakeNode.new(log: test_log).run(opts) do |port| + FakeNode.new(log: fake_log).run(opts) do |port| uri = URI("http://localhost:#{port}/") response = Zold::Http.new(uri: uri).get assert( Zold::JsonPage.new(response.body).to_hash.key?('checksum'), response.body