X Tutup
Skip to content

Commit 375996f

Browse files
committed
Added stress test for launching app to detect CEF initialization failure on Linux. See Issue 131.
1 parent e3dfa6a commit 375996f

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

cefpython/cef3/wx-subpackage/examples/sample2.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import wx
1212
import wx.lib.agw.flatnotebook as fnb
1313
import cefpython3.wx.chromectrl as chrome
14+
import platform
15+
import sys
1416

1517
ROOT_NAME = "My Locations"
1618

@@ -32,6 +34,14 @@ def __init__(self):
3234
self.initComponents()
3335
self.layoutComponents()
3436
self.initEventHandlers()
37+
if len(sys.argv) == 2 and sys.argv[1] == "test-launch":
38+
wx.CallLater(500, self.testLaunch)
39+
40+
def testLaunch(self):
41+
# This hash is checked by /tests/test-launch.sh script
42+
# to detect whether CEF initialized successfully.
43+
print("b8ba7d9945c22425328df2e21fbb64cd")
44+
self.Close()
3545

3646
def initComponents(self):
3747
self.tree = wx.TreeCtrl(self, id=-1, size=(200, -1))
@@ -73,8 +83,16 @@ def OnPageClosing(self, event):
7383
def OnClose(self, event):
7484
self.Destroy()
7585

86+
7687
if __name__ == '__main__':
7788
chrome.Initialize()
89+
if platform.system() == "Linux":
90+
# CEF initialization fails intermittently on Linux during
91+
# launch of a subprocess (Issue 131). The solution is
92+
# to offload cpu for half a second after Initialize
93+
# has returned (it still runs some stuff in its thread).
94+
import time
95+
time.sleep(0.5)
7896
print('sample2.py: wx.version=%s' % wx.version())
7997
app = wx.PySimpleApp()
8098
MainFrame().Show()

cefpython/tests/test-launch.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# Usage: ./test-launch.sh 500
4+
5+
# When launching this test script more than once in current
6+
# Linux session then the CEF initialization issue is hard
7+
# to reproduce. The best results are when launching tests
8+
# in a clean Ubuntu session, just log out and log in again,
9+
# and run the test immediately. You could also run a few
10+
# terminal sessions with several test scripts running
11+
# simultaneously to simulate heavy overload.
12+
13+
for ((i = 1; i <= $1; i++)); do
14+
output=$(python ./../cef3/wx-subpackage/examples/sample2.py test-launch)
15+
code=$?
16+
if [[ $code != 0 || $output != *b8ba7d9945c22425328df2e21fbb64cd* ]]; then
17+
echo "EXIT CODE: $code"
18+
echo "OUTPUT: $output"
19+
echo "ERROR!"
20+
read -p "Press ENTER to exit"
21+
exit $code
22+
fi
23+
echo RUN $i OK
24+
done
25+
26+
echo TEST SUCCEEDED
27+
read -p "Press ENTER to exit"

0 commit comments

Comments
 (0)
X Tutup