@@ -361,28 +361,64 @@ class MetricsTests: XCTestCase {
361361 XCTAssertEqual ( recorder. values [ 0 ] . 1 , value, " expected value to match " )
362362 }
363363
364- func testMUX ( ) throws {
364+ func testMUX_Counter ( ) throws {
365365 // bootstrap with our test metrics
366366 let factories = [ TestMetrics ( ) , TestMetrics ( ) , TestMetrics ( ) ]
367367 MetricsSystem . bootstrapInternal ( MultiplexMetricsHandler ( factories: factories) )
368368 // run the test
369369 let name = NSUUID ( ) . uuidString
370370 let value = Int . random ( in: Int . min ... Int . max)
371- let mux = Counter ( label: name)
372- mux . increment ( by: value)
371+ let muxCounter = Counter ( label: name)
372+ muxCounter . increment ( by: value)
373373 factories. forEach { factory in
374374 let counter = factory. counters. first? . 1 as! TestCounter
375375 XCTAssertEqual ( counter. label, name, " expected label to match " )
376376 XCTAssertEqual ( counter. values. count, 1 , " expected number of entries to match " )
377377 XCTAssertEqual ( counter. values [ 0 ] . 1 , Int64 ( value) , " expected value to match " )
378378 }
379- mux . reset ( )
379+ muxCounter . reset ( )
380380 factories. forEach { factory in
381381 let counter = factory. counters. first? . 1 as! TestCounter
382382 XCTAssertEqual ( counter. values. count, 0 , " expected number of entries to match " )
383383 }
384384 }
385385
386+ func testMUX_Recorder( ) throws {
387+ // bootstrap with our test metrics
388+ let factories = [ TestMetrics ( ) , TestMetrics ( ) , TestMetrics ( ) ]
389+ MetricsSystem . bootstrapInternal ( MultiplexMetricsHandler ( factories: factories) )
390+ // run the test
391+ let name = NSUUID ( ) . uuidString
392+ let value = Double . random ( in: 0 ... 1 )
393+ let muxRecorder = Recorder ( label: name)
394+ muxRecorder. record ( value)
395+ factories. forEach { factory in
396+ let recorder = factory. recorders. first? . 1 as! TestRecorder
397+ XCTAssertEqual ( recorder. label, name, " expected label to match " )
398+ XCTAssertEqual ( recorder. values. count, 1 , " expected number of entries to match " )
399+ XCTAssertEqual ( recorder. values [ 0 ] . 1 , value, " expected value to match " )
400+ }
401+ }
402+
403+ func testMUX_Timer( ) throws {
404+ // bootstrap with our test metrics
405+ let factories = [ TestMetrics ( ) , TestMetrics ( ) , TestMetrics ( ) ]
406+ MetricsSystem . bootstrapInternal ( MultiplexMetricsHandler ( factories: factories) )
407+ // run the test
408+ let name = NSUUID ( ) . uuidString
409+ let seconds = Int . random ( in: 1 ... 10 )
410+ let muxTimer = Timer ( label: name, preferredDisplayUnit: . minutes)
411+ muxTimer. recordSeconds ( seconds)
412+ factories. forEach { factory in
413+ let timer = factory. timers. first? . 1 as! TestTimer
414+ XCTAssertEqual ( timer. label, name, " expected label to match " )
415+ XCTAssertEqual ( timer. values. count, 1 , " expected number of entries to match " )
416+ XCTAssertEqual ( timer. values [ 0 ] . 1 , Int64 ( seconds * 1_000_000_000 ) , " expected value to match " )
417+ XCTAssertEqual ( timer. displayUnit, . minutes, " expected value to match " )
418+ XCTAssertEqual ( timer. retrieveValueInPreferredUnit ( atIndex: 0 ) , Double ( seconds) / 60.0 , " seconds should be returned as minutes " )
419+ }
420+ }
421+
386422 func testCustomFactory( ) {
387423 final class CustomHandler : CounterHandler {
388424 func increment< DataType> ( by: DataType ) where DataType: BinaryInteger { }
0 commit comments