@@ -1875,29 +1875,31 @@ class BrowserCore(RunnerCore):
18751875 def __init__ (self , * args , ** kwargs ):
18761876 super ().__init__ (* args , ** kwargs )
18771877
1878- @staticmethod
1879- def browser_open (url ):
1880- if not EMTEST_BROWSER :
1881- logger .info ('Using default system browser' )
1882- webbrowser .open_new (url )
1883- return
1878+ @classmethod
1879+ def browser_restart (cls ):
1880+ # Kill existing browser
1881+ logger .info ("Restarting browser process" )
1882+ print (cls .browser_proc )
1883+ print (cls .browser_proc .pid )
1884+ cls .browser_proc .terminate ()
1885+ try :
1886+ cls .browser_proc .wait (1 )
1887+ except subprocess .TimeoutExpired :
1888+ cls .browser_proc .kill ()
1889+ cls .browser_proc .wait ()
1890+ print ("KILLED" )
1891+ cls .browser_open (cls .harness_url )
18841892
1893+ @classmethod
1894+ def browser_open (cls , url ):
1895+ global EMTEST_BROWSER
1896+ if not EMTEST_BROWSER :
1897+ logger .info ('No EMTEST_BROWSER set. Defaulting on `chrome`' )
1898+ EMTEST_BROWSER = 'chrome'
18851899 browser_args = shlex .split (EMTEST_BROWSER )
1886- # If the given browser is a scalar, treat it like one of the possible types
1887- # from https://docs.python.org/2/library/webbrowser.html
1888- if len (browser_args ) == 1 :
1889- try :
1890- # This throws if the type of browser isn't available
1891- webbrowser .get (browser_args [0 ]).open_new (url )
1892- logger .info ('Using Emscripten browser: %s' , browser_args [0 ])
1893- return
1894- except webbrowser .Error :
1895- # Ignore the exception and fallback to the custom command logic
1896- pass
1897- # Else assume the given browser is a specific program with additional
1898- # parameters and delegate to that
1899- logger .info ('Using Emscripten browser: %s' , str (browser_args ))
1900- subprocess .Popen (browser_args + [url ])
1900+ logger .info ('Launching browser: %s' , str (browser_args ))
1901+ print (cls )
1902+ cls .browser_proc = subprocess .Popen (browser_args + [url ])
19011903
19021904 @classmethod
19031905 def setUpClass (cls ):
@@ -1912,7 +1914,8 @@ def setUpClass(cls):
19121914 cls .harness_server = multiprocessing .Process (target = harness_server_func , args = (cls .harness_in_queue , cls .harness_out_queue , cls .port ))
19131915 cls .harness_server .start ()
19141916 print ('[Browser harness server on process %d]' % cls .harness_server .pid )
1915- cls .browser_open ('http://localhost:%s/run_harness' % cls .port )
1917+ cls .harness_url = 'http://localhost:%s/run_harness' % cls .port
1918+ cls .browser_open (cls .harness_url )
19161919
19171920 @classmethod
19181921 def tearDownClass (cls ):
@@ -1944,7 +1947,7 @@ def run_browser(self, html_file, expected=None, message=None, timeout=None, extr
19441947 if not has_browser ():
19451948 return
19461949 if BrowserCore .unresponsive_tests >= BrowserCore .MAX_UNRESPONSIVE_TESTS :
1947- self .skipTest ('too many unresponsive tests, skipping browser launch - check your setup! ' )
1950+ self .skipTest ('too many unresponsive tests, skipping remaining tests ' )
19481951 self .assert_out_queue_empty ('previous test' )
19491952 if DEBUG :
19501953 print ('[browser launch:' , html_file , ']' )
@@ -1969,6 +1972,7 @@ def run_browser(self, html_file, expected=None, message=None, timeout=None, extr
19691972 if not received_output :
19701973 BrowserCore .unresponsive_tests += 1
19711974 print ('[unresponsive tests: %d]' % BrowserCore .unresponsive_tests )
1975+ self .browser_restart ()
19721976 if output is None :
19731977 # the browser harness reported an error already, and sent a None to tell
19741978 # us to also fail the test
0 commit comments