[Checkins] SVN: zc.twist/trunk/src/zc/twist/ Fix floating-point additive accumulation error in the tests.
Zvezdan Petkovic
zvezdan at zope.com
Tue Sep 29 16:01:40 EDT 2009
Log message for revision 104624:
Fix floating-point additive accumulation error in the tests.
The tests were failing 1 out of 10 times on average when run consecutively.
With this patch
./bin/test -N 1000 --all
passes without a single failure!
Changed:
U zc.twist/trunk/src/zc/twist/README.txt
U zc.twist/trunk/src/zc/twist/__init__.py
-=-
Modified: zc.twist/trunk/src/zc/twist/README.txt
===================================================================
--- zc.twist/trunk/src/zc/twist/README.txt 2009-09-29 19:13:11 UTC (rev 104623)
+++ zc.twist/trunk/src/zc/twist/README.txt 2009-09-29 20:01:40 UTC (rev 104624)
@@ -215,6 +215,10 @@
reactor; we'll use a `time_flies` function, which takes seconds to move
ahead, to simulate time passing in the reactor.
+We use powers of 2 for the floating-points numbers (e.g. 0.125) to avoid
+a floating-point additive accumulation error that happened in the tests
+when values such as 0.1 were used.
+
>>> db.setPoolSize(1)
>>> db.getPoolSize()
1
@@ -226,7 +230,7 @@
>>> d = deferred.addCallback(get_result)
>>> call.attempt_count
0
- >>> time_flies(.1) >= 1 # returns number of connection attempts
+ >>> time_flies(.125) >= 1 # returns number of connection attempts
True
>>> call.attempt_count
0
@@ -234,7 +238,7 @@
>>> db.setPoolSize(2)
>>> db.getPoolSize()
2
- >>> time_flies(.2) >= 1
+ >>> time_flies(.25) >= 1
True
>>> call.attempt_count > 0
True
@@ -256,12 +260,12 @@
>>> d = deferred.addCallback(get_result)
>>> call.attempt_count
0
- >>> time_flies(.1) >= 1
+ >>> time_flies(.125) >= 1
True
>>> call.attempt_count
0
>>> res # None
- >>> time_flies(2.0) >= 2 # for a total of at least 3
+ >>> time_flies(2) >= 2 # for a total of at least 3
True
>>> res
2
@@ -800,7 +804,7 @@
>>> d = deferred.addCallback(get_result)
>>> call.attempt_count
0
- >>> time_flies(.1) >= 1 # returns number of connection attempts
+ >>> time_flies(.125) >= 1 # returns number of connection attempts
True
>>> call.attempt_count
0
@@ -808,7 +812,7 @@
>>> db.setPoolSize(2)
>>> db.getPoolSize()
2
- >>> time_flies(.2) >= 1
+ >>> time_flies(.25) >= 1
True
>>> call.attempt_count > 0
True
@@ -830,12 +834,12 @@
>>> d = deferred.addCallback(get_result)
>>> call.attempt_count
0
- >>> time_flies(.1) >= 1
+ >>> time_flies(.125) >= 1
True
>>> call.attempt_count
0
>>> res # None
- >>> time_flies(1.9) >= 2 # for a total of at least 3
+ >>> time_flies(2) >= 2 # for a total of at least 3
True
>>> res
2
Modified: zc.twist/trunk/src/zc/twist/__init__.py
===================================================================
--- zc.twist/trunk/src/zc/twist/__init__.py 2009-09-29 19:13:11 UTC (rev 104623)
+++ zc.twist/trunk/src/zc/twist/__init__.py 2009-09-29 20:01:40 UTC (rev 104624)
@@ -96,7 +96,7 @@
def get_connection(db, deferred=None, backoff=0, reactor=None):
if deferred is None:
deferred = twisted.internet.defer.Deferred()
- backoff += random.random() / 20.0 + .05 # .05 to .10 of a second
+ backoff += random.random() / 20.0 + .0625 # 1/16 second (USE POWERS OF 2!)
# if this is taking too long (i.e., the cumulative backoff is taking
# more than half a second) then we'll just take one. This might be
# a bad idea: we'll have to see in practice. Otherwise, if the
More information about the checkins
mailing list