Changeset 108094 in webkit


Ignore:
Timestamp:
Feb 17, 2012 10:47:05 AM (12 years ago)
Author:
rniwa@webkit.org
Message:

perf-o-matic needs model unit tests
https://bugs.webkit.org/show_bug.cgi?id=78885

Reviewed by Adam Barth.

Added unit tests for models.py.

Also renamed modelFromNumericId to model_from_numeric_id and moved set_persitent_cache and get_persistent_cache
from controller to PersistentCache.set_cache and PersistentCahce.set_cache respectively.

  • Websites/webkit-perf.appspot.com/controller.py:

(cache_manifest):
(CachedManifestHandler.get):
(cache_dashboard):
(CachedDashboardHandler.get):
(cache_runs):
(CachedRunsHandler.get):

  • Websites/webkit-perf.appspot.com/create_handler.py:

(CreateHandler._create_builder):
(CreateHandler._create_builder.execute):

  • Websites/webkit-perf.appspot.com/models.py:

(create_in_transaction_with_numeric_id_holder):
(model_from_numeric_id):
(Builder):
(Builder.create):
(Builder.update_password):
(Builder._hashed_password):
(TestResult.key_name):
(ReportLog.get_value):
(ReportLog._integer_in_payload):
(ReportLog):
(ReportLog.timestamp):
(PersistentCache):
(PersistentCache.set_cache):
(PersistentCache.set_cache.execute):
(PersistentCache.get_cache):

  • Websites/webkit-perf.appspot.com/models_unittest.py: Added.

(HelperTests):
(HelperTests.setUp):
(HelperTests.tearDown):
(HelperTests._assert_there_is_exactly_one_id_holder_and_matches):
(HelperTests.test_create_in_transaction_with_numeric_id_holder):
(HelperTests.test_create_in_transaction_with_numeric_id_holder.execute):
(HelperTests.test_failing_in_create_in_transaction_with_numeric_id_holder):
(HelperTests.test_failing_in_create_in_transaction_with_numeric_id_holder.execute):
(HelperTests.test_raising_in_create_in_transaction_with_numeric_id_holder):
(HelperTests.test_raising_in_create_in_transaction_with_numeric_id_holder.execute):
(HelperTests.test_delete_model_with_numeric_id_holder):
(HelperTests.test_delete_model_with_numeric_id_holder.execute):
(HelperTests.test_model_from_numeric_id):
(HelperTests.test_model_from_numeric_id.execute):
(BuilderTests):
(BuilderTests.setUp):
(BuilderTests.tearDown):
(BuilderTests.test_create):
(BuilderTests.test_update_password):
(BuilderTests.test_hashed_password):
(BuilderTests.test_authenticate):
(ReportLog):
(ReportLog.setUp):
(ReportLog.tearDown):
(ReportLog._create_log_with_payload):
(ReportLog.test_parsed_payload):
(ReportLog.test_get_value):
(ReportLog.test_results):
(ReportLog.test_builder):
(ReportLog.test_build_number):
(ReportLog.test_webkit_revision):
(ReportLog.chromium_revision):
(PersistentCacheTests):
(PersistentCacheTests.setUp):
(PersistentCacheTests.tearDown):
(PersistentCacheTests._assert_persistent_cache):
(PersistentCacheTests.test_set):
(PersistentCacheTests.test_get):

  • Websites/webkit-perf.appspot.com/runs_handler.py:

