Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Paul Graydon
erp5
Commits
446ecbd9
Commit
446ecbd9
authored
Aug 02, 2019
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
qa: make runUnitTest able to run functional tests with WSGI
parent
27268639
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
31 deletions
+83
-31
product/ERP5/bin/zopewsgi.py
product/ERP5/bin/zopewsgi.py
+25
-13
product/ERP5Type/tests/ProcessingNodeTestCase.py
product/ERP5Type/tests/ProcessingNodeTestCase.py
+58
-18
No files found.
product/ERP5/bin/zopewsgi.py
View file @
446ecbd9
...
@@ -6,7 +6,7 @@ import posixpath
...
@@ -6,7 +6,7 @@ import posixpath
import
socket
import
socket
from
tempfile
import
TemporaryFile
from
tempfile
import
TemporaryFile
import
time
import
time
from
urllib
import
quote
from
urllib
import
quote
,
splitport
from
waitress.server
import
create_server
from
waitress.server
import
create_server
import
ZConfig
import
ZConfig
...
@@ -73,7 +73,7 @@ class TransLogger(object):
...
@@ -73,7 +73,7 @@ class TransLogger(object):
self
.
logger
.
warn
(
message
)
self
.
logger
.
warn
(
message
)
def
app_wrapper
(
large_file_threshold
,
use_webdav
):
def
app_wrapper
(
large_file_threshold
=
10
<<
20
,
webdav_ports
=
()
):
try
:
try
:
from
Products.DeadlockDebugger.dumper
import
dump_threads
,
dump_url
from
Products.DeadlockDebugger.dumper
import
dump_threads
,
dump_url
except
Exception
:
except
Exception
:
...
@@ -115,7 +115,7 @@ def app_wrapper(large_file_threshold, use_webdav):
...
@@ -115,7 +115,7 @@ def app_wrapper(large_file_threshold, use_webdav):
return
[
msg
]
return
[
msg
]
new_wsgi_input
.
seek
(
0
)
new_wsgi_input
.
seek
(
0
)
if
use_webdav
:
if
int
(
environ
[
'SERVER_PORT'
])
in
webdav_ports
:
# Munge the request to ensure that we call manage_FTPGet.
# Munge the request to ensure that we call manage_FTPGet.
# Set a flag to indicate this request came through the WebDAV source
# Set a flag to indicate this request came through the WebDAV source
...
@@ -132,10 +132,22 @@ def app_wrapper(large_file_threshold, use_webdav):
...
@@ -132,10 +132,22 @@ def app_wrapper(large_file_threshold, use_webdav):
return
publish_module
(
environ
,
start_response
)
return
publish_module
(
environ
,
start_response
)
return
app
return
app
def
createServer
(
application
,
logger
,
**
kw
):
def
runwsgi
():
global
server
global
server
server
=
create_server
(
TransLogger
(
application
,
logger
=
logger
),
trusted_proxy
=
'*'
,
trusted_proxy_headers
=
(
'x-forwarded-for'
,),
clear_untrusted_proxy_headers
=
True
,
**
kw
)
if
not
hasattr
(
server
,
'addr'
):
server
.
addr
=
server
.
adj
.
listen
[
0
][
3
]
elif
not
server
.
addr
:
server
.
addr
=
server
.
sockinfo
[
3
]
return
server
def
runwsgi
():
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'-w'
,
'--webdav'
,
action
=
'store_true'
)
parser
.
add_argument
(
'-w'
,
'--webdav'
,
action
=
'store_true'
)
parser
.
add_argument
(
'address'
,
help
=
'<ip>:<port>'
)
parser
.
add_argument
(
'address'
,
help
=
'<ip>:<port>'
)
...
@@ -148,13 +160,13 @@ def runwsgi():
...
@@ -148,13 +160,13 @@ def runwsgi():
make_wsgi_app
({},
zope_conf
=
args
.
zope_conf
)
make_wsgi_app
({},
zope_conf
=
args
.
zope_conf
)
server
=
create_server
(
ip
,
port
=
splitport
(
args
.
address
)
TransLogger
(
app_wrapper
(
conf
.
large_file_threshold
,
args
.
webdav
),
port
=
int
(
port
)
logger
=
logging
.
getLogger
(
"access"
)),
createServer
(
app_wrapper
(
large_file_threshold
=
conf
.
large_file_threshold
,
webdav_ports
=
[
port
]
if
args
.
webdav
else
()),
listen
=
args
.
address
,
listen
=
args
.
address
,
logger
=
logging
.
getLogger
(
"access"
),
threads
=
conf
.
zserver_threads
,
threads
=
conf
.
zserver_threads
,
trusted_proxy
=
'*'
,
).
run
()
trusted_proxy_headers
=
(
'x-forwarded-for'
,),
clear_untrusted_proxy_headers
=
True
,
)
server
.
run
()
product/ERP5Type/tests/ProcessingNodeTestCase.py
View file @
446ecbd9
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
base64
,
errno
,
os
,
select
,
socket
,
sys
,
time
import
base64
,
errno
,
logging
,
os
,
select
,
socket
,
sys
,
time
from
threading
import
Thread
from
threading
import
Thread
from
UserDict
import
IterableUserDict
from
UserDict
import
IterableUserDict
import
Lifetime
import
Lifetime
...
@@ -8,8 +8,8 @@ from Testing import ZopeTestCase
...
@@ -8,8 +8,8 @@ from Testing import ZopeTestCase
from
ZODB.POSException
import
ConflictError
from
ZODB.POSException
import
ConflictError
from
zLOG
import
LOG
,
ERROR
from
zLOG
import
LOG
,
ERROR
from
Products.CMFActivity.Activity.Queue
import
VALIDATION_ERROR_DELAY
from
Products.CMFActivity.Activity.Queue
import
VALIDATION_ERROR_DELAY
from
Products.ERP5Type.tests.utils
import
addUserToDeveloperRole
from
Products.ERP5Type.tests.utils
import
\
from
Products.ERP5Type.tests.utils
import
createZServer
addUserToDeveloperRole
,
createZServer
,
parseListeningAddress
from
Products.CMFActivity.ActivityTool
import
getCurrentNode
from
Products.CMFActivity.ActivityTool
import
getCurrentNode
...
@@ -141,23 +141,63 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
...
@@ -141,23 +141,63 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
if
utils
.
_Z2HOST
is
None
:
if
utils
.
_Z2HOST
is
None
:
from
Products.ERP5Type.tests.runUnitTest
import
tests_home
from
Products.ERP5Type.tests.runUnitTest
import
tests_home
log
=
os
.
path
.
join
(
tests_home
,
"Z2.log"
)
log
=
os
.
path
.
join
(
tests_home
,
"Z2.log"
)
_print
=
lambda
hs
:
verbose
and
ZopeTestCase
.
_print
(
message
=
"Running %s server at %s:%s
\
n
"
"Running %s server at %s:%s
\
n
"
%
(
if
int
(
os
.
environ
.
get
(
'erp5_wsgi'
,
0
)):
hs
.
server_protocol
,
hs
.
server_name
,
hs
.
server_port
))
from
Products.ERP5.bin.zopewsgi
import
app_wrapper
,
createServer
try
:
sockets
=
[]
hs
=
createZServer
(
log
)
server_type
=
'HTTP'
except
RuntimeError
,
e
:
zserver
=
os
.
environ
.
get
(
'zserver'
)
ZopeTestCase
.
_print
(
str
(
e
))
try
:
for
ip
,
port
in
parseListeningAddress
(
zserver
):
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
try
:
s
.
bind
((
ip
,
port
))
except
socket
.
error
as
e
:
s
.
close
()
if
e
[
0
]
!=
errno
.
EADDRINUSE
:
raise
if
zserver
:
raise
RuntimeError
(
str
(
e
))
else
:
if
sockets
:
webdav_ports
=
port
,
else
:
webdav_ports
=
()
sockets
.
append
(
s
)
ZopeTestCase
.
_print
(
message
%
(
server_type
,
ip
,
port
))
if
webdav_ports
:
break
server_type
=
'WebDAV'
except
RuntimeError
as
e
:
ZopeTestCase
.
_print
(
'Could not start %s server: %s
\
n
'
%
(
server_type
,
e
))
if
sockets
:
logger
=
logging
.
getLogger
(
"access"
)
logger
.
addHandler
(
logging
.
FileHandler
(
log
))
logger
.
propagate
=
False
hs
=
createServer
(
app_wrapper
(
webdav_ports
=
webdav_ports
),
logger
,
sockets
=
sockets
)
utils
.
_Z2HOST
,
utils
.
_Z2PORT
=
hs
.
addr
t
=
Thread
(
target
=
hs
.
run
)
t
.
setDaemon
(
1
)
t
.
start
()
else
:
else
:
utils
.
_Z2HOST
,
utils
.
_Z2PORT
=
hs
.
server_name
,
hs
.
server_port
_print
=
lambda
hs
:
verbose
and
ZopeTestCase
.
_print
(
_print
(
hs
)
message
%
(
hs
.
server_protocol
,
hs
.
server_name
,
hs
.
server_port
)
)
try
:
try
:
_print
(
createZServer
(
log
,
zserver_type
=
'webdav'
))
hs
=
createZServer
(
log
)
except
RuntimeError
,
e
:
except
RuntimeError
as
e
:
ZopeTestCase
.
_print
(
'Could not start webdav zserver: %s
\
n
'
%
e
)
ZopeTestCase
.
_print
(
str
(
e
))
t
=
Thread
(
target
=
Lifetime
.
loop
)
else
:
t
.
setDaemon
(
1
)
utils
.
_Z2HOST
,
utils
.
_Z2PORT
=
hs
.
server_name
,
hs
.
server_port
t
.
start
()
_print
(
hs
)
try
:
_print
(
createZServer
(
log
,
zserver_type
=
'webdav'
))
except
RuntimeError
as
e
:
ZopeTestCase
.
_print
(
'Could not start webdav zserver: %s
\
n
'
%
e
)
t
=
Thread
(
target
=
Lifetime
.
loop
)
t
.
setDaemon
(
1
)
t
.
start
()
from
Products.CMFActivity
import
ActivityTool
from
Products.CMFActivity
import
ActivityTool
# Reset, in case that getServerAddress was already called,
# Reset, in case that getServerAddress was already called,
# in which case, the value was ('', '')
# in which case, the value was ('', '')
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment