Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
208e5a18
Commit
208e5a18
authored
Oct 23, 2001
by
matt@zope.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added timeout validation functions
parent
0a50f515
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
135 additions
and
0 deletions
+135
-0
lib/python/Products/Transience/tests/testTimeoutRelated.py
lib/python/Products/Transience/tests/testTimeoutRelated.py
+135
-0
No files found.
lib/python/Products/Transience/tests/testTimeoutRelated.py
0 → 100644
View file @
208e5a18
import
sys
,
os
,
time
sys
.
path
.
insert
(
0
,
'..'
)
sys
.
path
.
insert
(
0
,
'../../..'
)
os
.
chdir
(
'../../..'
)
import
ZODB
# in order to get Persistence.Persistent working
from
Testing
import
makerequest
import
Acquisition
from
Acquisition
import
aq_base
from
Products.Transience.Transience
import
TransientObjectContainer
#from Products.CoreSessionTracking.SessionIdManager import SessionIdManager
#from Products.Transience.Transience import TransientObject
from
Products.Transience.Transience
import
WRITEGRANULARITY
import
Products.Transience.Transience
from
Products.PythonScripts.PythonScript
import
PythonScript
from
ZODB.POSException
import
InvalidObjectReference
from
DateTime
import
DateTime
from
unittest
import
TestCase
,
TestSuite
,
TextTestRunner
,
makeSuite
import
time
,
threading
,
whrandom
#sessionidmgr = 'session_id_mgr'
epoch
=
time
.
time
()
class
TestBase
(
TestCase
):
def
setUp
(
self
):
import
Zope
Products
.
Transience
.
Transience
.
time
=
fauxtime
self
.
app
=
makerequest
.
makerequest
(
Zope
.
app
())
del
Zope
timeout
=
self
.
timeout
=
1
#sidmgr = SessionIdManager(sessionidmgr)
sm
=
TransientObjectContainer
(
id
=
'sm'
,
timeout_mins
=
timeout
,
title
=
'SessionThing'
,
addNotification
=
onstartf
,
delNotification
=
onendf
)
#try: self.app._delObject(sessionidmgr)
#except AttributeError: pass
try
:
self
.
app
.
_delObject
(
'sm'
)
except
AttributeError
:
pass
try
:
self
.
app
.
_delObject
(
'onstartf'
)
except
AttributeError
:
pass
try
:
self
.
app_delObject
(
'onendf'
)
except
AttributeError
:
pass
#self.app._setObject(sessionidmgr, sidmgr)
self
.
app
.
_setObject
(
'sm'
,
sm
)
#onstartf = PythonScript('onstartf')
#self.app._setObject('onstartf', onstartf)
#onstartf.write('##parameters=sdo\nsdo["a"]=context.ZopeTime()')
#onstartf._makeFunction()
#onendf = PythonScript('onendf')
#self.app._setObject('onendf', onendf)
#onendf.write('##parameters=sdo\nsdo.demo()')
#onendf._makeFunction()
## admin = self.app.acl_users.getUser('admin')
## if admin is None:
## raise "Need to define an 'admin' user before running these tests"
## admin = admin.__of__(self.app.acl_users)
## self.app.sm.changeOwnership(admin)
def
tearDown
(
self
):
get_transaction
().
abort
()
self
.
app
.
_p_jar
.
close
()
self
.
app
=
None
del
self
.
app
class
TestLastAccessed
(
TestBase
):
def
testLastAccessed
(
self
):
sdo
=
self
.
app
.
sm
.
new_or_existing
(
'TempObject'
)
la1
=
sdo
.
getLastAccessed
()
fauxsleep
(
WRITEGRANULARITY
+
1
)
sdo
=
self
.
app
.
sm
[
'TempObject'
]
assert
sdo
.
getLastAccessed
()
>
la1
class
TestOnStartEnd
(
TestBase
):
def
testOnStart
(
self
):
self
.
app
.
sm
.
setAddNotificationTarget
(
onstartf
)
sdo
=
self
.
app
.
sm
.
new_or_existing
(
'TempObject'
)
now
=
fauxtime
()
k
=
sdo
.
get
(
'starttime'
)
assert
type
(
k
)
==
type
(
now
)
assert
k
<=
now
def
testOnEnd
(
self
):
self
.
app
.
sm
.
setDelNotificationTarget
(
onendf
)
sdo
=
self
.
app
.
sm
.
new_or_existing
(
'TempObject'
)
timeout
=
self
.
timeout
*
60
fauxsleep
(
timeout
+
(
timeout
*
.
33
))
try
:
sdo1
=
self
.
app
.
sm
[
'TempObject'
]
except
KeyError
:
pass
now
=
fauxtime
()
k
=
sdo
.
get
(
'endtime'
)
assert
type
(
k
)
==
type
(
now
)
assert
k
<=
now
def
onstartf
(
item
,
context
):
#print "onstartf called for %s" % item
item
[
'starttime'
]
=
fauxtime
()
def
onendf
(
item
,
context
):
#print "onendf called for %s" % item
item
[
'endtime'
]
=
fauxtime
()
def
fauxtime
():
""" False timer -- returns time 10 x faster than normal time """
return
(
time
.
time
()
-
epoch
)
*
10.0
def
fauxsleep
(
duration
):
""" False sleep -- sleep for 1/10 the time specifed """
time
.
sleep
(
duration
/
10.0
)
if
__name__
==
'__main__'
:
last_accessed
=
makeSuite
(
TestLastAccessed
,
'test'
)
start_end
=
makeSuite
(
TestOnStartEnd
,
'test'
)
runner
=
TextTestRunner
()
suite
=
TestSuite
((
start_end
,
last_accessed
))
runner
.
run
(
suite
)
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