(RunsHandler.post):

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r108053 r108094  
     12012-02-17  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        perf-o-matic needs model unit tests
     4        https://bugs.webkit.org/show_bug.cgi?id=78885
     5
     6        Reviewed by Adam Barth.
     7
     8        Added unit tests for models.py.
     9
     10        Also renamed modelFromNumericId to model_from_numeric_id and moved set_persitent_cache and get_persistent_cache
     11        from controller to PersistentCache.set_cache and PersistentCahce.set_cache respectively.
     12
     13        * Websites/webkit-perf.appspot.com/controller.py:
     14        (cache_manifest):
     15        (CachedManifestHandler.get):
     16        (cache_dashboard):
     17        (CachedDashboardHandler.get):
     18        (cache_runs):
     19        (CachedRunsHandler.get):
     20        * Websites/webkit-perf.appspot.com/create_handler.py:
     21        (CreateHandler._create_builder):
     22        (CreateHandler._create_builder.execute):
     23        * Websites/webkit-perf.appspot.com/models.py:
     24        (create_in_transaction_with_numeric_id_holder):
     25        (model_from_numeric_id):
     26        (Builder):
     27        (Builder.create):
     28        (Builder.update_password):
     29        (Builder._hashed_password):
     30        (TestResult.key_name):
     31        (ReportLog.get_value):
     32        (ReportLog._integer_in_payload):
     33        (ReportLog):
     34        (ReportLog.timestamp):
     35        (PersistentCache):
     36        (PersistentCache.set_cache):
     37        (PersistentCache.set_cache.execute):
     38        (PersistentCache.get_cache):
     39        * Websites/webkit-perf.appspot.com/models_unittest.py: Added.
     40        (HelperTests):
     41        (HelperTests.setUp):
     42        (HelperTests.tearDown):
     43        (HelperTests._assert_there_is_exactly_one_id_holder_and_matches):
     44        (HelperTests.test_create_in_transaction_with_numeric_id_holder):
     45        (HelperTests.test_create_in_transaction_with_numeric_id_holder.execute):
     46        (HelperTests.test_failing_in_create_in_transaction_with_numeric_id_holder):
     47        (HelperTests.test_failing_in_create_in_transaction_with_numeric_id_holder.execute):
     48        (HelperTests.test_raising_in_create_in_transaction_with_numeric_id_holder):
     49        (HelperTests.test_raising_in_create_in_transaction_with_numeric_id_holder.execute):
     50        (HelperTests.test_delete_model_with_numeric_id_holder):
     51        (HelperTests.test_delete_model_with_numeric_id_holder.execute):
     52        (HelperTests.test_model_from_numeric_id):
     53        (HelperTests.test_model_from_numeric_id.execute):
     54        (BuilderTests):
     55        (BuilderTests.setUp):
     56        (BuilderTests.tearDown):
     57        (BuilderTests.test_create):
     58        (BuilderTests.test_update_password):
     59        (BuilderTests.test_hashed_password):
     60        (BuilderTests.test_authenticate):
     61        (ReportLog):
     62        (ReportLog.setUp):
     63        (ReportLog.tearDown):
     64        (ReportLog._create_log_with_payload):
     65        (ReportLog.test_parsed_payload):
     66        (ReportLog.test_get_value):
     67        (ReportLog.test_results):
     68        (ReportLog.test_builder):
     69        (ReportLog.test_build_number):
     70        (ReportLog.test_webkit_revision):
     71        (ReportLog.chromium_revision):
     72        (PersistentCacheTests):
     73        (PersistentCacheTests.setUp):
     74        (PersistentCacheTests.tearDown):
     75        (PersistentCacheTests._assert_persistent_cache):
     76        (PersistentCacheTests.test_set):
     77        (PersistentCacheTests.test_get):
     78        * Websites/webkit-perf.appspot.com/runs_handler.py:
     79        (RunsHandler.post):
     80
    1812012-02-17  Carlos Garcia Campos  <cgarcia@igalia.com>
    282
  • trunk/Websites/webkit-perf.appspot.com/controller.py

    r107590 r108094  
    2929
    3030import webapp2
    31 from google.appengine.api import memcache
    3231from google.appengine.api import taskqueue
    3332from google.appengine.ext import db
     
    3736
    3837
    39 def set_persistent_cache(name, value):
    40     memcache.set(name, value)
    41 
    42     def execute():
    43         cache = PersistentCache.get_by_key_name(name)
    44         if cache:
    45             cache.value = value
    46             cache.put()
    47         else:
    48             PersistentCache(key_name=name, value=value).put()
    49 
    50     db.run_in_transaction(execute)
    51 
    52 
    53 def get_persistent_cache(name):
    54     value = memcache.get(name)
    55     if value:
    56         return value
    57     cache = PersistentCache.get_by_key_name(name)
    58     memcache.set(name, cache.value)
    59     return cache.value
    60 
    61 
    6238def cache_manifest(cache):
    63     set_persistent_cache('manifest', cache)
     39    PersistentCache.set_cache('manifest', cache)
    6440
    6541
     
    7147    def get(self):
    7248        self.response.headers['Content-Type'] = 'application/json'
    73         manifest = get_persistent_cache('manifest')
     49        manifest = PersistentCache.get_cache('manifest')
    7450        if manifest:
    7551            self.response.out.write(manifest)
     
    7955
    8056def cache_dashboard(cache):
    81     set_persistent_cache('dashboard', cache)
     57    PersistentCache.set_cache('dashboard', cache)
    8258
    8359
     
    8965    def get(self):
    9066        self.response.headers['Content-Type'] = 'application/json'
    91         dashboard = get_persistent_cache('dashboard')
     67        dashboard = PersistentCache.get_cache('dashboard')
    9268        if dashboard:
    9369            self.response.out.write(dashboard)
     
    9773
    9874def cache_runs(test_id, branch_id, platform_id, cache):
    99     set_persistent_cache(Test.cache_key(test_id, branch_id, platform_id), cache)
     75    PersistentCache.set_cache(Test.cache_key(test_id, branch_id, platform_id), cache)
    10076
    10177
     
    11894            platform_id = 0
    11995
    120         runs = get_persistent_cache(Test.cache_key(test_id, branch_id, platform_id))
     96        runs = PersistentCache.get_cache(Test.cache_key(test_id, branch_id, platform_id))
    12197        if runs:
    12298            self.response.out.write(runs)
  • trunk/Websites/webkit-perf.appspot.com/create_handler.py

    r107274 r108094  
    7171            return 'Invalid name or password'
    7272
    73         password = Builder.hashed_password(password)
    74 
    7573        def execute():
    7674            message = None
     
    7876            if bot:
    7977                message = 'Updating the password since bot "%s" already exists' % name
    80                 bot.password = password
     78                bot.update_password(password)
    8179            else:
    82                 bot = Builder(name=name, password=password, key_name=name)
    83             bot.put()
     80                Builder.create(name, password)
    8481            return message
    8582
  • trunk/Websites/webkit-perf.appspot.com/models.py

    r107531 r108094  
    3434from datetime import datetime
    3535from google.appengine.ext import db
     36from google.appengine.api import memcache
    3637
    3738
     
    4546    id_holder.put()
    4647    id_holder = NumericIdHolder.get(id_holder.key())
    47     owner = db.run_in_transaction(callback, id_holder.key().id())
    48     if owner:
    49         id_holder.owner = owner
    50         id_holder.put()
    51     else:
    52         id_holder.delete()
     48    owner = None
     49    try:
     50        owner = db.run_in_transaction(callback, id_holder.key().id())
     51        if owner:
     52            id_holder.owner = owner
     53            id_holder.put()
     54    finally:
     55        if not owner:
     56            id_holder.delete()
    5357    return owner
    5458
     
    6064
    6165
    62 def modelFromNumericId(id, expected_kind):
     66def model_from_numeric_id(id, expected_kind):
    6367    id_holder = NumericIdHolder.get_by_id(id)
    6468    return id_holder.owner if id_holder and id_holder.owner and isinstance(id_holder.owner, expected_kind) else None
     
    7983    password = db.StringProperty(required=True)
    8084
     85    @staticmethod
     86    def create(name, raw_password):
     87        return Builder(name=name, password=Builder._hashed_password(raw_password), key_name=name).put()
     88
     89    def update_password(self, raw_password):
     90        self.password = Builder._hashed_password(raw_password)
     91        self.put()
     92
    8193    def authenticate(self, raw_password):
    8294        return self.password == hashlib.sha256(raw_password).hexdigest()
    8395
    8496    @staticmethod
    85     def hashed_password(raw_password):
     97    def _hashed_password(raw_password):
    8698        return hashlib.sha256(raw_password).hexdigest()
    8799
     
    123135
    124136
    125 # Temporarily store log reports sent by bots
    126137class ReportLog(db.Model):
    127138    timestamp = db.DateTimeProperty(required=True)
     
    141152        if not self._parsed_payload():
    142153            return None
    143         return self._parsed.get(keyName, '')
     154        return self._parsed.get(keyName)
    144155
    145156    def results(self):
     
    173184        try:
    174185            return int(self.get_value(keyName))
     186        except TypeError:
     187            return None
    175188        except ValueError:
    176189            return None
    177190
     191    # FIXME: We also have timestamp as a member variable.
    178192    def timestamp(self):
    179193        try:
     
    185199
    186200
    187 # Used when memcache entry is evicted
    188201class PersistentCache(db.Model):
    189202    value = db.TextProperty(required=True)
     203
     204    @staticmethod
     205    def set_cache(name, value):
     206        memcache.set(name, value)
     207
     208        def execute():
     209            cache = PersistentCache.get_by_key_name(name)
     210            if cache:
     211                cache.value = value
     212                cache.put()
     213            else:
     214                PersistentCache(key_name=name, value=value).put()
     215
     216        db.run_in_transaction(execute)
     217
     218    @staticmethod
     219    def get_cache(name):
     220        value = memcache.get(name)
     221        if value:
     222            return value
     223        cache = PersistentCache.get_by_key_name(name)
     224        if not cache:
     225            return None
     226        memcache.set(name, cache.value)
     227        return cache.value
  • trunk/Websites/webkit-perf.appspot.com/runs_handler.py

    r107274 r108094  
    4242from models import Test
    4343from models import TestResult
    44 from models import modelFromNumericId
     44from models import model_from_numeric_id
    4545
    4646
     
    6363
    6464        builds = Build.all()
    65         builds.filter('branch =', modelFromNumericId(branch_id, Branch))
    66         builds.filter('platform =', modelFromNumericId(platform_id, Platform))
     65        builds.filter('branch =', model_from_numeric_id(branch_id, Branch))
     66        builds.filter('platform =', model_from_numeric_id(platform_id, Platform))
    6767
    68         test = modelFromNumericId(test_id, Test)
     68        test = model_from_numeric_id(test_id, Test)
    6969        test_name = test.name if test else None
    7070        test_runs = []
Note: See TracChangeset for help on using the changeset viewer.