← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/garbo-feature-flags into lp:launchpad

 

William Grant has proposed merging lp:~wgrant/launchpad/garbo-feature-flags into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #937501 in Launchpad itself: "BugHeatUpdater can't see its feature flag"
  https://bugs.launchpad.net/launchpad/+bug/937501

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/garbo-feature-flags/+merge/93928

I yesterday changed the BugHeatUpdater garbo task to require a feature flag. But it turns out that it can't see the flag because garbo runs it in a thread with no feature controller.

This branch fixes garbo to install a feature controller when it starts a new thread, and adds a test that BugHeatUpdater vaguely works in a realish garbo environment.
-- 
https://code.launchpad.net/~wgrant/launchpad/garbo-feature-flags/+merge/93928
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/garbo-feature-flags into lp:launchpad.
=== modified file 'lib/lp/scripts/garbo.py'
--- lib/lp/scripts/garbo.py	2012-02-20 10:29:24 +0000
+++ lib/lp/scripts/garbo.py	2012-02-21 07:26:19 +0000
@@ -66,7 +66,11 @@
     session_store,
     sqlvalues,
     )
-from lp.services.features import getFeatureFlag
+from lp.services.features import (
+    getFeatureFlag,
+    install_feature_controller,
+    make_script_feature_controller,
+    )
 from lp.services.identity.interfaces.account import AccountStatus
 from lp.services.identity.interfaces.emailaddress import EmailAddressStatus
 from lp.services.identity.model.account import Account
@@ -1122,6 +1126,7 @@
         """
         self.logger.debug(
             "Worker thread %s running.", threading.currentThread().name)
+        install_feature_controller(make_script_feature_controller(self.name))
         self.login()
 
         while True:

=== modified file 'lib/lp/scripts/tests/test_garbo.py'
--- lib/lp/scripts/tests/test_garbo.py	2012-01-20 15:42:44 +0000
+++ lib/lp/scripts/tests/test_garbo.py	2012-02-21 07:26:19 +0000
@@ -72,6 +72,7 @@
     UTC_NOW,
     )
 from lp.services.database.lpstorm import IMasterStore
+from lp.services.features.model import FeatureFlag
 from lp.services.identity.interfaces.account import AccountStatus
 from lp.services.identity.interfaces.emailaddress import EmailAddressStatus
 from lp.services.job.model.job import Job
@@ -995,6 +996,24 @@
         self.runDaily()
         self.assertEqual(0, unreferenced_msgsets.count())
 
+    def test_BugHeatUpdater_sees_feature_flag(self):
+        # BugHeatUpdater can see its feature flag even though it's
+        # running in a thread. garbo sets up a feature controller for
+        # each worker.
+        switch_dbuser('testadmin')
+        bug = self.factory.makeBug()
+        now = datetime.now(UTC)
+        cutoff = now - timedelta(days=1)
+        old_update = now - timedelta(days=2)
+        bug.heat_last_updated = old_update
+        IMasterStore(FeatureFlag).add(FeatureFlag(
+            u'default', 0, u'bugs.heat_updates.cutoff',
+            cutoff.isoformat().decode('ascii')))
+        transaction.commit()
+        self.assertEqual(old_update, bug.heat_last_updated)
+        self.runHourly()
+        self.assertNotEqual(old_update, bug.heat_last_updated)
+
 
 class TestGarboTasks(TestCaseWithFactory):
     layer = LaunchpadZopelessLayer