diff options
author | Michael Cahill <michael.cahill@wiredtiger.com> | 2013-07-11 16:52:04 +1000 |
---|---|---|
committer | Michael Cahill <michael.cahill@wiredtiger.com> | 2013-07-11 16:52:04 +1000 |
commit | c495977b9a99c8363c35e91d65810205f8da57a3 (patch) | |
tree | b75bfeb379ac00b221429d552ae5abd5629ef41b | |
parent | 654b9c2b932df7b5e48a52265935ccb3580d92d9 (diff) | |
download | mongo-c495977b9a99c8363c35e91d65810205f8da57a3.tar.gz |
Fix a race manipulating file descriptors in the test suite. Always close the connection before closing redirected stdout and stderr. Make sure the connection and redirected files are both closed if a test fails.
-rw-r--r-- | test/suite/suite_subprocess.py | 12 | ||||
-rw-r--r-- | test/suite/wttest.py | 23 |
2 files changed, 20 insertions, 15 deletions
diff --git a/test/suite/suite_subprocess.py b/test/suite/suite_subprocess.py index d9657bcdd85..f7cbddf232b 100644 --- a/test/suite/suite_subprocess.py +++ b/test/suite/suite_subprocess.py @@ -142,14 +142,12 @@ class suite_subprocess: print "*********************************************" print "**** Run 'wt' via: run " + " ".join(procargs[3:]) + infilepart + ">" + wtoutname + " 2>" + wterrname print "*********************************************" - proc = subprocess.Popen(procargs) + subprocess.call(procargs) + elif infilename: + with open(infilename, "r") as wtin: + subprocess.call(procargs, stdin=wtin, stdout=wtout, stderr=wterr) else: - if infilename != None: - with open(infilename, "r") as wtin: - proc = subprocess.Popen(procargs, stdin=wtin, stdout=wtout, stderr=wterr) - else: - proc = subprocess.Popen(procargs, stdout=wtout, stderr=wterr) - proc.wait() + subprocess.call(procargs, stdout=wtout, stderr=wterr) if errfilename == None: self.check_empty_file(wterrname) if outfilename == None: diff --git a/test/suite/wttest.py b/test/suite/wttest.py index 2e5234fd7cb..32808011d9d 100644 --- a/test/suite/wttest.py +++ b/test/suite/wttest.py @@ -95,7 +95,8 @@ class CapturedFd(object): in the constructor. """ filefd = os.open(self.filename, os.O_RDWR | os.O_CREAT | os.O_APPEND) - os.close(self.targetFd) + if filefd < 0: + raise Exception(self.testdir + ": cannot remove directory") os.dup2(filefd, self.targetFd) os.close(filefd) @@ -103,8 +104,8 @@ class CapturedFd(object): """ Stop capturing. Restore the original fd from the duped copy. """ - os.close(self.targetFd) - os.dup2(self.originalDupedFd, self.targetFd) + if self.originalDupedFd >= 0: + os.dup2(self.originalDupedFd, self.targetFd) def show(self, pfx=None): contents = self.readFileFrom(self.filename, 0, 1000) @@ -264,23 +265,29 @@ class WiredTigerTestCase(unittest.TestCase): if os.path.exists(self.testdir): raise Exception(self.testdir + ": cannot remove directory") os.makedirs(self.testdir) + os.chdir(self.testdir) + self.fdSetUp() + # tearDown needs a conn field, set it here in case the open fails. + self.conn = None try: - os.chdir(self.testdir) - self.fdSetUp() self.conn = self.setUpConnectionOpen(".") self.session = self.setUpSessionOpen(self.conn) except: - os.chdir(self.origcwd) + self.tearDown() raise def tearDown(self): excinfo = sys.exc_info() passed = (excinfo == (None, None, None)) + self.pr('finishing') try: - self.fdTearDown() - self.pr('finishing') self.close_conn() + except: + pass + + try: + self.fdTearDown() # Only check for unexpected output if the test passed if passed: self.captureout.check(self) |