@@ -108,6 +108,7 @@ impl Drop for RenderingTimesRecorder<'_> {
108
108
#[ cfg( test) ]
109
109
mod tests {
110
110
use crate :: test:: { assert_success, wrapper} ;
111
+ use crate :: Context ;
111
112
use std:: collections:: HashMap ;
112
113
113
114
#[ test]
@@ -133,8 +134,8 @@ mod tests {
133
134
( "/sitemap.xml" , "static resource" ) ,
134
135
( "/-/static/style.css" , "static resource" ) ,
135
136
( "/-/static/vendored.css" , "static resource" ) ,
136
- ( "/rustdoc/rcc/0.0.0/rcc/index.html" , "database " ) ,
137
- ( "/rustdoc/gcc/0.0.0/gcc/index.html" , "database " ) ,
137
+ ( "/rustdoc/rcc/0.0.0/rcc/index.html" , "rustdoc page " ) ,
138
+ ( "/rustdoc/gcc/0.0.0/gcc/index.html" , "rustdoc page " ) ,
138
139
] ;
139
140
140
141
wrapper ( |env| {
@@ -167,29 +168,43 @@ mod tests {
167
168
* entry += 2 ;
168
169
}
169
170
171
+ // this shows what the routes were *actually* recorded as, making it easier to update ROUTES if the name changes.
172
+ let metrics_serialized = metrics. gather ( & env. pool ( ) ?, & env. build_queue ( ) ) ?;
173
+ let all_routes_visited = metrics_serialized
174
+ . iter ( )
175
+ . find ( |x| x. get_name ( ) == "docsrs_routes_visited" )
176
+ . unwrap ( ) ;
177
+ let routes_visited_pretty: Vec < _ > = all_routes_visited
178
+ . get_metric ( )
179
+ . iter ( )
180
+ . map ( |metric| {
181
+ let labels = metric. get_label ( ) ;
182
+ assert_eq ! ( labels. len( ) , 1 ) ; // not sure when this would be false
183
+ let route = labels[ 0 ] . get_value ( ) ;
184
+ let count = metric. get_counter ( ) . get_value ( ) ;
185
+ format ! ( "{}: {}" , route, count)
186
+ } )
187
+ . collect ( ) ;
188
+ println ! ( "routes: {:?}" , routes_visited_pretty) ;
189
+
170
190
for ( label, count) in expected. iter ( ) {
171
191
assert_eq ! (
172
192
metrics. routes_visited. with_label_values( & [ * label] ) . get( ) ,
173
- * count
193
+ * count,
194
+ "routes_visited metrics for {} are incorrect" ,
195
+ label,
174
196
) ;
175
197
assert_eq ! (
176
198
metrics
177
199
. response_time
178
200
. with_label_values( & [ * label] )
179
201
. get_sample_count( ) ,
180
- * count as u64
202
+ * count as u64 ,
203
+ "response_time metrics for {} are incorrect" ,
204
+ label,
181
205
) ;
182
206
}
183
207
184
- // extra metrics for the "database success" hack
185
- assert_eq ! (
186
- metrics
187
- . routes_visited
188
- . with_label_values( & [ "database success" ] )
189
- . get( ) ,
190
- 2
191
- ) ;
192
-
193
208
Ok ( ( ) )
194
209
} )
195
210
}
0 commit comments