[前][次][番号順一覧][スレッド一覧]

ruby-changes:53265

From: k0kubun <ko1@a...>
Date: Thu, 1 Nov 2018 13:20:32 +0900 (JST)
Subject: [ruby-changes:53265] k0kubun:r65480 (trunk): test_win32ole_event.rb: retry #test_s_new_loop with sleep

k0kubun	2018-11-01 13:20:26 +0900 (Thu, 01 Nov 2018)

  New Revision: 65480

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65480

  Log:
    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

  Modified files:
    trunk/test/win32ole/test_win32ole_event.rb
Index: test/win32ole/test_win32ole_event.rb
===================================================================
--- test/win32ole/test_win32ole_event.rb	(revision 65479)
+++ test/win32ole/test_win32ole_event.rb	(revision 65480)
@@ -117,7 +117,10 @@ if defined?(WIN32OLE_EVENT) https://github.com/ruby/ruby/blob/trunk/test/win32ole/test_win32ole_event.rb#L117
           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) https://github.com/ruby/ruby/blob/trunk/test/win32ole/test_win32ole_event.rb#L150
         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
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]