@@ -21,6 +21,7 @@ package prometheus_test
2121
2222import (
2323 "bytes"
24+ "fmt"
2425 "io/ioutil"
2526 "math/rand"
2627 "net/http"
@@ -783,6 +784,11 @@ func TestAlreadyRegistered(t *testing.T) {
783784// same HistogramVec is registered concurrently and the Gather method of the
784785// registry is called concurrently.
785786func TestHistogramVecRegisterGatherConcurrency (t * testing.T ) {
787+ labelNames := make ([]string , 16 ) // Need at least 13 to expose #512.
788+ for i := range labelNames {
789+ labelNames [i ] = fmt .Sprint ("label_" , i )
790+ }
791+
786792 var (
787793 reg = prometheus .NewPedanticRegistry ()
788794 hv = prometheus .NewHistogramVec (
@@ -791,7 +797,7 @@ func TestHistogramVecRegisterGatherConcurrency(t *testing.T) {
791797 Help : "This helps testing." ,
792798 ConstLabels : prometheus.Labels {"foo" : "bar" },
793799 },
794- [] string { "one" , "two" , "three" } ,
800+ labelNames ,
795801 )
796802 labelValues = []string {"a" , "b" , "c" , "alpha" , "beta" , "gamma" , "aleph" , "beth" , "gimel" }
797803 quit = make (chan struct {})
@@ -806,11 +812,11 @@ func TestHistogramVecRegisterGatherConcurrency(t *testing.T) {
806812 return
807813 default :
808814 obs := rand .NormFloat64 ()* .1 + .2
809- hv . WithLabelValues (
810- labelValues [ rand . Intn ( len ( labelValues ))],
811- labelValues [rand .Intn (len (labelValues ))],
812- labelValues [ rand . Intn ( len ( labelValues ))],
813- ).Observe (obs )
815+ values := make ([] string , 0 , len ( labelNames ))
816+ for range labelNames {
817+ values = append ( values , labelValues [rand .Intn (len (labelValues ))])
818+ }
819+ hv . WithLabelValues ( values ... ).Observe (obs )
814820 }
815821 }
816822 }
@@ -848,7 +854,7 @@ func TestHistogramVecRegisterGatherConcurrency(t *testing.T) {
848854 if len (g ) != 1 {
849855 t .Error ("Gathered unexpected number of metric families:" , len (g ))
850856 }
851- if len (g [0 ].Metric [0 ].Label ) != 4 {
857+ if len (g [0 ].Metric [0 ].Label ) != len ( labelNames ) + 1 {
852858 t .Error ("Gathered unexpected number of label pairs:" , len (g [0 ].Metric [0 ].Label ))
853859 }
854860 }
0 commit comments