From 99bd3269deb790fbe04329e1ad66dd2853050358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sat, 21 Feb 2015 19:32:26 -0200 Subject: [PATCH] Add a failing test for #115 --- test/commands/eval_test.rb | 66 ++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/test/commands/eval_test.rb b/test/commands/eval_test.rb index b2398bd66..ee4dea15a 100644 --- a/test/commands/eval_test.rb +++ b/test/commands/eval_test.rb @@ -33,19 +33,19 @@ def test_eval_properly_evaluates_expressions check_output_includes '5' end - def test_eval_properly_evals_expressions_involving_threads - enter 'eval Thread.new {}.join' - debug_code(program) - check_output_includes(/#/) - end - - def test_eval_properly_evaluates_an_expression_using_timeout + def test_eval_properly_evaluates_expressions_using_threads require 'timeout' enter 'eval Timeout::timeout(60) { 1 }' debug_code(program) check_output_includes '1' end + def test_eval_does_not_hang_when_evaluating_expressions_using_new_threads + enter 'eval Thread.new {}.join' + debug_code(program) + check_output_includes(/#/) + end + def test_eval_works_when_inspect_raises_an_exception enter 'c 18', 'eval @foo' debug_code(program) { assert_equal 18, state.line } @@ -97,5 +97,57 @@ def test_putl_prints_expression_and_sorts_and_columnize_the_result debug_code(program) check_output_includes '1 3 5 7 9', '2 4 6 8' end + + def program_threads + <<-EOC + module Byebug + # + # Toy class to test evaluation in Byebug's prompt + # + class Hola + def initialize + Thread.new do + loop do + sleep 0.01 + next if numbers.empty? + squares << (numbers.pop)**2 + end + end + end + + def numbers + @numbers ||= Queue.new + end + + def squares + @squares ||= [] + end + + def calc(number) + numbers.push(number) + + loop do + next if squares.empty? + + return squares.pop + end + end + end + + worker = Hola.new + + byebug + + 'Processed: ' + worker.squares.join(' ') + end + EOC + end + + def test_eval_does_not_hang_when_evaluating_expressions_using_old_threads + skip + enter 'eval worker.calc(10)' + debug_code(program_threads) + check_output_includes '100' + end end end