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

Side by Side Diff: Tools/GardeningServer/alerts_test.py

Issue 469983002: Compress alerts with zlib level 1 to fit in sheriff-o-matic's memcache. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add a test for a large number of alerts. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « Tools/GardeningServer/alerts.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import alerts 5 import alerts
6 import json 6 import json
7 import random
8 import string
7 import unittest 9 import unittest
8 import webtest 10 import webtest
9 11
10 from google.appengine.api import memcache 12 from google.appengine.api import memcache
11 from google.appengine.ext import testbed 13 from google.appengine.ext import testbed
12 14
13 15
14 class AlertsTest(unittest.TestCase): 16 class AlertsTest(unittest.TestCase):
15 def setUp(self): 17 def setUp(self):
16 self.testbed = testbed.Testbed() 18 self.testbed = testbed.Testbed()
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 57
56 def test_post_invalid_data_does_not_overwrite_valid_data(self): 58 def test_post_invalid_data_does_not_overwrite_valid_data(self):
57 # Populate the cache with something valid 59 # Populate the cache with something valid
58 params = {'content': '{"alerts": "everything is OK"}'} 60 params = {'content': '{"alerts": "everything is OK"}'}
59 self.testapp.post('/alerts', params) 61 self.testapp.post('/alerts', params)
60 self.testapp.post('/alerts', {'content': 'woozlwuzl'}, status=400) 62 self.testapp.post('/alerts', {'content': 'woozlwuzl'}, status=400)
61 res = self.testapp.get('/alerts') 63 res = self.testapp.get('/alerts')
62 self.check_json_headers(res) 64 self.check_json_headers(res)
63 alerts = json.loads(res.body) 65 alerts = json.loads(res.body)
64 self.assertEqual(alerts['alerts'], 'everything is OK') 66 self.assertEqual(alerts['alerts'], 'everything is OK')
67
68 def test_large_number_of_alerts(self):
69 # This generates ~2.5MB of JSON that compresses to ~750K. Real
70 # data compresses about 6x better.
71 random.seed(0xf00f00)
72 put_alerts = self.generate_fake_alerts(4000)
73
74 params = {'content': json.dumps(put_alerts)}
75 self.testapp.post('/alerts', params)
76
77 res = self.testapp.get('/alerts')
78 got_alerts = json.loads(res.body)
79 self.assertEquals(got_alerts['alerts'], put_alerts['alerts'])
80
81 def generate_fake_alerts(self, n):
82 return {'alerts': [self.generate_fake_alert() for _ in range(n)]}
83
84 def generate_fake_alert(self):
85 # fake labels
86 labels = [['', 'last_', 'latest_', 'failing_', 'passing_'],
87 ['build', 'builder', 'revision'],
88 ['', 's', '_url', '_reason', '_name']]
89
90 def label():
91 return string.join(map(random.choice, labels), '')
92
93 # fake values
94 def time():
95 return random.randint(1407976107614, 1408076107614) / 101.0
96
97 def build():
98 return random.randint(2737, 2894)
99
100 def revision():
101 return random.randint(288849, 289415)
102
103 tests = [['Activity', 'Async', 'Browser', 'Content', 'Input'],
104 ['Manager', 'Card', 'Sandbox', 'Container'],
105 ['Test.'],
106 ['', 'Basic', 'Empty', 'More'],
107 ['Mouse', 'App', 'Selection', 'Network', 'Grab'],
108 ['Input', 'Click', 'Failure', 'Capture']]
109
110 def test():
111 return string.join(map(random.choice, tests), '')
112
113 def literal_array():
114 generator = random.choice([time, build, revision])
115 return [generator() for _ in range(random.randint(0, 10))]
116
117 def literal_map():
118 generators = [build, revision, test, literal_array]
119 obj = {}
120 for _ in range(random.randint(3, 9)):
121 obj[label()] = random.choice(generators)()
122 return obj
123
124 def value():
125 generators = [time, build, revision, test, literal_array,
126 literal_map]
127 return random.choice(generators)()
128
129 alert = {}
130 for _ in range(random.randint(6, 9)):
131 alert[label()] = value()
132 return alert
OLDNEW
« no previous file with comments | « Tools/GardeningServer/alerts.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698