💄 Generalize rendering of histograms
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / MetricsPageTest.kt
index 0565612..5a5d588 100644 (file)
@@ -62,14 +62,38 @@ class MetricsPageTest : WebPageTest() {
        }
 
        @Test
-       fun `metrics page lists stats about sone parsing durations`() {
-               createHistogram("sone.parsing.duration")
+       fun `metrics page auto-converts histogram name`() {
+               createHistogram("sone.random.duration")
                page.handleRequest(soneRequest, templateContext)
-               verifyHistogram("soneParsingDuration")
+               verifyHistogram("soneRandomDuration")
+       }
+
+       @Test
+       @Suppress("UNCHECKED_CAST")
+       fun `metrics page stores histogram keys in template`() {
+               createHistogram("sone.random.duration2")
+               createHistogram("sone.random.duration1")
+               page.handleRequest(soneRequest, templateContext)
+               assertThat(templateContext["histogramKeys"] as Iterable<String>, contains("soneRandomDuration1", "soneRandomDuration2"))
+       }
+
+       @Test
+       fun `metrics page stores i18n names for histogram keys`() {
+               createHistogram("sone.random.duration1")
+               page.handleRequest(soneRequest, templateContext)
+               assertThat(templateContext["soneRandomDuration1I18n"] as String, equalTo("SoneRandomDuration1"))
+       }
+
+       @Test
+       fun `metrics page delivers correct histogram size`() {
+               val histogram = metricRegistry.histogram("sone.parsing.duration")
+               (0..4000).forEach(histogram::update)
+               page.handleRequest(soneRequest, templateContext)
+               assertThat(templateContext["soneParsingDurationCount"] as Long, equalTo(4001L))
        }
 
        private fun verifyHistogram(name: String) {
-               assertThat(templateContext["${name}Count"] as Int, equalTo(5))
+               assertThat(templateContext["${name}Count"] as Long, equalTo(5L))
                assertThat(templateContext["${name}Min"] as Long, equalTo(1L))
                assertThat(templateContext["${name}Max"] as Long, equalTo(10L))
                assertThat(templateContext["${name}Median"] as Double, equalTo(8.0))