Skip to content

Commit

Permalink
Fix log handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
adiroiban committed Apr 6, 2013
1 parent 04d800d commit e83b4d7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 26 deletions.
4 changes: 2 additions & 2 deletions master/buildbot/status/github.py
Expand Up @@ -211,6 +211,6 @@ def _sendGitHubStatus(self, status):
'Fail to send status "%(state)s" for '
'%(repoOwner)s/%(repoName)s at %(sha)s.'
) % status
d.addCallback(log.msg, success_message)
d.addErrback(log.err, error_message)
d.addCallback(lambda result: log.msg(success_message))
d.addErrback(lambda failure: log.err(failure, error_message))
return d
68 changes: 44 additions & 24 deletions master/buildbot/test/unit/test_status_github.py
Expand Up @@ -46,8 +46,39 @@ def tearDown(self):
len(self._logEvents),
'There are still logs not validated:\n%s' % self._logEvents,
)

pending_errors = self.flushLoggedErrors()
self.assertEqual(
0,
len(pending_errors),
'There are still errors not validated:\n%s' % pending_errors,
)

super(TestGitHubStatus, self).tearDown()

def assertLog(self, message):
"""
Check that top of the log queue has message.
"""
log_event = self._popLog()
self.assertFalse(log_event['isError'], 'Log is an error.')
self.assertEqual(
(message, ), log_event['message'], 'Wrong log message')

def assertLogError(self, message):
"""
Pop log queue and validate error message.
"""
log_event = self._popLog()
self.assertTrue(log_event['isError'], 'Log is not an error.')
self.assertEqual(message, log_event['why'], 'Wrong error message.')

def _popLog(self):
try:
return self._logEvents.pop()
except IndexError:
raise AssertionError('Log queue is empty.')

def test_initialization_required_arguments(self):
"""
Status can be initialized by only specifying GitHub API token
Expand Down Expand Up @@ -227,16 +258,11 @@ def test_getGitHubRepoProperties_skip_no_sha(self):
self.build._sha = Interpolate('')

d = self.status._getGitHubRepoProperties(self.build)

result = []
d.addCallback(result.append)
self.assertEqual({}, result[0])

# Check log.
log_event = self._logEvents.pop()
self.assertFalse(log_event['isError'])
self.assertEqual(
('GitHubStatus: No revision found.',), log_event['message'])
self.assertEqual({}, result[0])
self.assertLog('GitHubStatus: No revision found.')

def test_getGitHubRepoProperties_skip_no_owner(self):
self.status._repoOwner = Interpolate('')
Expand All @@ -255,9 +281,9 @@ def test_getGitHubRepoProperties_skip_no_name(self):
self.status._sha = Interpolate('sha')

d = self.status._getGitHubRepoProperties(self.build)

result = []
d.addCallback(result.append)

self.assertEqual({}, result[0])

def test_getGitHubRepoProperties_ok(self):
Expand All @@ -271,10 +297,11 @@ def test_getGitHubRepoProperties_ok(self):
self.status._status = Mock()
self.status._status.getURLForThing = lambda build: 'http://thing'
self.build.getNumber = lambda: 1
d = self.status._getGitHubRepoProperties(self.build)

d = self.status._getGitHubRepoProperties(self.build)
result = []
d.addCallback(result.append)

self.assertEqual({
'buildNumber': '1',
'repoName': 'name',
Expand Down Expand Up @@ -328,14 +355,10 @@ def test_sendGitHubStatus_success(self):
description='description-resum\xc3\xa9',
)

# Check log.
log_event = self._logEvents.pop()
self.assertFalse(log_event['isError'])
self.assertEqual(
(None,
u'Status "state-resum\xe9" sent for '
u'owner-resum\xe9/name-resum\xe9 at sha-resum\xe9.'),
log_event['message'])
self.assertLog(
u'Status "state-resum\xe9" sent for '
u'owner-resum\xe9/name-resum\xe9 at sha-resum\xe9.'
)

def test_sendGitHubStatus_error(self):
"""
Expand All @@ -354,12 +377,9 @@ def test_sendGitHubStatus_error(self):

self.status._sendGitHubStatus(status)

# Check error log.
log_event = self._logEvents.pop()
self.assertTrue(log_event['isError'])
self.assertEqual(
u'Fail to send status "state" for owner/name at sha.',
log_event['why'],
)
self.assertLogError(
u'Fail to send status "state" for owner/name at sha.')

# We also put the error in the error queue.
errors = self.flushLoggedErrors()
self.assertEqual(1, len(errors))

0 comments on commit e83b4d7

Please sign in to comment.