[Buildbot-commits] buildbot/buildbot/test emitlogs.py, 1.2, 1.3 test_shell.py, 1.2, 1.3
Brian Warner
warner at users.sourceforge.net
Sun Aug 6 22:37:22 UTC 2006
Update of /cvsroot/buildbot/buildbot/buildbot/test
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv12486/buildbot/test
Modified Files:
emitlogs.py test_shell.py
Log Message:
[project @ LogFileWatcher: survive logfiles which aren't around at startup correctly]
Original author: warner at lothar.com
Date: 2006-08-06 22:34:59
Index: emitlogs.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/emitlogs.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- emitlogs.py 20 Jun 2006 08:08:58 -0000 1.2
+++ emitlogs.py 6 Aug 2006 22:37:20 -0000 1.3
@@ -1,9 +1,27 @@
#! /usr/bin/python
-import sys, time
+import sys, time, os.path, StringIO
-log2 = open("log2.out", "wt")
-log3 = open("log3.out", "wt")
+mode = 0
+if len(sys.argv) > 1:
+ mode = int(sys.argv[1])
+
+if mode == 0:
+ log2 = open("log2.out", "wt")
+ log3 = open("log3.out", "wt")
+elif mode == 1:
+ # delete the logfiles first, and wait a moment to exercise a failure path
+ if os.path.exists("log2.out"):
+ os.unlink("log2.out")
+ if os.path.exists("log3.out"):
+ os.unlink("log3.out")
+ time.sleep(2)
+ log2 = open("log2.out", "wt")
+ log3 = open("log3.out", "wt")
+elif mode == 2:
+ # don't create the logfiles at all
+ log2 = StringIO.StringIO()
+ log3 = StringIO.StringIO()
def write(i):
log2.write("this is log2 %d\n" % i)
Index: test_shell.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_shell.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- test_shell.py 20 Jun 2006 08:08:58 -0000 1.2
+++ test_shell.py 6 Aug 2006 22:37:20 -0000 1.3
@@ -35,27 +35,50 @@
lines.append("this is %s %d\n" % (filename, i))
return "".join(lines)
- def testLogFiles(self):
+ def testLogFiles_0(self):
+ return self._testLogFiles(0)
+
+ def testLogFiles_1(self):
+ return self._testLogFiles(1)
+
+ def testLogFiles_2(self):
+ return self._testLogFiles(2)
+
+ def testLogFiles_3(self):
+ return self._testLogFiles(3)
+
+ def _testLogFiles(self, mode):
basedir = "test_shell.testLogFiles"
self.setUpBuilder(basedir)
# emitlogs.py writes two lines to stdout and two logfiles, one second
# apart. Then it waits for us to write something to stdin, then it
# writes one more line.
- # we write something to the log file first, to exercise the logic
- # that distinguishes between the old file and the one as modified by
- # the ShellCommand. We set the timestamp back 5 seconds so that
- # timestamps can be used to distinguish old from new.
- log2file = os.path.join(basedir, "log2.out")
- f = open(log2file, "w")
- f.write("dummy text\n")
- f.close()
- earlier = time.time() - 5
- os.utime(log2file, (earlier, earlier))
+ if mode != 3:
+ # we write something to the log file first, to exercise the logic
+ # that distinguishes between the old file and the one as modified
+ # by the ShellCommand. We set the timestamp back 5 seconds so
+ # that timestamps can be used to distinguish old from new.
+ log2file = os.path.join(basedir, "log2.out")
+ f = open(log2file, "w")
+ f.write("dummy text\n")
+ f.close()
+ earlier = time.time() - 5
+ os.utime(log2file, (earlier, earlier))
+ if mode == 3:
+ # mode=3 doesn't create the old logfiles in the first place, but
+ # then behaves like mode=1 (where the command pauses before
+ # creating them).
+ mode = 1
+
+ # mode=1 will cause emitlogs.py to delete the old logfiles first, and
+ # then wait two seconds before creating the new files. mode=0 does
+ # not do this.
args = {
'command': [sys.executable,
- util.sibpath(__file__, "emitlogs.py")],
+ util.sibpath(__file__, "emitlogs.py"),
+ "%s" % mode],
'workdir': ".",
'logfiles': {"log2": "log2.out",
"log3": "log3.out"},
@@ -74,10 +97,14 @@
d.addCallback(self.collectUpdates)
def _check(logs):
self.failUnlessEqual(logs['stdout'], self._generateText("stdout"))
- self.failUnlessEqual(logs[('log','log2')],
- self._generateText("log2"))
- self.failUnlessEqual(logs[('log','log3')],
- self._generateText("log3"))
+ if mode == 2:
+ self.failIf(('log','log2') in logs)
+ self.failIf(('log','log3') in logs)
+ else:
+ self.failUnlessEqual(logs[('log','log2')],
+ self._generateText("log2"))
+ self.failUnlessEqual(logs[('log','log3')],
+ self._generateText("log3"))
d.addCallback(_check)
d.addBoth(self._maybePrintError)
return maybeWait(d)
More information about the Commits
mailing list