Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZEO
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
ZEO
Commits
75508843
Commit
75508843
authored
Sep 08, 2010
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved a test into a docstring to make a future import work.
parent
a063f8c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
108 deletions
+108
-108
src/ZEO/tests/invalidations_while_connecting.test
src/ZEO/tests/invalidations_while_connecting.test
+0
-102
src/ZEO/tests/testConnection.py
src/ZEO/tests/testConnection.py
+108
-6
No files found.
src/ZEO/tests/invalidations_while_connecting.test
deleted
100644 → 0
View file @
a063f8c5
Invalidations
while
connecting
==============================
As
soon
as
a
client
registers
with
a
server
,
it
will
recieve
invalidations
from
the
server
.
The
client
must
be
careful
to
queue
these
invalidations
until
it
is
ready
to
deal
with
them
.
At
the
time
of
the
writing
of
this
test
,
clients
weren
't careful enough about
queing invalidations. This led to cache corruption in the form of
both low-level file corruption as well as out-of-date records marked
as current.
This tests tries to provoke this bug by:
- starting a server
>>> import ZEO.tests.testZEO, ZEO.tests.forker
>>> addr = '
localhost
', ZEO.tests.testZEO.get_port()
>>> zconf = ZEO.tests.forker.ZEOConfig(addr)
>>> sconf = '
<
filestorage
1
>
\npath
Data
.
fs\n
</
filestorage
>
\n
'
>>> _, adminaddr, pid, conf_path = ZEO.tests.forker.start_zeo_server(
... sconf, zconf, addr[1])
- opening a client to the server that writes some objects, filling
it'
s
cache
at
the
same
time
,
>>>
import
ZEO
.
ClientStorage
,
ZODB
.
tests
.
MinPO
,
transaction
>>>
db
=
ZODB
.
DB
(
ZEO
.
ClientStorage
.
ClientStorage
(
addr
,
client
=
'x'
))
>>>
conn
=
db
.
open
()
>>>
nobs
=
1000
>>>
for
i
in
range
(
nobs
)
:
...
conn
.
root
()[
i
]
=
ZODB
.
tests
.
MinPO
.
MinPO
(
0
)
>>>
transaction
.
commit
()
-
disconnecting
the
first
client
(
closing
it
with
a
persistent
cache
),
>>>
db
.
close
()
-
starting
a
second
client
that
writes
objects
more
or
less
constantly
,
>>>
import
random
,
threading
,
time
>>>
stop
=
False
>>>
db2
=
ZODB
.
DB
(
ZEO
.
ClientStorage
.
ClientStorage
(
addr
))
>>>
tm
=
transaction
.
TransactionManager
()
>>>
conn2
=
db2
.
open
(
transaction_manager
=
tm
)
>>>
random
=
random
.
Random
(
0
)
>>>
lock
=
threading
.
Lock
()
>>>
def
run
()
:
...
while
1
:
...
i
=
random
.
randint
(
0
,
nobs
-
1
)
...
if
stop
:
...
return
...
with
lock
:
...
conn2
.
root
()[
i
]
.
value
+=
1
...
tm
.
commit
()
...
time
.
sleep
(
0
)
>>>
thread
=
threading
.
Thread
(
target
=
run
)
>>>
thread
.
setDaemon
(
True
)
>>>
thread
.
start
()
-
restarting
the
first
client
,
and
-
testing
for
cache
validity
.
>>>
import
zope
.
testing
.
loggingsupport
,
logging
>>>
handler
=
zope
.
testing
.
loggingsupport
.
InstalledHandler
(
...
'ZEO'
,
level
=
logging
.
ERROR
)
>>>
try
:
...
for
c
in
range
(
10
)
:
...
time
.
sleep
(
.
1
)
...
db
=
ZODB
.
DB
(
ZEO
.
ClientStorage
.
ClientStorage
(
addr
,
client
=
'x'
))
...
with
lock
:
...
@
wait_until
(
"connected and we've caught up"
,
timeout
=
199
)
...
def
_
()
:
...
return
(
db
.
storage
.
is_connected
()
...
and
db
.
storage
.
lastTransaction
()
...
==
db
.
storage
.
_server
.
lastTransaction
()
...
)
...
...
conn
=
db
.
open
()
...
for
i
in
range
(
1000
)
:
...
if
conn
.
root
()[
i
]
.
value
!=
conn2
.
root
()[
i
]
.
value
:
...
print
'bad'
,
c
,
i
,
conn
.
root
()[
i
]
.
value
,
...
print
conn2
.
root
()[
i
]
.
value
...
db
.
close
()
...
finally
:
...
stop
=
True
...
thread
.
join
(
10
)
>>>
thread
.
isAlive
()
False
>>>
for
record
in
handler
.
records
:
...
print
record
.
name
,
record
.
levelname
...
print
handler
.
format
(
record
)
>>>
handler
.
uninstall
()
>>>
db
.
close
()
>>>
db2
.
close
()
>>>
ZEO
.
tests
.
forker
.
shutdown_zeo_server
(
adminaddr
)
src/ZEO/tests/testConnection.py
View file @
75508843
...
...
@@ -16,6 +16,9 @@
The actual tests are in ConnectionTests.py; this file provides the
platform-dependent scaffolding.
"""
from
__future__
import
with_statement
from
ZEO.tests
import
ConnectionTests
,
InvalidationTests
from
zope.testing
import
setupstack
import
doctest
...
...
@@ -128,18 +131,117 @@ test_classes = [FileStorageConnectionTests,
MonitorTests
,
]
def
invalidations_while_connecting
():
r"""
As soon as a client registers with a server, it will recieve
invalidations from the server. The client must be careful to queue
these invalidations until it is ready to deal with them. At the time
of the writing of this test, clients weren't careful enough about
queing invalidations. This led to cache corruption in the form of
both low-level file corruption as well as out-of-date records marked
as current.
This tests tries to provoke this bug by:
- starting a server
>>> import ZEO.tests.testZEO, ZEO.tests.forker
>>> addr = 'localhost', ZEO.tests.testZEO.get_port()
>>> zconf = ZEO.tests.forker.ZEOConfig(addr)
>>> sconf = '<filestorage 1>\npath Data.fs\n</filestorage>\n'
>>> _, adminaddr, pid, conf_path = ZEO.tests.forker.start_zeo_server(
... sconf, zconf, addr[1])
- opening a client to the server that writes some objects, filling
it's cache at the same time,
>>> import ZEO.ClientStorage, ZODB.tests.MinPO, transaction
>>> db = ZODB.DB(ZEO.ClientStorage.ClientStorage(addr, client='x'))
>>> conn = db.open()
>>> nobs = 1000
>>> for i in range(nobs):
... conn.root()[i] = ZODB.tests.MinPO.MinPO(0)
>>> transaction.commit()
- disconnecting the first client (closing it with a persistent cache),
>>> db.close()
- starting a second client that writes objects more or less
constantly,
>>> import random, threading, time
>>> stop = False
>>> db2 = ZODB.DB(ZEO.ClientStorage.ClientStorage(addr))
>>> tm = transaction.TransactionManager()
>>> conn2 = db2.open(transaction_manager=tm)
>>> random = random.Random(0)
>>> lock = threading.Lock()
>>> def run():
... while 1:
... i = random.randint(0, nobs-1)
... if stop:
... return
... with lock:
... conn2.root()[i].value += 1
... tm.commit()
... time.sleep(0)
>>> thread = threading.Thread(target=run)
>>> thread.setDaemon(True)
>>> thread.start()
- restarting the first client, and
- testing for cache validity.
>>> import zope.testing.loggingsupport, logging
>>> handler = zope.testing.loggingsupport.InstalledHandler(
... 'ZEO', level=logging.ERROR)
>>> try:
... for c in range(10):
... time.sleep(.1)
... db = ZODB.DB(ZEO.ClientStorage.ClientStorage(addr, client='x'))
... with lock:
... @wait_until("connected and we've caught up", timeout=199)
... def _():
... return (db.storage.is_connected()
... and db.storage.lastTransaction()
... == db.storage._server.lastTransaction()
... )
...
... conn = db.open()
... for i in range(1000):
... if conn.root()[i].value != conn2.root()[i].value:
... print 'bad', c, i, conn.root()[i].value,
... print conn2.root()[i].value
... db.close()
... finally:
... stop = True
... thread.join(10)
>>> thread.isAlive()
False
>>> for record in handler.records:
... print record.name, record.levelname
... print handler.format(record)
>>> handler.uninstall()
>>> db.close()
>>> db2.close()
>>> ZEO.tests.forker.shutdown_zeo_server(adminaddr)
"""
# '
def
test_suite
():
suite
=
unittest
.
TestSuite
()
for
klass
in
test_classes
:
sub
=
unittest
.
makeSuite
(
klass
,
'check'
)
suite
.
addTest
(
sub
)
suite
.
addTest
(
doctest
.
DocFileSuite
(
'invalidations_while_connecting.test'
,
suite
.
addTest
(
doctest
.
DocTestSuite
(
setUp
=
ZEO
.
tests
.
forker
.
setUp
,
tearDown
=
setupstack
.
tearDown
,
))
suite
.
layer
=
ZODB
.
tests
.
util
.
MininalTestLayer
(
'ZEO Connection Tests'
)
return
suite
if
__name__
==
"__main__"
:
unittest
.
main
(
defaultTest
=
'test_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