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

Unified Diff: appengine/swarming/handlers_endpoints_test.py

Issue 2198063002: Add bots.count endpoint (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: Run them in parallel Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: appengine/swarming/handlers_endpoints_test.py
diff --git a/appengine/swarming/handlers_endpoints_test.py b/appengine/swarming/handlers_endpoints_test.py
index eae4523c1a80438455bda3556a35174e9b191289..2eac327fcc0b01300f76b1b91058a6fcfeb8c558 100755
--- a/appengine/swarming/handlers_endpoints_test.py
+++ b/appengine/swarming/handlers_endpoints_test.py
@@ -1422,6 +1422,74 @@ class BotsApiTest(BaseTest):
request = swarming_rpcs.BotsRequest(dimensions=['bad'])
self.call_api('list', body=message_to_dict(request), status=400)
+ def test_count_ok(self):
+ """Asserts that BotsCount is returned for the appropriate set of bots."""
+ self.set_as_privileged_user()
+ self.mock_now(datetime.datetime(2009, 1, 2, 3, 4, 5, 6))
+ bot_management.bot_event(
+ event_type='bot_connected', bot_id='id3',
+ external_ip='8.8.4.4', authenticated_as='bot:whitelisted-ip',
+ dimensions={'foo': ['bar'], 'id': ['id3']}, state={'ram': 65},
+ version='123456789', quarantined=True, task_id=None, task_name=None)
+ now = datetime.datetime(2010, 1, 2, 3, 4, 5, 6)
+ self.mock_now(now)
+ bot_management.bot_event(
+ event_type='bot_connected', bot_id='id1',
+ external_ip='8.8.4.4', authenticated_as='bot:whitelisted-ip',
+ dimensions={'foo': ['bar'], 'id': ['id1']}, state={'ram': 65},
+ version='123456789', quarantined=False, task_id=None, task_name=None)
+ bot_management.bot_event(
+ event_type='bot_connected', bot_id='id2',
+ external_ip='8.8.4.4', authenticated_as='bot:whitelisted-ip',
+ dimensions={'foo': ['bar'], 'id': ['id2']}, state={'ram': 65},
+ version='123456789', quarantined=True, task_id='987', task_name=None)
+ expected = {
+ u'count': unicode(3),
M-A Ruel 2016/08/01 19:18:37 Use actual values, it's shorter, e.g. u'3'
kjlubick 2016/08/01 19:25:43 Done.
+ u'quarantined': unicode(2),
+ u'dead': unicode(1),
+ u'busy': unicode(1),
+ u'now': unicode(now.strftime(self.DATETIME_FORMAT)),
+ }
+ request = swarming_rpcs.BotsRequest()
+ response = self.call_api('count', body=message_to_dict(request))
+ self.assertEqual(expected, response.json)
+
+ expected = {
+ u'count': unicode(1),
+ u'quarantined': unicode(0),
+ u'dead': unicode(0),
+ u'busy': unicode(0),
+ u'now': unicode(now.strftime(self.DATETIME_FORMAT)),
+ }
+ request = swarming_rpcs.BotsRequest(dimensions=['foo:bar', 'id:id1'])
+ response = self.call_api('count', body=message_to_dict(request))
+ self.assertEqual(expected, response.json)
+
+ expected[u'quarantined'] = unicode(1)
+ expected[u'busy'] = unicode(1)
+ request = swarming_rpcs.BotsRequest(dimensions=['foo:bar', 'id:id2'])
+ response = self.call_api('count', body=message_to_dict(request))
+ self.assertEqual(expected, response.json)
+
+ expected[u'dead'] = unicode(1)
+ expected[u'busy'] = unicode(0)
+ request = swarming_rpcs.BotsRequest(dimensions=['foo:bar', 'id:id3'])
+ response = self.call_api('count', body=message_to_dict(request))
+ self.assertEqual(expected, response.json)
+
+ request = swarming_rpcs.BotsRequest(dimensions=['not:existing'])
+ response = self.call_api('count', body=message_to_dict(request))
+ expected = {
+ u'count': unicode(0),
+ u'quarantined': unicode(0),
+ u'dead': unicode(0),
+ u'busy': unicode(0),
+ u'now': unicode(now.strftime(self.DATETIME_FORMAT)),
+ }
+ self.assertEqual(expected, response.json)
+
+ request = swarming_rpcs.BotsRequest(dimensions=['bad'])
+ self.call_api('count', body=message_to_dict(request), status=400)
class BotApiTest(BaseTest):
api_service_cls = handlers_endpoints.SwarmingBotService

Powered by Google App Engine
This is Rietveld 408576698