@@ -69,13 +69,13 @@ func hasNumberOfMetrics(t *testing.T, timeout time.Duration, requiredMessages in
6969}
7070
7171func TestSimpleStartStop (t * testing.T ) {
72- go Run (1234 , "/random" , 100 )
72+ go Run (1234 , "/random" )
7373 isRunningWithTimeout (t , time .Second )
7474 Stop ()
7575}
7676
7777func TestStartMultipleStop (t * testing.T ) {
78- go Run (1234 , "/random" , 100 )
78+ go Run (1234 , "/random" )
7979 isRunningWithTimeout (t , time .Second )
8080 Stop ()
8181 Stop ()
@@ -86,7 +86,7 @@ func cleaningUpAfterTest() {
8686}
8787
8888func initTest () {
89- go Run (12345 , "notimportant" , 100 )
89+ go Run (12345 , "notimportant" )
9090}
9191
9292// decorator function that properly inits and cleans after higher level test of Monitoring package
@@ -131,7 +131,7 @@ func TestExportingMetrics(t *testing.T) {
131131}
132132
133133func TestHttpRun (t * testing.T ) {
134- go Run (9876 , "/metrics" , 10 )
134+ go Run (9876 , "/metrics" )
135135 defer Stop ()
136136
137137 isRunningWithTimeout (t , time .Second )
@@ -545,6 +545,24 @@ func TestMetricsHistogramObject(t *testing.T) {
545545 }
546546}
547547
548+ func measureFunc (metric * Metric ) {
549+ defer TimerMS (metric )()
550+ defer TimerNS (metric )()
551+ time .Sleep (100 * time .Millisecond )
552+ }
553+
554+ func TestTimers (t * testing.T ) {
555+ metric := NewMetric ("test" )
556+ measureFunc (& metric )
557+ fields := metric .fields
558+ if fields ["execution_time_ms" ].(int64 ) < 100 {
559+ t .Error ("wrong milliseconds" )
560+ }
561+ if fields ["execution_time_ns" ].(int64 ) < 100000000 {
562+ t .Error ("wrong nanoseconds" )
563+ }
564+ }
565+
548566func BenchmarkSimple (b * testing.B ) {
549567 cpuProfileFile , err := os .Create ("cpu_profile.pprof" )
550568 if err != nil {
@@ -575,19 +593,8 @@ func BenchmarkSimple(b *testing.B) {
575593 pprof .WriteHeapProfile (heapProfileFile )
576594}
577595
578- // This benchmark cannot be run for too long as it will fill whole RAM even with
579- // results:
580- // goos: linux
581- // goarch: amd64
582- // pkg: github.com/AliceO2Group/Control/common/monitoring
583- // cpu: 11th Gen Intel(R) Core(TM) i9-11900H @ 2.50GHz
584- // BenchmarkSendingMetrics-16
585- //
586- // 123365481 192.6 ns/op
587- // PASS
588- // ok github.com/AliceO2Group/Control/common/monitoring 44.686s
589596func BenchmarkSendingMetrics (b * testing.B ) {
590- go Run (12345 , "/metrics" , 100 )
597+ go Run (12345 , "/metrics" )
591598
592599 defer Stop ()
593600
0 commit comments