Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: appengine/swarming/handlers_test.py

Issue 2212073002: Add endpoint and cron job to aggregate all dimensions and values (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: reuse KEY Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # coding: utf-8 2 # coding: utf-8
3 # Copyright 2013 The LUCI Authors. All rights reserved. 3 # Copyright 2013 The LUCI Authors. All rights reserved.
4 # Use of this source code is governed under the Apache License, Version 2.0 4 # Use of this source code is governed under the Apache License, Version 2.0
5 # that can be found in the LICENSE file. 5 # that can be found in the LICENSE file.
6 6
7 import datetime
7 import itertools 8 import itertools
8 import json 9 import json
9 import logging 10 import logging
10 import os 11 import os
11 import re 12 import re
12 import sys 13 import sys
13 import unittest 14 import unittest
14 import urllib 15 import urllib
15 16
16 # Setups environment. 17 # Setups environment.
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 473
473 # Only cron job requests can be gets for this handler. 474 # Only cron job requests can be gets for this handler.
474 response = self.app.get(cron_job_url, status=403) 475 response = self.app.get(cron_job_url, status=403)
475 self.assertEqual( 476 self.assertEqual(
476 '403 Forbidden\n\nAccess was denied to this resource.\n\n ' 477 '403 Forbidden\n\nAccess was denied to this resource.\n\n '
477 'Only internal cron jobs can do this ', 478 'Only internal cron jobs can do this ',
478 response.body) 479 response.body)
479 # The actual number doesn't matter, just make sure they are unqueued. 480 # The actual number doesn't matter, just make sure they are unqueued.
480 self.execute_tasks() 481 self.execute_tasks()
481 482
483
484 def testCronBotsAggregateTask(self):
485 # Tests that the aggregation works
486 now = datetime.datetime(2010, 1, 2, 3, 4, 5)
487 self.mock_now(now)
488
489 bot_management.bot_event(
490 event_type='bot_connected', bot_id='id1',
491 external_ip='8.8.4.4', authenticated_as='bot:whitelisted-ip',
492 dimensions={'foo': ['beta'], 'id': ['id1']}, state={'ram': 65},
493 version='123456789', quarantined=False, task_id=None, task_name=None)
494 bot_management.bot_event(
495 event_type='bot_connected', bot_id='id2',
496 external_ip='8.8.4.4', authenticated_as='bot:whitelisted-ip',
497 dimensions={'foo': ['alpha'], 'id': ['id2']}, state={'ram': 65},
498 version='123456789', quarantined=True, task_id='987', task_name=None)
499
500 self.app.get('/internal/cron/aggregate_bots_dimensions',
501 headers={'X-AppEngine-Cron': 'true'}, status=200)
502 aggregate = bot_management.DimensionAggregation.KEY.get()
M-A Ruel 2016/08/05 18:06:01 actual = bot_management.DimensionAggregation.KEY.g
kjlubick 2016/08/05 18:28:42 Done.
503 expected = bot_management.DimensionAggregation(
504 key=bot_management.DimensionAggregation.KEY,
M-A Ruel 2016/08/05 18:06:01 +4
kjlubick 2016/08/05 18:28:42 Done.
505 dimensions = [
M-A Ruel 2016/08/05 18:06:02 no spacing
kjlubick 2016/08/05 18:28:42 Done.
506 bot_management.DimensionValues(
507 dimension=u'foo',
M-A Ruel 2016/08/05 18:06:02 alignment is incorrect.
kjlubick 2016/08/05 18:28:42 Done.
508 values=[u'alpha',u'beta'])
509 ],
510 ts = now)
M-A Ruel 2016/08/05 18:06:02 no spacing
kjlubick 2016/08/05 18:28:42 Done.
511 self.assertEqual(expected, aggregate)
512
482 def testCronTriggerTask(self): 513 def testCronTriggerTask(self):
483 triggers = ( 514 triggers = (
484 '/internal/cron/trigger_cleanup_data', 515 '/internal/cron/trigger_cleanup_data',
485 ) 516 )
486 517
487 for url in triggers: 518 for url in triggers:
488 response = self.app.get( 519 response = self.app.get(
489 url, headers={'X-AppEngine-Cron': 'true'}, status=200) 520 url, headers={'X-AppEngine-Cron': 'true'}, status=200)
490 self.assertEqual('Success.', response.body) 521 self.assertEqual('Success.', response.body)
491 self.assertEqual(1, self.execute_tasks()) 522 self.assertEqual(1, self.execute_tasks())
(...skipping 19 matching lines...) Expand all
511 url, headers={'X-AppEngine-QueueName': 'bogus name'}, status=403) 542 url, headers={'X-AppEngine-QueueName': 'bogus name'}, status=403)
512 543
513 544
514 if __name__ == '__main__': 545 if __name__ == '__main__':
515 if '-v' in sys.argv: 546 if '-v' in sys.argv:
516 unittest.TestCase.maxDiff = None 547 unittest.TestCase.maxDiff = None
517 logging.basicConfig( 548 logging.basicConfig(
518 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL, 549 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL,
519 format='%(levelname)-7s %(filename)s:%(lineno)3d %(message)s') 550 format='%(levelname)-7s %(filename)s:%(lineno)3d %(message)s')
520 unittest.main() 551 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698