Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 145 lines (135 sloc) 5.113 kb
4b50beb @ianb AMO collection mode -- this connects adds another kind of input (AMO)…
ianb authored
1 This is a basic functional test of ``server/pyfomatic/collect_amo.py``.
2
3 The container (``test_collect_amo.py``) sets up ``sys.path``.
4
5 First we'll mock the database connections::
6
7 >>> from minimock import mock, Mock
8 >>> from itertools import count
9 >>> import graphsdb
10 >>> # Have to patch this in sometimes
11 >>> graphsdb.amo_db = None
12 >>> mock('graphsdb.db')
13 >>> mock('graphsdb.amo_db')
14 >>> graphsdb.db.cursor.mock_returns = Mock('db_cursor')
15 >>> graphsdb.amo_db.cursor.mock_returns = Mock('amo_cursor')
16 >>> graphsdb.amo_db.insert_id.mock_returns_iter = count(1)
17
18 We need to patch in at least one return value for `get_os_for_machine()`::
19
20 >>> return_row_next_time = False
21 >>> def return_os_id_execute(sql, params=None):
22 ... global return_row_next_time
23 ... if 'os_list.name' in sql:
24 ... return_row_next_time = True
25 >>> def return_os_id_fetchone():
26 ... if return_row_next_time:
19d9f6b @ianb Split the single os_name string into os (Windows, etc) and version (7…
ianb authored
27 ... return ['Windows 1.0']
4b50beb @ianb AMO collection mode -- this connects adds another kind of input (AMO)…
ianb authored
28 ... else:
29 ... return None
30 >>> graphsdb.db.cursor.mock_returns.execute.mock_returns_func = return_os_id_execute
31 >>> graphsdb.db.cursor.mock_returns.fetchone = return_os_id_fetchone
32
33 Then import stuff::
34
35 >>> from cStringIO import StringIO
36 >>> from pyfomatic.collect_amo import parse_amo_collection
37
38 And run the examples (as taken from
39 https://wiki.mozilla.org/Buildbot/Talos/DataFormat#Schema_for_AMO_Perf_Results_Storage)::
40
41 >>> pageload_example = StringIO('''\
42 ... Firefox,3.6,1066
9476b49 @ianb Move to REPLACE INTO perf_results instead of INSERT (to make rows uni…
ianb authored
43 ... machine_1, ts, branch_1, changeset_1, 13, 1229477017
4b50beb @ianb AMO collection mode -- this connects adds another kind of input (AMO)…
ianb authored
44 ... 1,1.0,page_01
45 ... 2,2.0,page_02
46 ... 3,3.0,page_03
47 ... 4,1.0,page_04
48 ... 5,2.0,page_05
49 ... 6,3.0,page_06
50 ... 7,1.0,page_07
51 ... 8,2.0,page_08
52 ... 9,3.0,page_09
53 ... 10,1.0,page_10
54 ... 11,2.0,page_11
55 ... 12,3.0,page_12
56 ... END''')
57 >>> parse_amo_collection(pageload_example)
58 Called graphsdb.amo_db.cursor()
59 Called amo_cursor.execute(
60 '...SELECT id FROM perf_appversions...',
61 ('fx', '3.6'))
62 Called amo_cursor.fetchone()
63 Called graphsdb.amo_db.cursor()
64 Called amo_cursor.execute(
65 '...INSERT INTO perf_appversions...VALUES (%s, %s, NOW(), NOW())...',
66 ('fx', '3.6'))
67 Called graphsdb.amo_db.insert_id()
68 Called graphsdb.amo_db.commit()
69 Called graphsdb.db.cursor()
70 Called db_cursor.execute(
71 '...SELECT os_list.name...WHERE machines.os_id = os_list.id...AND machines.name = %s...',
72 ('machine_1',))
73 Called graphsdb.amo_db.cursor()
74 Called amo_cursor.execute(
19d9f6b @ianb Split the single os_name string into os (Windows, etc) and version (7…
ianb authored
75 '...SELECT id FROM perf_osversions...WHERE os = %s...AND version = %s...',
76 ('Windows', '1.0'))
4b50beb @ianb AMO collection mode -- this connects adds another kind of input (AMO)…
ianb authored
77 Called amo_cursor.fetchone()
78 Called graphsdb.amo_db.cursor()
79 Called amo_cursor.execute(
19d9f6b @ianb Split the single os_name string into os (Windows, etc) and version (7…
ianb authored
80 '...INSERT INTO perf_osversions...VALUES (%s, %s, NOW(), NOW())...',
81 ('Windows', '1.0'))
4b50beb @ianb AMO collection mode -- this connects adds another kind of input (AMO)…
ianb authored
82 Called graphsdb.amo_db.insert_id()
83 Called graphsdb.amo_db.commit()
84 Called graphsdb.amo_db.cursor()
85 Called amo_cursor.execute(
9476b49 @ianb Move to REPLACE INTO perf_results instead of INSERT (to make rows uni…
ianb authored
86 '...REPLACE INTO perf_results...VALUES (%s, %s, %s, %s, %s, NOW(), NOW())...',
87 ('1066', 1, 2.0, 2, 'ts'))
4b50beb @ianb AMO collection mode -- this connects adds another kind of input (AMO)…
ianb authored
88 Called graphsdb.amo_db.commit()
89 >>> startup_example = StringIO('''\
90 ... Firefox,3.6,1066
91 ... machine_1, ts, branch_1, changeset_1, 13, 1229477017
92 ... 1,1500,NULL
93 ... 2,862,NULL
94 ... 3,863,NULL
95 ... 4,860,NULL
96 ... 5,865,NULL
97 ... 6,865,NULL
98 ... 7,867,NULL
99 ... 8,865,NULL
100 ... 9,870,NULL
101 ... 10,889,NULL
102 ... 11,865,NULL
103 ... 12,864,NULL
104 ... 13,864,NULL
105 ... 14,870,NULL
106 ... 15,871,NULL
107 ... 16,869,NULL
108 ... 17,868,NULL
109 ... 18,870,NULL
110 ... 19,864,NULL
111 ... 20,865,NULL
112 ... END''')
113 >>> parse_amo_collection(startup_example)
114 Called graphsdb.amo_db.cursor()
115 Called amo_cursor.execute(
116 '...SELECT id FROM perf_appversions...WHERE app = %s AND version = %s...',
117 ('fx', '3.6'))
118 Called amo_cursor.fetchone()
119 Called graphsdb.amo_db.cursor()
120 Called amo_cursor.execute(
121 '...INSERT INTO perf_appversions...VALUES (%s, %s, NOW(), NOW())...',
122 ('fx', '3.6'))
123 Called graphsdb.amo_db.insert_id()
124 Called graphsdb.amo_db.commit()
125 Called graphsdb.db.cursor()
126 Called db_cursor.execute(
127 '...SELECT os_list.name...WHERE machines.os_id = os_list.id...AND machines.name = %s...',
128 ('machine_1',))
129 Called graphsdb.amo_db.cursor()
130 Called amo_cursor.execute(
19d9f6b @ianb Split the single os_name string into os (Windows, etc) and version (7…
ianb authored
131 '...SELECT id FROM perf_osversions...WHERE os = %s...AND version = %s...',
132 ('Windows', '1.0'))
4b50beb @ianb AMO collection mode -- this connects adds another kind of input (AMO)…
ianb authored
133 Called amo_cursor.fetchone()
134 Called graphsdb.amo_db.cursor()
135 Called amo_cursor.execute(
19d9f6b @ianb Split the single os_name string into os (Windows, etc) and version (7…
ianb authored
136 '...INSERT INTO perf_osversions...VALUES (%s, %s, NOW(), NOW())...',
137 ('Windows', '1.0'))
4b50beb @ianb AMO collection mode -- this connects adds another kind of input (AMO)…
ianb authored
138 Called graphsdb.amo_db.insert_id()
139 Called graphsdb.amo_db.commit()
140 Called graphsdb.amo_db.cursor()
141 Called amo_cursor.execute(
9476b49 @ianb Move to REPLACE INTO perf_results instead of INSERT (to make rows uni…
ianb authored
142 '...REPLACE INTO perf_results...VALUES (%s, %s, %s, %s, %s, NOW(), NOW())...',
143 ('1066', 3, 898.79999999999995, 4, 'ts'))
4b50beb @ianb AMO collection mode -- this connects adds another kind of input (AMO)…
ianb authored
144 Called graphsdb.amo_db.commit()
Something went wrong with that request. Please try again.