Skip to content

Commit f1ff37f

Browse files
Fix flaky test failure (#261)
In particular ``` $ ruby -Itest:lib -rpry-byebug -e 'require "./test/breakpoints_test.rb"; require "./test/pry_ext_test.rb"' -- --seed=1 --verbose -n "/^(?:BreakpointsTestGeneral#(?:test_add_method_adds_class_method_breakpoint)|when disable-pry called#(?:test_0002_does not start byebug))$/" Run options: --seed=1 --verbose -n "/^(?:BreakpointsTestGeneral#(?:test_add_method_adds_class_method_breakpoint)|when disable-pry called#(?:test_0002_does not start byebug))$/" # Running: BreakpointsTestGeneral#test_add_method_adds_class_method_breakpoint = 0.00 s = . /home/deivid/Code/pry-byebug/test/examples/multiple.rb:5: warning: __FILE__ in eval may not return location in binding; use Binding#source_location instead /home/deivid/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/pry-0.12.2/lib/pry/commands/whereami.rb:40: warning: in `eval' /home/deivid/Code/pry-byebug/test/examples/multiple.rb:5: warning: __LINE__ in eval may not return location in binding; use Binding#source_location instead /home/deivid/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/pry-0.12.2/lib/pry/commands/whereami.rb:41: warning: in `eval' when disable-pry called#test_0002_does not start byebug = 0.08 s = F Failure: when disable-pry called#test_0002_does not start byebug [/home/deivid/Code/pry-byebug/test/pry_ext_test.rb:22]: Expected false to be truthy. ``` To fix it, I'm cleaning up breakpoints leaked by the breakpoints tests preventing byebug to be "autostopped" because it has active breakpoints. Clearing breakpoints through `Breakpoints.delete_all` was not enough because the underlying byebug breakpoints were not being deleted unless Byebug was already started, and Byebug is not started during the execution of this unit test. Normally I don't like making changes in lib just to fix a flaky test but in this case I see no particular reason to do this check so I'll take the risk and remove the conditions.
1 parent 48a3cef commit f1ff37f

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/pry/byebug/breakpoints.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def change(id, expression = nil)
8888
#
8989
def delete(id)
9090
deleted =
91-
::Byebug.started? &&
9291
::Byebug::Breakpoint.remove(id) &&
9392
breakpoints.delete(find_by_id(id))
9493

@@ -100,7 +99,7 @@ def delete(id)
10099
#
101100
def delete_all
102101
@breakpoints = []
103-
::Byebug.breakpoints.clear if ::Byebug.started?
102+
::Byebug.breakpoints.clear
104103
end
105104

106105
#

test/breakpoints_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def test_add_method_adds_instance_method_breakpoint
3131

3232
assert_equal "BreakpointsTest::Tester", bp.source
3333
assert_equal "instance_method", bp.pos
34+
35+
breakpoints_class.delete_all
3436
end
3537

3638
def test_add_method_adds_class_method_breakpoint
@@ -39,5 +41,7 @@ def test_add_method_adds_class_method_breakpoint
3941

4042
assert_equal "BreakpointsTest::Tester", bp.source
4143
assert_equal "class_method", bp.pos
44+
45+
breakpoints_class.delete_all
4246
end
4347
end

0 commit comments

Comments
 (0)