Skip to content

Commit

Permalink
Added stress test for launching app to detect CEF initialization fail…
Browse files Browse the repository at this point in the history
…ure on Linux. See Issue 131.
  • Loading branch information
cztomczak committed Aug 25, 2014
1 parent c1260fb commit 6e60d78
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cefpython/cef3/wx-subpackage/examples/sample2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import wx
import wx.lib.agw.flatnotebook as fnb
import cefpython3.wx.chromectrl as chrome
import platform
import sys

ROOT_NAME = "My Locations"

Expand All @@ -32,6 +34,14 @@ def __init__(self):
self.initComponents()
self.layoutComponents()
self.initEventHandlers()
if len(sys.argv) == 2 and sys.argv[1] == "test-launch":
wx.CallLater(500, self.testLaunch)

def testLaunch(self):
# This hash is checked by /tests/test-launch.sh script
# to detect whether CEF initialized successfully.
print("b8ba7d9945c22425328df2e21fbb64cd")
self.Close()

def initComponents(self):
self.tree = wx.TreeCtrl(self, id=-1, size=(200, -1))
Expand Down Expand Up @@ -73,8 +83,16 @@ def OnPageClosing(self, event):
def OnClose(self, event):
self.Destroy()


if __name__ == '__main__':
chrome.Initialize()
if platform.system() == "Linux":
# CEF initialization fails intermittently on Linux during
# launch of a subprocess (Issue 131). The solution is
# to offload cpu for half a second after Initialize
# has returned (it still runs some stuff in its thread).
import time
time.sleep(0.5)
print('sample2.py: wx.version=%s' % wx.version())
app = wx.PySimpleApp()
MainFrame().Show()
Expand Down
27 changes: 27 additions & 0 deletions cefpython/tests/test-launch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Usage: ./test-launch.sh 500

# When launching this test script more than once in current
# Linux session then the CEF initialization issue is hard
# to reproduce. The best results are when launching tests
# in a clean Ubuntu session, just log out and log in again,
# and run the test immediately. You could also run a few
# terminal sessions with several test scripts running
# simultaneously to simulate heavy overload.

for ((i = 1; i <= $1; i++)); do
output=$(python ./../cef3/wx-subpackage/examples/sample2.py test-launch)
code=$?
if [[ $code != 0 || $output != *b8ba7d9945c22425328df2e21fbb64cd* ]]; then
echo "EXIT CODE: $code"
echo "OUTPUT: $output"
echo "ERROR!"
read -p "Press ENTER to exit"
exit $code
fi
echo RUN $i OK
done

echo TEST SUCCEEDED
read -p "Press ENTER to exit"

0 comments on commit 6e60d78

Please sign in to comment.