Skip to content

Commit

Permalink
test and fix the return value from appendLog
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Aug 27, 2013
1 parent 1598f9c commit be204ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 4 additions & 4 deletions master/buildbot/db/logs.py
Expand Up @@ -114,17 +114,17 @@ def thd(conn):
# Break the content up into chunks. This takes advantage of the
# fact that no character but u'\n' maps to b'\n' in UTF-8.

first_line = row[0]
first_line = chunk_first_line = row[0]
remaining = content.encode('utf-8')
while remaining:
chunk, remaining = self._splitBigChunk(remaining, logid)

last_line = first_line + chunk.count('\n')
last_line = chunk_first_line + chunk.count('\n')
conn.execute(self.db.model.logchunks.insert(),
dict(logid=logid, first_line=first_line,
dict(logid=logid, first_line=chunk_first_line,
last_line=last_line, content=chunk,
compressed=0))
first_line = last_line + 1
chunk_first_line = last_line + 1

conn.execute(self.db.model.logs.update(),
whereclause=(self.db.model.logs.c.id == logid),
Expand Down
14 changes: 10 additions & 4 deletions master/buildbot/test/unit/test_db_logs.py
Expand Up @@ -203,7 +203,8 @@ def test_addLog_getLog(self):
@defer.inlineCallbacks
def test_appendLog_getLogLines(self):
yield self.insertTestData(self.backgroundData + self.testLogLines)
yield self.db.logs.appendLog(201, u'abc\ndef\n')
self.assertEqual((yield self.db.logs.appendLog(201, u'abc\ndef\n')),
(7, 8))
self.assertEqual((yield self.db.logs.getLogLines(201, 6, 7)),
u"yet another line\nabc\n")
self.assertEqual((yield self.db.logs.getLogLines(201, 7, 8)),
Expand All @@ -221,7 +222,9 @@ def test_compressLog(self):
@defer.inlineCallbacks
def test_addLogLines_big_chunk(self):
yield self.insertTestData(self.backgroundData + self.testLogLines)
yield self.db.logs.appendLog(201, u'abc\n' * 20000) # 80k
self.assertEqual(
(yield self.db.logs.appendLog(201, u'abc\n' * 20000)), # 80k
(7, 20006))
lines = yield self.db.logs.getLogLines(201, 7, 50000)
self.assertEqual(len(lines), 80000)
self.assertEqual(lines, (u'abc\n' * 20000))
Expand All @@ -230,7 +233,8 @@ def test_addLogLines_big_chunk(self):
def test_addLogLines_big_chunk_big_lines(self):
yield self.insertTestData(self.backgroundData + self.testLogLines)
line = u'x' * 33000 + '\n'
yield self.db.logs.appendLog(201, line*3)
self.assertEqual((yield self.db.logs.appendLog(201, line*3)),
(7, 9)) # three long lines, all truncated
lines = yield self.db.logs.getLogLines(201, 7, 100)
self.assertEqual(len(lines), 99003)
self.assertEqual(lines, (line*3))
Expand All @@ -241,7 +245,9 @@ class RealTests(Tests):
@defer.inlineCallbacks
def test_addLogLines_db(self):
yield self.insertTestData(self.backgroundData + self.testLogLines)
yield self.db.logs.appendLog(201, u'abc\ndef\nghi\njkl\n')
self.assertEqual(
(yield self.db.logs.appendLog(201, u'abc\ndef\nghi\njkl\n')),
(7, 10))
def thd(conn):
res = conn.execute(self.db.model.logchunks.select(
whereclause=self.db.model.logchunks.c.first_line > 6))
Expand Down

0 comments on commit be204ea

Please sign in to comment.