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

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

Issue 2121323002: swarming: add active jobs pending times metric (Closed) Base URL: https://github.com/luci/luci-py.git@master
Patch Set: tests 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 unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2016 The LUCI Authors. All rights reserved. 2 # Copyright 2016 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 import datetime 6 import datetime
7 import os 7 import os
8 import sys 8 import sys
9 import unittest 9 import unittest
10 10
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 'master:test_master', 126 'master:test_master',
127 'buildername:test_builder', 127 'buildername:test_builder',
128 'name:some_tests', 128 'name:some_tests',
129 ] 129 ]
130 summary_running = _gen_task_result_summary(self.now, 1, tags=tags) 130 summary_running = _gen_task_result_summary(self.now, 1, tags=tags)
131 summary_running.state = task_result.State.RUNNING 131 summary_running.state = task_result.State.RUNNING
132 summary_running.modified_ts = self.now 132 summary_running.modified_ts = self.now
133 summary_running.bot_id = 'test_bot1' 133 summary_running.bot_id = 'test_bot1'
134 summary_running.put() 134 summary_running.put()
135 135
136 summary_pending = _gen_task_result_summary(self.now, 2, tags=tags) 136 summary_pending = _gen_task_result_summary(
137 self.now - datetime.timedelta(minutes=5), 2, tags=tags)
137 summary_pending.state = task_result.State.PENDING 138 summary_pending.state = task_result.State.PENDING
138 summary_pending.modified_ts = self.now 139 summary_pending.modified_ts = self.now
139 summary_pending.bot_id = 'test_bot2' 140 summary_pending.bot_id = 'test_bot2'
140 summary_pending.put() 141 summary_pending.put()
141 142
142 summary_pending = _gen_task_result_summary(self.now, 3, tags=tags) 143 summary_pending = _gen_task_result_summary(
144 self.now - datetime.timedelta(minutes=10), 3, tags=tags)
143 summary_pending.state = task_result.State.PENDING 145 summary_pending.state = task_result.State.PENDING
144 summary_pending.modified_ts = self.now 146 summary_pending.modified_ts = self.now
145 summary_pending.bot_id = '' 147 summary_pending.bot_id = ''
146 summary_pending.put() 148 summary_pending.put()
147 149
148 _gen_bot_info('bot_ready', self.now).put() 150 _gen_bot_info('bot_ready', self.now).put()
149 _gen_bot_info('bot_running', self.now, task_id='deadbeef').put() 151 _gen_bot_info('bot_running', self.now, task_id='deadbeef').put()
150 _gen_bot_info('bot_quarantined', self.now, quarantined=True).put() 152 _gen_bot_info('bot_quarantined', self.now, quarantined=True).put()
151 _gen_bot_info('bot_dead', self.now - datetime.timedelta(days=365)).put() 153 _gen_bot_info('bot_dead', self.now - datetime.timedelta(days=365)).put()
152 bots_expected = { 154 bots_expected = {
(...skipping 18 matching lines...) Expand all
171 jobs_target_fields['hostname'] = 'autogen:test_bot2' 173 jobs_target_fields['hostname'] = 'autogen:test_bot2'
172 self.assertFalse(ts_mon_metrics.jobs_running.get( 174 self.assertFalse(ts_mon_metrics.jobs_running.get(
173 fields=jobs_fields, target_fields=jobs_target_fields)) 175 fields=jobs_fields, target_fields=jobs_target_fields))
174 jobs_fields['status'] = 'running' 176 jobs_fields['status'] = 'running'
175 self.assertEqual(1, ts_mon_metrics.jobs_active.get( 177 self.assertEqual(1, ts_mon_metrics.jobs_active.get(
176 fields=jobs_fields, target_fields=ts_mon_metrics.TARGET_FIELDS)) 178 fields=jobs_fields, target_fields=ts_mon_metrics.TARGET_FIELDS))
177 jobs_fields['status'] = 'pending' 179 jobs_fields['status'] = 'pending'
178 self.assertEqual(2, ts_mon_metrics.jobs_active.get( 180 self.assertEqual(2, ts_mon_metrics.jobs_active.get(
179 fields=jobs_fields, target_fields=ts_mon_metrics.TARGET_FIELDS)) 181 fields=jobs_fields, target_fields=ts_mon_metrics.TARGET_FIELDS))
180 182
183 self.assertEqual(900, ts_mon_metrics.jobs_pending_durations.get(
184 fields=jobs_fields, target_fields=ts_mon_metrics.TARGET_FIELDS).sum)
185
181 for bot_id, status in bots_expected.iteritems(): 186 for bot_id, status in bots_expected.iteritems():
182 target_fields = dict(ts_mon_metrics.TARGET_FIELDS) 187 target_fields = dict(ts_mon_metrics.TARGET_FIELDS)
183 target_fields['hostname'] = 'autogen:' + bot_id 188 target_fields['hostname'] = 'autogen:' + bot_id
184 self.assertEqual(status, ts_mon_metrics.executors_status.get( 189 self.assertEqual(status, ts_mon_metrics.executors_status.get(
185 target_fields=target_fields)) 190 target_fields=target_fields))
186 191
187 self.assertEqual('bot_id:%s|os:Linux|os:Ubuntu' % bot_id, 192 self.assertEqual('bot_id:%s|os:Linux|os:Ubuntu' % bot_id,
188 ts_mon_metrics.executors_pool.get( 193 ts_mon_metrics.executors_pool.get(
189 target_fields=target_fields)) 194 target_fields=target_fields))
190 195
191 196
192 if __name__ == '__main__': 197 if __name__ == '__main__':
193 if '-v' in sys.argv: 198 if '-v' in sys.argv:
194 unittest.TestCase.maxDiff = None 199 unittest.TestCase.maxDiff = None
195 unittest.main() 200 unittest.main()
OLDNEW
« appengine/swarming/ts_mon_metrics.py ('K') | « appengine/swarming/ts_mon_metrics.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698