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

Proposed by William Grant
Status: Merged
Merged at revision: 14845
Proposed branch: lp:~wgrant/launchpad/garbo-feature-flags
Merge into: lp:launchpad
Diff against target: 61 lines (+25/-1)
2 files modified
lib/lp/scripts/garbo.py (+6/-1)
lib/lp/scripts/tests/test_garbo.py (+19/-0)
To merge this branch: bzr merge lp:~wgrant/launchpad/garbo-feature-flags
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+93928@code.launchpad.net

Commit message

[r=stub][bug=937501] Install a feature controller in garbo worker threads to unbreak BugHeatUpdater.

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

A generic feature flag test would be nice (but not required), as BugHeatUpdater will change over time.

Otherwise fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/scripts/garbo.py'
2--- lib/lp/scripts/garbo.py 2012-02-20 10:29:24 +0000
3+++ lib/lp/scripts/garbo.py 2012-02-21 07:26:19 +0000
4@@ -66,7 +66,11 @@
5 session_store,
6 sqlvalues,
7 )
8-from lp.services.features import getFeatureFlag
9+from lp.services.features import (
10+ getFeatureFlag,
11+ install_feature_controller,
12+ make_script_feature_controller,
13+ )
14 from lp.services.identity.interfaces.account import AccountStatus
15 from lp.services.identity.interfaces.emailaddress import EmailAddressStatus
16 from lp.services.identity.model.account import Account
17@@ -1122,6 +1126,7 @@
18 """
19 self.logger.debug(
20 "Worker thread %s running.", threading.currentThread().name)
21+ install_feature_controller(make_script_feature_controller(self.name))
22 self.login()
23
24 while True:
25
26=== modified file 'lib/lp/scripts/tests/test_garbo.py'
27--- lib/lp/scripts/tests/test_garbo.py 2012-01-20 15:42:44 +0000
28+++ lib/lp/scripts/tests/test_garbo.py 2012-02-21 07:26:19 +0000
29@@ -72,6 +72,7 @@
30 UTC_NOW,
31 )
32 from lp.services.database.lpstorm import IMasterStore
33+from lp.services.features.model import FeatureFlag
34 from lp.services.identity.interfaces.account import AccountStatus
35 from lp.services.identity.interfaces.emailaddress import EmailAddressStatus
36 from lp.services.job.model.job import Job
37@@ -995,6 +996,24 @@
38 self.runDaily()
39 self.assertEqual(0, unreferenced_msgsets.count())
40
41+ def test_BugHeatUpdater_sees_feature_flag(self):
42+ # BugHeatUpdater can see its feature flag even though it's
43+ # running in a thread. garbo sets up a feature controller for
44+ # each worker.
45+ switch_dbuser('testadmin')
46+ bug = self.factory.makeBug()
47+ now = datetime.now(UTC)
48+ cutoff = now - timedelta(days=1)
49+ old_update = now - timedelta(days=2)
50+ bug.heat_last_updated = old_update
51+ IMasterStore(FeatureFlag).add(FeatureFlag(
52+ u'default', 0, u'bugs.heat_updates.cutoff',
53+ cutoff.isoformat().decode('ascii')))
54+ transaction.commit()
55+ self.assertEqual(old_update, bug.heat_last_updated)
56+ self.runHourly()
57+ self.assertNotEqual(old_update, bug.heat_last_updated)
58+
59
60 class TestGarboTasks(TestCaseWithFactory):
61 layer = LaunchpadZopelessLayer