Thanks for the review, Brad, but my changes have broken an existing test
because it was calling remove_read_only_file() after calling
publication.beforeTraversal(request). That's problematic because the
mode switch can't actually happen at that point (it can only happen at
the beginning of a request) so the new assertion I added was failing.
The change below makes the new assertion conditional on a newly added
method argument, so that it can be skipped when needed.
-def remove_read_only_file():
- """Remove the file named read-only.txt from the root of the tree."""
+def remove_read_only_file(assert_mode_switch=True):
+ """Remove the file named read-only.txt from the root of the tree.
+
+ May also assert that the mode switch actually happened (i.e. not
+ is_read_only()). This assertion has to be conditional because some tests
+ will use this during the processing of a request, when a mode change can't
+ happen (i.e. is_read_only() will still return True during that request's
+ processing, even though the read-only.txt file has been removed).
+ """
os.remove(read_only_file_path)
- # Assert that the switch succeeded and make sure the mode change is
- # logged.
- assert not is_read_only(), "Switching to read-write failed."
+ if assert_mode_switch:
+ # Assert that the switch succeeded and make sure the mode change is
+ # logged.
+ assert not is_read_only(), "Switching to read-write failed."
=== modified file 'lib/canonical/launchpad/webapp/tests/test_publication.py'
--- lib/canonical/launchpad/webapp/tests/test_publication.py 2010-01-19 04:22:17 +0000
+++ lib/canonical/launchpad/webapp/tests/test_publication.py 2010-01-26 17:53:28 +0000
@@ -23,6 +23,7 @@
from canonical.launchpad.interfaces.lpstorm import IMasterStore
from canonical.launchpad.interfaces.oauth import IOAuthConsumerSet
from canonical.launchpad.ftests import ANONYMOUS, login
+from canonical.launchpad.readonly import is_read_only
from canonical.launchpad.tests.readonly import (
remove_read_only_file, touch_read_only_file)
import canonical.launchpad.webapp.adapter as dbadapter
@@ -79,6 +80,9 @@
# Cleanup needed so that further tests can start processing other
# requests (e.g. calling beforeTraversal). self.publication.endRequest(self.request, None)
+ # Force pending mode switches to actually happen and get logged so
+ # that we don't interfere with other tests.
+ assert not is_read_only()
def setUp(self): TestCase.setUp(self)
@@ -127,7 +131,10 @@ touch_read_only_file() self.publication.beforeTraversal(self.request)
finally:
- remove_read_only_file()
+ # Tell remove_read_only_file() to not assert that the mode switch
+ # actually happened, as we know it won't happen until this request
+ # is finished.
+ remove_read_only_file(assert_mode_switch=False)
# Here the mode has changed to read-only, so the stores were removed
# from zstorm.
Thanks for the review, Brad, but my changes have broken an existing test read_only_ file() after calling beforeTraversal (request) . That's problematic because the
because it was calling remove_
publication.
mode switch can't actually happen at that point (it can only happen at
the beginning of a request) so the new assertion I added was failing.
The change below makes the new assertion conditional on a newly added
method argument, so that it can be skipped when needed.
=== modified file 'lib/canonical/ launchpad/ tests/readonly. py' launchpad/ tests/readonly. py 2010-01-26 13:06:36 +0000 launchpad/ tests/readonly. py 2010-01-26 17:41:29 +0000
--- lib/canonical/
+++ lib/canonical/
@@ -31,9 +31,17 @@
assert is_read_only(), "Switching to read-only failed."
-def remove_ read_only_ file(): read_only_ file(assert_ mode_switch= True): remove( read_only_ file_path)
- """Remove the file named read-only.txt from the root of the tree."""
+def remove_
+ """Remove the file named read-only.txt from the root of the tree.
+
+ May also assert that the mode switch actually happened (i.e. not
+ is_read_only()). This assertion has to be conditional because some tests
+ will use this during the processing of a request, when a mode change can't
+ happen (i.e. is_read_only() will still return True during that request's
+ processing, even though the read-only.txt file has been removed).
+ """
os.
- # Assert that the switch succeeded and make sure the mode change is
- # logged.
- assert not is_read_only(), "Switching to read-write failed."
+ if assert_mode_switch:
+ # Assert that the switch succeeded and make sure the mode change is
+ # logged.
+ assert not is_read_only(), "Switching to read-write failed."
=== modified file 'lib/canonical/ launchpad/ webapp/ tests/test_ publication. py' launchpad/ webapp/ tests/test_ publication. py 2010-01-19 04:22:17 +0000 launchpad/ webapp/ tests/test_ publication. py 2010-01-26 17:53:28 +0000 launchpad. interfaces. lpstorm import IMasterStore launchpad. interfaces. oauth import IOAuthConsumerSet launchpad. ftests import ANONYMOUS, login launchpad. readonly import is_read_only launchpad. tests.readonly import ( read_only_ file, touch_read_ only_file) launchpad. webapp. adapter as dbadapter
self. publication. endRequest( self.request, None)
--- lib/canonical/
+++ lib/canonical/
@@ -23,6 +23,7 @@
from canonical.
from canonical.
from canonical.
+from canonical.
from canonical.
remove_
import canonical.
@@ -79,6 +80,9 @@
# Cleanup needed so that further tests can start processing other
# requests (e.g. calling beforeTraversal).
+ # Force pending mode switches to actually happen and get logged so
+ # that we don't interfere with other tests.
+ assert not is_read_only()
def setUp(self):
TestCase. setUp(self)
touch_ read_only_ file()
self. publication. beforeTraversal (self.request) read_only_ file() read_only_ file() to not assert that the mode switch read_only_ file(assert_ mode_switch= False)
@@ -127,7 +131,10 @@
finally:
- remove_
+ # Tell remove_
+ # actually happened, as we know it won't happen until this request
+ # is finished.
+ remove_
# Here the mode has changed to read-only, so the stores were removed
# from zstorm.
--
Guilherme Salgado <email address hidden>