← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~michael.nelson/launchpad/627608-p3a-token-race into lp:launchpad/devel

 

Michael Nelson has proposed merging lp:~michael.nelson/launchpad/627608-p3a-token-race into lp:launchpad/devel.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  #627608 Got a 401 on a fresh purchase
  https://bugs.launchpad.net/bugs/627608


Overview
========

This branch ensures that if a token is created *while* the generate_ppa_htaccess script is running (ie. before the script finishes), that it will be included the next time the script runs.

Details
=======
We did some work recently to improve the generate_ppa_htaccess script so that it could run minutely. That work selected only tokens that had been created since the last successful script run completed.

We recently saw bug 627608 happening again, even though the script was running minutely, and discovered that if the token is created in the tiny window *after* a run of the script has started, but before it is finished, then it won't be included in the next run either (more detailed description on the bug).

The branch does the adds a test and trivial fix, and fixes an existing test which was incorrectly setting the date_started for the script activity.

To test
=======

bin/test -vvm test_generate_ppa_htaccess

-- 
https://code.launchpad.net/~michael.nelson/launchpad/627608-p3a-token-race/+merge/39469
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~michael.nelson/launchpad/627608-p3a-token-race into lp:launchpad/devel.
=== modified file 'lib/lp/archivepublisher/scripts/generate_ppa_htaccess.py'
--- lib/lp/archivepublisher/scripts/generate_ppa_htaccess.py	2010-09-03 16:14:28 +0000
+++ lib/lp/archivepublisher/scripts/generate_ppa_htaccess.py	2010-10-27 19:19:45 +0000
@@ -260,7 +260,7 @@
         extra_expr = []
         if last_success:
             extra_expr = [
-                ArchiveAuthToken.date_created >= last_success.date_completed]
+                ArchiveAuthToken.date_created >= last_success.date_started]
 
         new_ppa_tokens = store.find(
             ArchiveAuthToken,

=== modified file 'lib/lp/archivepublisher/tests/test_generate_ppa_htaccess.py'
--- lib/lp/archivepublisher/tests/test_generate_ppa_htaccess.py	2010-10-20 20:51:26 +0000
+++ lib/lp/archivepublisher/tests/test_generate_ppa_htaccess.py	2010-10-27 19:19:45 +0000
@@ -589,13 +589,27 @@
         now = datetime.now(pytz.UTC)
         tokens = self.setupDummyTokens()[1]
         getUtility(IScriptActivitySet).recordSuccess(
-            'generate-ppa-htaccess', now, now - timedelta(minutes=3))
+            'generate-ppa-htaccess', now - timedelta(minutes=3, seconds=2),
+            now - timedelta(minutes=3))
         removeSecurityProxy(tokens[0]).date_created = (
             now - timedelta(minutes=4))
 
         script = self.getScript()
         self.assertContentEqual(tokens[1:], script.getNewTokensSinceLastRun())
 
+    def test_getNewTokensSinceLastRun_includes_tokens_during_last_run(self):
+        """Tokens created during the last ppa run will be included."""
+        now = datetime.now(pytz.UTC)
+        tokens = self.setupDummyTokens()[1]
+        getUtility(IScriptActivitySet).recordSuccess(
+            'generate-ppa-htaccess', now - timedelta(minutes=3, seconds=2),
+            now - timedelta(minutes=3))
+        removeSecurityProxy(tokens[0]).date_created = (
+            now - timedelta(minutes=3, seconds=1))
+
+        script = self.getScript()
+        self.assertContentEqual(tokens, script.getNewTokensSinceLastRun())
+
     def test_getNewTokensSinceLastRun_only_active_tokens(self):
         """Only active tokens are returned."""
         now = datetime.now(pytz.UTC)