GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Metrics::Any::Adapter::Test(3) User Contributed Perl Documentation Metrics::Any::Adapter::Test(3)

"Metrics::Any::Adapter::Test" - a metrics reporting adapter for unit testing

   use Test::More;
   use Metrics::Any::Adapter 'Test';

   {
      Metrics::Any::Adapter::Test->clear;

      # perform some work in the code under test

      is( Metrics::Any::Adapter::Test->metrics,
         "an_expected_metric = 1\n",
         'Metrics were reported while doing something'
      );
   }

This Metrics::Any adapter type stores reported metrics locally, allowing access to them by the "metrics" method. This is useful to use in a unit test to check that the code under test reports the correct metrics.

This adapter supports timer metrics by storing the count and total duration.

For predictable output of timer metrics in unit tests, a unit test may wish to use the "override_timer_duration" method.

   $result = Metrics::Any::Adapter::Test->metrics

This class method returns a string describing all of the stored metric values. Each is reported on a line formatted as

   name = value

Each line, including the final one, is terminated by a linefeed. The metrics are sorted alphabetically. Any multi-part metric names will be joined with underscores ("_").

Metrics that have additional labels are formatted with additional label names and label values in declared order after the name and before the "=" symbol:

   name l1:v1 l2:v2 = value

   Metrics::Any::Adapter::Test->clear

This class method removes all of the stored values of reported metrics.

   Metrics::Any::Adapter::Test->override_timer_duration( $duration )

This class method sets a duration value, that any subsequent call to "inc_timer" will use instead of the value the caller actually passed in. This will ensure reliably predictable output in unit tests.

Any value set here will be cleared by "clear".

Paul Evans <leonerd@leonerd.org.uk>
2022-04-07 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.