<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12845] CalendarServer/trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/12845">12845</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-03-07 12:48:43 -0800 (Fri, 07 Mar 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Fix master-child slot counting issues.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertapcaldavpy">CalendarServer/trunk/calendarserver/tap/caldav.py</a></li>
<li><a href="#CalendarServertrunkcalendarservertaptesttest_caldavpy">CalendarServer/trunk/calendarserver/tap/test/test_caldav.py</a></li>
<li><a href="#CalendarServertrunktxweb2metafdpy">CalendarServer/trunk/txweb2/metafd.py</a></li>
<li><a href="#CalendarServertrunktxweb2testtest_metafdpy">CalendarServer/trunk/txweb2/test/test_metafd.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarservertapcaldavpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tap/caldav.py (12844 => 12845)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tap/caldav.py        2014-03-07 20:48:27 UTC (rev 12844)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py        2014-03-07 20:48:43 UTC (rev 12845)
</span><span class="lines">@@ -536,7 +536,9 @@
</span><span class="cx"> def startService(self):
</span><span class="cx"> for slaveNumber in xrange(0, config.MultiProcess.ProcessCount):
</span><span class="cx"> if config.UseMetaFD:
</span><del>- extraArgs = dict(metaSocket=self.dispatcher.addSocket())
</del><ins>+ extraArgs = dict(
+ metaSocket=self.dispatcher.addSocket(slaveNumber)
+ )
</ins><span class="cx"> else:
</span><span class="cx"> extraArgs = dict(inheritFDs=self.inheritFDs,
</span><span class="cx"> inheritSSLFDs=self.inheritSSLFDs)
</span><span class="lines">@@ -2025,7 +2027,6 @@
</span><span class="cx"> @ivar metaSocket: an AF_UNIX/SOCK_DGRAM socket (initialized from the
</span><span class="cx"> dispatcher passed to C{__init__}) that is to be inherited by the
</span><span class="cx"> subprocess and used to accept incoming connections.
</span><del>-
</del><span class="cx"> @type metaSocket: L{socket.socket}
</span><span class="cx">
</span><span class="cx"> @ivar ampSQLDispenser: a factory for AF_UNIX/SOCK_STREAM sockets that are
</span><span class="lines">@@ -2060,6 +2061,30 @@
</span><span class="cx"> self.ampDBSocket = None
</span><span class="cx">
</span><span class="cx">
</span><ins>+ def starting(self):
+ """
+ Called when the process is being started (or restarted). Allows for various initialization
+ operations to be done. The child process will itself signal back to the master when it is ready
+ to accept sockets - until then the master socket is marked as "starting" which means it is not
+ active and won't be dispatched to.
+ """
+
+ # Always tell any metafd socket that we have started, so it can re-initialize state.
+ if self.metaSocket is not None:
+ self.metaSocket.start()
+
+
+ def stopped(self):
+ """
+ Called when the process has stopped (died). The socket is marked as "stopped" which means it is
+ not active and won't be dispatched to.
+ """
+
+ # Always tell any metafd socket that we have started, so it can re-initialize state.
+ if self.metaSocket is not None:
+ self.metaSocket.stop()
+
+
</ins><span class="cx"> def getName(self):
</span><span class="cx"> return "{}-{}".format(self.prefix, self.id)
</span><span class="cx">
</span><span class="lines">@@ -2088,7 +2113,7 @@
</span><span class="cx"> fds = {}
</span><span class="cx"> extraFDs = []
</span><span class="cx"> if self.metaSocket is not None:
</span><del>- extraFDs.append(self.metaSocket.fileno())
</del><ins>+ extraFDs.append(self.metaSocket.childSocket().fileno())
</ins><span class="cx"> if self.ampSQLDispenser is not None:
</span><span class="cx"> self.ampDBSocket = self.ampSQLDispenser.dispense()
</span><span class="cx"> extraFDs.append(self.ampDBSocket.fileno())
</span><span class="lines">@@ -2150,7 +2175,7 @@
</span><span class="cx">
</span><span class="cx"> if self.metaSocket is not None:
</span><span class="cx"> args.extend([
</span><del>- "-o", "MetaFD={}".format(self.metaSocket.fileno())
</del><ins>+ "-o", "MetaFD={}".format(self.metaSocket.childSocket().fileno())
</ins><span class="cx"> ])
</span><span class="cx"> if self.ampDBSocket is not None:
</span><span class="cx"> args.extend([
</span><span class="lines">@@ -2243,6 +2268,13 @@
</span><span class="cx"> exists
</span><span class="cx"> """
</span><span class="cx"> class SimpleProcessObject(object):
</span><ins>+
+ def starting(self):
+ pass
+
+ def stopped(self):
+ pass
+
</ins><span class="cx"> def getName(self):
</span><span class="cx"> return name
</span><span class="cx">
</span><span class="lines">@@ -2334,7 +2366,10 @@
</span><span class="cx"> def processEnded(self, name):
</span><span class="cx"> """
</span><span class="cx"> When a child process has ended it calls me so I can fire the
</span><del>- appropriate deferred which was created in stopService
</del><ins>+ appropriate deferred which was created in stopService.
+
+ Also make sure to signal the dispatcher so that the socket is
+ marked as inactive.
</ins><span class="cx"> """
</span><span class="cx"> # Cancel the scheduled _forceStopProcess function if the process
</span><span class="cx"> # dies naturally
</span><span class="lines">@@ -2343,6 +2378,8 @@
</span><span class="cx"> self.murder[name].cancel()
</span><span class="cx"> del self.murder[name]
</span><span class="cx">
</span><ins>+ self.processes[name][0].stopped()
+
</ins><span class="cx"> del self.protocols[name]
</span><span class="cx">
</span><span class="cx"> if self._reactor.seconds() - self.timeStarted[name] < self.threshold:
</span><span class="lines">@@ -2429,6 +2466,8 @@
</span><span class="cx">
</span><span class="cx"> childFDs.update(procObj.getFileDescriptors())
</span><span class="cx">
</span><ins>+ procObj.starting()
+
</ins><span class="cx"> args = procObj.getCommandLine()
</span><span class="cx">
</span><span class="cx"> self._reactor.spawnProcess(
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertaptesttest_caldavpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tap/test/test_caldav.py (12844 => 12845)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tap/test/test_caldav.py        2014-03-07 20:48:27 UTC (rev 12844)
+++ CalendarServer/trunk/calendarserver/tap/test/test_caldav.py        2014-03-07 20:48:43 UTC (rev 12845)
</span><span class="lines">@@ -954,6 +954,14 @@
</span><span class="cx"> self.args = args
</span><span class="cx">
</span><span class="cx">
</span><ins>+ def starting(self):
+ pass
+
+
+ def stopped(self):
+ pass
+
+
</ins><span class="cx"> def getCommandLine(self):
</span><span class="cx"> """
</span><span class="cx"> Simple command line.
</span><span class="lines">@@ -1204,12 +1212,35 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><ins>+class FakeSubsocket(object):
+
+ def __init__(self, fakefd):
+ self.fakefd = fakefd
+
+
+ def childSocket(self):
+ return self.fakefd
+
+
+ def start(self):
+ pass
+
+
+ def restarted(self):
+ pass
+
+
+ def stop(self):
+ pass
+
+
+
</ins><span class="cx"> class FakeDispatcher(object):
</span><span class="cx"> n = 3
</span><span class="cx">
</span><span class="cx"> def addSocket(self):
</span><span class="cx"> self.n += 1
</span><del>- return FakeFD(self.n)
</del><ins>+ return FakeSubsocket(FakeFD(self.n))
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunktxweb2metafdpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txweb2/metafd.py (12844 => 12845)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txweb2/metafd.py        2014-03-07 20:48:27 UTC (rev 12844)
+++ CalendarServer/trunk/txweb2/metafd.py        2014-03-07 20:48:43 UTC (rev 12845)
</span><span class="lines">@@ -21,12 +21,11 @@
</span><span class="cx"> """
</span><span class="cx"> from __future__ import print_function
</span><span class="cx">
</span><del>-from functools import total_ordering
-
</del><span class="cx"> from zope.interface import implementer
</span><span class="cx">
</span><span class="cx"> from twext.internet.sendfdport import (
</span><del>- InheritedPort, InheritedSocketDispatcher, InheritingProtocolFactory)
</del><ins>+ InheritedPort, InheritedSocketDispatcher, InheritingProtocolFactory,
+ IStatus)
</ins><span class="cx"> from twext.internet.tcp import MaxAcceptTCPServer
</span><span class="cx"> from twext.python.log import Logger
</span><span class="cx"> from txweb2.channel.http import HTTPFactory
</span><span class="lines">@@ -164,17 +163,26 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><del>-@total_ordering
</del><ins>+@implementer(IStatus)
</ins><span class="cx"> class WorkerStatus(FancyStrMixin, object):
</span><span class="cx"> """
</span><span class="cx"> The status of a worker process.
</span><span class="cx"> """
</span><span class="cx">
</span><del>- showAttributes = ("acknowledged unacknowledged started abandoned unclosed"
</del><ins>+ showAttributes = ("acknowledged unacknowledged total started abandoned unclosed starting stopped"
</ins><span class="cx"> .split())
</span><span class="cx">
</span><del>- def __init__(self, acknowledged=0, unacknowledged=0, started=0,
- abandoned=0, unclosed=0):
</del><ins>+ def __init__(
+ self,
+ acknowledged=0,
+ unacknowledged=0,
+ total=0,
+ started=0,
+ abandoned=0,
+ unclosed=0,
+ starting=1,
+ stopped=0
+ ):
</ins><span class="cx"> """
</span><span class="cx"> Create a L{ConnectionStatus} with a number of sent connections and a
</span><span class="cx"> number of un-acknowledged connections.
</span><span class="lines">@@ -187,20 +195,32 @@
</span><span class="cx"> the subprocess which have never received a status response (a
</span><span class="cx"> "C{+}" status message).
</span><span class="cx">
</span><ins>+ @param total: The total number of acknowledged connections over
+ the lifetime of this socket.
+
+ @param started: The number of times this worker has been started.
+
</ins><span class="cx"> @param abandoned: The number of connections which have been sent to
</span><span class="cx"> this worker, but were not acknowledged at the moment that the
</span><del>- worker restarted.
</del><ins>+ worker was stopped.
</ins><span class="cx">
</span><del>- @param started: The number of times this worker has been started.
-
</del><span class="cx"> @param unclosed: The number of sockets which have been sent to the
</span><span class="cx"> subprocess but not yet closed.
</span><ins>+
+ @param starting: The process that owns this socket is starting. Do not
+ dispatch to it until we receive the started message.
+
+ @param stopped: The process that owns this socket has stopped. Do not
+ dispatch to it.
</ins><span class="cx"> """
</span><span class="cx"> self.acknowledged = acknowledged
</span><span class="cx"> self.unacknowledged = unacknowledged
</span><ins>+ self.total = total
</ins><span class="cx"> self.started = started
</span><span class="cx"> self.abandoned = abandoned
</span><span class="cx"> self.unclosed = unclosed
</span><ins>+ self.starting = starting
+ self.stopped = stopped
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def effective(self):
</span><span class="lines">@@ -210,43 +230,67 @@
</span><span class="cx"> return self.acknowledged + self.unacknowledged
</span><span class="cx">
</span><span class="cx">
</span><del>- def restarted(self):
</del><ins>+ def active(self):
</ins><span class="cx"> """
</span><del>- The L{WorkerStatus} derived from the current status of a process and
- the fact that it just restarted.
</del><ins>+ Is the subprocess associated with this socket available to dispatch to.
+ i.e, this socket is neither stopped nor starting
</ins><span class="cx"> """
</span><del>- return self.__class__(0, 0, self.started + 1, self.unacknowledged)
</del><ins>+ return self.starting == 0 and self.stopped == 0
</ins><span class="cx">
</span><span class="cx">
</span><del>- def _tuplify(self):
- return tuple(getattr(self, attr) for attr in self.showAttributes)
</del><ins>+ def start(self):
+ """
+ The child process for this L{WorkerStatus} is about to (re)start. Reset the status to indicate it
+ is starting - that should prevent any new connections being dispatched.
+ """
+ return self.reset(
+ starting=1,
+ stopped=0,
+ )
</ins><span class="cx">
</span><span class="cx">
</span><del>- def __lt__(self, other):
- if not isinstance(other, WorkerStatus):
- return NotImplemented
- return self.effective() < other.effective()
</del><ins>+ def restarted(self):
+ """
+ The child process for this L{WorkerStatus} has indicated it is now available to accept
+ connections, so reset the starting status so this socket will be available for dispatch.
+ """
+ return self.reset(
+ started=self.started + 1,
+ starting=0,
+ )
</ins><span class="cx">
</span><span class="cx">
</span><del>- def __eq__(self, other):
- if not isinstance(other, WorkerStatus):
- return NotImplemented
- return self._tuplify() == other._tuplify()
</del><ins>+ def stop(self):
+ """
+ The child process for this L{WorkerStatus} has stopped. Stop the socket and clear out
+ existing counters, but track abandoned connections.
+ """
+ return self.reset(
+ acknowledged=0,
+ unacknowledged=0,
+ abandoned=self.abandoned + self.unacknowledged,
+ starting=0,
+ stopped=1,
+ )
</ins><span class="cx">
</span><span class="cx">
</span><del>- def __add__(self, other):
- if not isinstance(other, WorkerStatus):
- return NotImplemented
- a = self._tuplify()
- b = other._tuplify()
- c = [a1 + b1 for (a1, b1) in zip(a, b)]
- return self.__class__(*c)
</del><ins>+ def adjust(self, **kwargs):
+ """
+ Update the L{WorkerStatus} by adding the supplied values to the specified attributes.
+ """
+ for k, v in kwargs.items():
+ newval = getattr(self, k) + v
+ setattr(self, k, max(newval, 0))
+ return self
</ins><span class="cx">
</span><span class="cx">
</span><del>- def __sub__(self, other):
- if not isinstance(other, WorkerStatus):
- return NotImplemented
- return self + self.__class__(*[-x for x in other._tuplify()])
</del><ins>+ def reset(self, **kwargs):
+ """
+ Reset the L{WorkerStatus} by setting the supplied values in the specified attributes.
+ """
+ for k, v in kwargs.items():
+ setattr(self, k, v)
+ return self
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -272,6 +316,7 @@
</span><span class="cx"> self.dispatcher = InheritedSocketDispatcher(self)
</span><span class="cx"> self.maxAccepts = maxAccepts
</span><span class="cx"> self.maxRequests = maxRequests
</span><ins>+ self.overloaded = False
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def startService(self):
</span><span class="lines">@@ -314,20 +359,20 @@
</span><span class="cx"> # A connection has gone away in a subprocess; we should start
</span><span class="cx"> # accepting connections again if we paused (see
</span><span class="cx"> # newConnectionStatus)
</span><del>- return previousStatus - WorkerStatus(acknowledged=1)
</del><ins>+ return previousStatus.adjust(acknowledged=-1)
+
</ins><span class="cx"> elif message == '0':
</span><del>- # A new process just started accepting new connections. It might
- # still have some unacknowledged connections, but any connections
- # that it acknowledged working on are now completed. (We have no
- # way of knowing whether the acknowledged connections were acted
- # upon or dropped, so we have to treat that number with a healthy
- # amount of skepticism.)
</del><ins>+ # A new process just started accepting new connections.
</ins><span class="cx"> return previousStatus.restarted()
</span><ins>+
</ins><span class="cx"> else:
</span><span class="cx"> # '+' acknowledges that the subprocess has taken on the work.
</span><del>- return previousStatus + WorkerStatus(acknowledged=1,
- unacknowledged=-1,
- unclosed=1)
</del><ins>+ return previousStatus.adjust(
+ acknowledged=1,
+ unacknowledged=-1,
+ total=1,
+ unclosed=1,
+ )
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def closeCountFromStatus(self, status):
</span><span class="lines">@@ -335,21 +380,22 @@
</span><span class="cx"> Determine the number of sockets to close from the current status.
</span><span class="cx"> """
</span><span class="cx"> toClose = status.unclosed
</span><del>- return (toClose, status - WorkerStatus(unclosed=toClose))
</del><ins>+ return (toClose, status.adjust(unclosed=-toClose))
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def newConnectionStatus(self, previousStatus):
</span><span class="cx"> """
</span><del>- Determine the effect of a new connection being sent on a subprocess
- socket.
</del><ins>+ A connection was just sent to the process, but not yet acknowledged.
</ins><span class="cx"> """
</span><del>- return previousStatus + WorkerStatus(unacknowledged=1)
</del><ins>+ return previousStatus.adjust(unacknowledged=1)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def statusesChanged(self, statuses):
</span><span class="cx"> """
</span><span class="cx"> The L{InheritedSocketDispatcher} is reporting that the list of
</span><del>- connection-statuses have changed.
</del><ins>+ connection-statuses have changed. Check to see if we are overloaded
+ or if there are no active processes left. If so, stop the protocol
+ factory from processing more requests until capacity is back.
</ins><span class="cx">
</span><span class="cx"> (The argument to this function is currently duplicated by the
</span><span class="cx"> C{self.dispatcher.statuses} attribute, which is what
</span><span class="lines">@@ -360,8 +406,10 @@
</span><span class="cx"> self._outstandingRequests = current # preserve for or= field in log
</span><span class="cx"> maximum = self.maxRequests
</span><span class="cx"> overloaded = (current >= maximum)
</span><ins>+ available = len(filter(lambda x: x.active(), self.dispatcher.statuses))
+ self.overloaded = (overloaded or available == 0)
</ins><span class="cx"> for f in self.factories:
</span><del>- if overloaded:
</del><ins>+ if self.overloaded:
</ins><span class="cx"> f.loadAboveMaximum()
</span><span class="cx"> else:
</span><span class="cx"> f.loadNominal()
</span></span></pre></div>
<a id="CalendarServertrunktxweb2testtest_metafdpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txweb2/test/test_metafd.py (12844 => 12845)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txweb2/test/test_metafd.py        2014-03-07 20:48:27 UTC (rev 12844)
+++ CalendarServer/trunk/txweb2/test/test_metafd.py        2014-03-07 20:48:43 UTC (rev 12845)
</span><span class="lines">@@ -71,15 +71,12 @@
</span><span class="cx"> def startReading(self):
</span><span class="cx"> "Do nothing."
</span><span class="cx">
</span><del>-
</del><span class="cx"> def stopReading(self):
</span><span class="cx"> "Do nothing."
</span><span class="cx">
</span><del>-
</del><span class="cx"> def startWriting(self):
</span><span class="cx"> "Do nothing."
</span><span class="cx">
</span><del>-
</del><span class="cx"> def stopWriting(self):
</span><span class="cx"> "Do nothing."
</span><span class="cx">
</span><span class="lines">@@ -93,19 +90,15 @@
</span><span class="cx"> def startReading(self):
</span><span class="cx"> "Do nothing."
</span><span class="cx">
</span><del>-
</del><span class="cx"> def stopReading(self):
</span><span class="cx"> "Do nothing."
</span><span class="cx">
</span><del>-
</del><span class="cx"> def startWriting(self):
</span><span class="cx"> "Do nothing."
</span><span class="cx">
</span><del>-
</del><span class="cx"> def stopWriting(self):
</span><span class="cx"> "Do nothing."
</span><span class="cx">
</span><del>-
</del><span class="cx"> def __init__(self, *a, **kw):
</span><span class="cx"> super(ServerTransportForTesting, self).__init__(*a, **kw)
</span><span class="cx"> self.reactor = None
</span><span class="lines">@@ -225,12 +218,28 @@
</span><span class="cx"> L{WorkerStatus.__repr__} will show all the values associated with the
</span><span class="cx"> status of the worker.
</span><span class="cx"> """
</span><del>- self.assertEquals(repr(WorkerStatus(1, 2, 3, 4, 5)),
- "<WorkerStatus acknowledged=1 unacknowledged=2 "
- "started=3 abandoned=4 unclosed=5>")
</del><ins>+ self.assertEquals(repr(WorkerStatus(1, 2, 3, 4, 5, 6, 7, 8)),
+ "<WorkerStatus acknowledged=1 unacknowledged=2 total=3 "
+ "started=4 abandoned=5 unclosed=6 starting=7 stopped=8>")
</ins><span class="cx">
</span><span class="cx">
</span><ins>+ def test_workerStatusNonNegative(self):
+ """
+ L{WorkerStatus.__repr__} will show all the values associated with the
+ status of the worker.
+ """
+ w = WorkerStatus()
+ w.adjust(
+ acknowledged=1,
+ unacknowledged=-1,
+ total=1,
+ )
+ self.assertEquals(w.acknowledged, 1)
+ self.assertEquals(w.unacknowledged, 0)
+ self.assertEquals(w.total, 1)
</ins><span class="cx">
</span><ins>+
+
</ins><span class="cx"> class LimiterBuilder(object):
</span><span class="cx"> """
</span><span class="cx"> A L{LimiterBuilder} can build a L{ConnectionLimiter} and associated objects
</span><span class="lines">@@ -251,7 +260,9 @@
</span><span class="cx"> self.limiter.addPortService("TCP", 4321, "127.0.0.1", 5,
</span><span class="cx"> self.serverServiceMakerMaker(self.service))
</span><span class="cx"> for ignored in xrange(socketCount):
</span><del>- self.dispatcher.addSocket()
</del><ins>+ subskt = self.dispatcher.addSocket()
+ subskt.start()
+ subskt.restarted()
</ins><span class="cx"> # Has to be running in order to add stuff.
</span><span class="cx"> self.limiter.startService()
</span><span class="cx"> self.port = self.service.myPort
</span><span class="lines">@@ -296,7 +307,7 @@
</span><span class="cx"> @param count: Amount of load to add; default to the maximum that the
</span><span class="cx"> limiter.
</span><span class="cx"> """
</span><del>- for x in range(count or self.limiter.maxRequests):
</del><ins>+ for _ignore_x in range(count or self.limiter.maxRequests):
</ins><span class="cx"> self.dispatcher.sendFileDescriptor(None, "SSL")
</span><span class="cx"> if acknowledged:
</span><span class="cx"> self.dispatcher.statusMessage(
</span><span class="lines">@@ -305,6 +316,8 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def processRestart(self):
</span><ins>+ self.dispatcher._subprocessSockets[0].stop()
+ self.dispatcher._subprocessSockets[0].start()
</ins><span class="cx"> self.dispatcher.statusMessage(
</span><span class="cx"> self.dispatcher._subprocessSockets[0], "0"
</span><span class="cx"> )
</span></span></pre>
</div>
</div>
</body>
</html>