test/node/test_async_entrance.rb in zold-0.15.0 vs test/node/test_async_entrance.rb in zold-0.16.0

- old
+ new

@@ -19,10 +19,11 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. require 'minitest/autorun' +require 'threads' require_relative '../fake_home' require_relative '../test__helper' require_relative '../../lib/zold/id' require_relative '../../lib/zold/node/async_entrance' require_relative 'fake_entrance' @@ -31,36 +32,51 @@ # Author:: Yegor Bugayenko (yegor256@gmail.com) # Copyright:: Copyright (c) 2018 Yegor Bugayenko # License:: MIT class TestAsyncEntrance < Minitest::Test def test_renders_json - FakeHome.new.run do |home| + FakeHome.new(log: test_log).run do |home| Zold::AsyncEntrance.new(FakeEntrance.new, home.dir, log: test_log).start do |e| assert_equal(true, e.to_json[:'pool.running']) end end end - def test_sends_through - FakeHome.new.run do |home| + def test_sends_through_once + FakeHome.new(log: test_log).run do |home| wallet = home.create_wallet amount = Zold::Amount.new(zld: 39.99) key = Zold::Key.new(file: 'fixtures/id_rsa') wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key) basic = CountingEntrance.new Zold::AsyncEntrance.new(basic, File.join(home.dir, 'a/b/c'), log: test_log).start do |e| - 5.times { e.push(wallet.id, File.read(wallet.path)) } - assert_equal_wait(false) { basic.count.zero? } - assert(!basic.count.zero?) + e.push(wallet.id, IO.read(wallet.path)) + assert_equal_wait(1) { basic.count } end end end + def test_sends_through + FakeHome.new(log: test_log).run do |home| + basic = CountingEntrance.new + Zold::AsyncEntrance.new(basic, File.join(home.dir, 'a/b/c'), log: test_log).start do |e| + Threads.new(20).assert do + wallet = home.create_wallet + amount = Zold::Amount.new(zld: 39.99) + key = Zold::Key.new(file: 'fixtures/id_rsa') + wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key) + 5.times { e.push(wallet.id, IO.read(wallet.path)) } + end + end + assert_equal_wait(true) { basic.count >= 20 } + end + end + def test_handles_broken_entrance_gracefully - FakeHome.new.run do |home| + FakeHome.new(log: test_log).run do |home| wallet = home.create_wallet Zold::AsyncEntrance.new(BrokenEntrance.new, home.dir, log: test_log).start do |e| - e.push(wallet.id, File.read(wallet.path)) + e.push(wallet.id, IO.read(wallet.path)) end end end class CountingEntrance < FakeEntrance