~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/scripts/tests/test_garbo.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-12 21:08:41 UTC
  • mfrom: (8758.3.25 garbo)
  • Revision ID: launchpad@pqm.canonical.com-20110912210841-qyag5sunk3vo01we
[r=bac][bug=795305] Add garbo-frequently for every 5 mins tasks,
        reduce transaction target to 2 seconds,
        rollup bugsummary journal in garbo-grequently.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    Storm,
27
27
    )
28
28
from storm.store import Store
 
29
from testtools.matchers import (
 
30
    Equals,
 
31
    GreaterThan,
 
32
    )
29
33
import transaction
30
34
from zope.component import getUtility
31
35
from zope.security.proxy import removeSecurityProxy
85
89
    BulkPruner,
86
90
    DailyDatabaseGarbageCollector,
87
91
    DuplicateSessionPruner,
 
92
    FrequentDatabaseGarbageCollector,
88
93
    HourlyDatabaseGarbageCollector,
89
94
    OpenIDConsumerAssociationPruner,
90
95
    UnusedSessionPruner,
370
375
        # starting us in a known state.
371
376
        self.runDaily()
372
377
        self.runHourly()
 
378
        self.runFrequently()
373
379
 
374
380
        # Capture garbo log output to tests can examine it.
375
381
        self.log_buffer = StringIO()
376
382
        handler = logging.StreamHandler(self.log_buffer)
377
383
        self.log.addHandler(handler)
378
384
 
 
385
    def runFrequently(self, maximum_chunk_size=2, test_args=()):
 
386
        transaction.commit()
 
387
        LaunchpadZopelessLayer.switchDbUser('garbo_daily')
 
388
        collector = FrequentDatabaseGarbageCollector(
 
389
            test_args=list(test_args))
 
390
        collector._maximum_chunk_size = maximum_chunk_size
 
391
        collector.logger = self.log
 
392
        collector.main()
 
393
        return collector
 
394
 
379
395
    def runDaily(self, maximum_chunk_size=2, test_args=()):
380
396
        transaction.commit()
381
397
        LaunchpadZopelessLayer.switchDbUser('garbo_daily')
417
433
        # Make sure we have 4 nonces now.
418
434
        self.failUnlessEqual(store.find(OAuthNonce).count(), 4)
419
435
 
420
 
        self.runHourly(maximum_chunk_size=60)  # 1 minute maximum chunk size
 
436
        self.runFrequently(
 
437
            maximum_chunk_size=60)  # 1 minute maximum chunk size
421
438
 
422
439
        store = IMasterStore(OAuthNonce)
423
440
 
460
477
        self.failUnlessEqual(store.find(OpenIDConsumerNonce).count(), 4)
461
478
 
462
479
        # Run the garbage collector.
463
 
        self.runHourly(maximum_chunk_size=60)  # 1 minute maximum chunks.
 
480
        self.runFrequently(maximum_chunk_size=60)  # 1 minute maximum chunks.
464
481
 
465
482
        store = IMasterStore(OpenIDConsumerNonce)
466
483
 
583
600
 
584
601
        # Expire all those expirable rows, and possibly a few more if this
585
602
        # test is running slow.
586
 
        self.runHourly()
 
603
        self.runFrequently()
587
604
 
588
605
        LaunchpadZopelessLayer.switchDbUser('testadmin')
589
606
        store = store_selector.get(MAIN_STORE, MASTER_FLAVOR)
947
964
 
948
965
        self.assertEqual(1, count)
949
966
 
 
967
    def test_BugSummaryJournalRollup(self):
 
968
        LaunchpadZopelessLayer.switchDbUser('testadmin')
 
969
        store = getUtility(IStoreSelector).get(MAIN_STORE, MASTER_FLAVOR)
 
970
 
 
971
        # Generate a load of entries in BugSummaryJournal.
 
972
        store.execute("UPDATE BugTask SET status=42")
 
973
 
 
974
        # We only need a few to test.
 
975
        num_rows = store.execute(
 
976
            "SELECT COUNT(*) FROM BugSummaryJournal").get_one()[0]
 
977
        self.assertThat(num_rows, GreaterThan(10))
 
978
 
 
979
        self.runFrequently()
 
980
 
 
981
        # We just care that the rows have been removed. The bugsummary
 
982
        # tests confirm that the rollup stored method is working correctly.
 
983
        num_rows = store.execute(
 
984
            "SELECT COUNT(*) FROM BugSummaryJournal").get_one()[0]
 
985
        self.assertThat(num_rows, Equals(0))
 
986
 
950
987
    def test_UnusedPOTMsgSetPruner_removes_obsolete_message_sets(self):
951
988
        # UnusedPOTMsgSetPruner removes any POTMsgSet that are
952
989
        # participating in a POTemplate only as obsolete messages.