Skip to content

Commit

Permalink
Merge pull request #111 from do3cc/fix_110
Browse files Browse the repository at this point in the history
Bugfix for #110
  • Loading branch information
mnaberez committed Feb 17, 2018
2 parents c7e6772 + 13f5e73 commit 7211954
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
@@ -1,6 +1,10 @@
1.1.0.dev0 (Next Release)
-------------------------

- Handle edge case for httpok check. If the timeout value is shorter
than the time to wait between retries, the httpok check never executed.
#110

1.0.0 (2016-10-02)
------------------

Expand Down
6 changes: 5 additions & 1 deletion superlance/httpok.py
Expand Up @@ -183,8 +183,12 @@ def runforever(self, test=False):
if self.eager or len(specs) > 0:

try:
# build a loop value that is guaranteed to execute at least
# once and at most until the timeout is reached and that
# has 0 as the last value (to allow raising an exception
# in the last iteration)
for will_retry in range(
self.timeout // (self.retry_time or 1) - 1 ,
(self.timeout - 1) // (self.retry_time or 1),
-1, -1):
try:
headers = {'User-Agent': 'httpok'}
Expand Down
23 changes: 20 additions & 3 deletions superlance/tests/httpok_test.py
Expand Up @@ -64,7 +64,8 @@ def _makeOne(self, *args, **kwargs):

def _makeOnePopulated(self, programs, any=None, statuses=None, inbody=None,
eager=True, gcore=None, coredir=None,
response=None, exc=None, name=None):
response=None, exc=None, name=None,
timeout=10, retry_time=0):
if statuses is None:
statuses = [200]
if response is None:
Expand All @@ -80,10 +81,10 @@ def _makeOnePopulated(self, programs, any=None, statuses=None, inbody=None,
name=name,
rpc=DummyRPCServer(),
url='http://foo/bar',
timeout=10,
timeout=timeout,
email='chrism@plope.com',
sendmail='cat - > /dev/null',
retry_time=0,
retry_time=retry_time,
)
httpok.stdin = StringIO()
httpok.stdout = StringIO()
Expand Down Expand Up @@ -380,6 +381,22 @@ def test_runforever_connrefused_error(self):
self.assertEqual(mailed[1],
'Subject: httpok: http://foo/bar: bad status returned')

def test_bug_110(self):
error = socket.error()
error.errno = 111
prog = self._makeOnePopulated(programs=['foo'], any=None,
exc=[error for x in range(100)], eager=False,
timeout=1, retry_time=10)
prog.stdin.write('eventname:TICK len:0\n')
prog.stdin.seek(0)
prog.runforever(test=True)
lines = [x for x in prog.stderr.getvalue().split('\n') if x]
self.assertEqual(lines[0],
("Restarting selected processes ['foo']")
)
self.assertEqual(lines[1], 'foo is in RUNNING state, restarting')
self.assertEqual(lines[2], 'foo restarted')

def test_subject_no_name(self):
"""set the name to None to check if subject formats to:
httpok: %(subject)s
Expand Down

0 comments on commit 7211954

Please sign in to comment.