From e31864a8a0508a66b71a643c95741199e65c81a2 Mon Sep 17 00:00:00 2001 From: k0kubun Date: Thu, 1 Nov 2018 04:20:26 +0000 Subject: [PATCH] test_win32ole_event.rb: retry #test_s_new_loop with sleep It seems to fail randomly: https://ci.appveyor.com/project/ruby/ruby/builds/19963142/job/8gaxepksa0i3b998 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/win32ole/test_win32ole_event.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/win32ole/test_win32ole_event.rb b/test/win32ole/test_win32ole_event.rb index e23097e2e1..a1546da4a2 100644 --- a/test/win32ole/test_win32ole_event.rb +++ b/test/win32ole/test_win32ole_event.rb @@ -117,7 +117,10 @@ if defined?(WIN32OLE_EVENT) message_loop GC.start end - assert_match(/OnObjectReady/, @event) + + # @event randomly becomes "OnCompleted" here. Try to wait until it matches. + # https://ci.appveyor.com/project/ruby/ruby/builds/19963142/job/8gaxepksa0i3b998 + assert_match_with_retries(/OnObjectReady/, :@event) end def test_on_event @@ -147,6 +150,19 @@ if defined?(WIN32OLE_EVENT) end raise end + + def assert_match_with_retries(regexp, ivarname) + ivar = instance_variable_get(ivarname) + + tries = 0 + while tries < 5 && !ivar.match(regexp) + $stderr.puts "test_win32ole_event.rb: retrying until #{ivarname} matches #{regexp} (tries: #{tries})..." + sleep(2 ** tries) # sleep at most 31s in total + ivar = instance_variable_get(ivarname) + end + + assert_match(regexp, ivar) + end end end