From b1f183c582302d26133dae9c6748f7e08dbd8b56 Mon Sep 17 00:00:00 2001 From: Matthias Bethke Date: Wed, 23 Nov 2016 00:36:12 +0700 Subject: [PATCH] use deterministic time values in MockDaemon --- bindings/perl/lib/Collectd/MockDaemon.pm | 16 +++++++++++++--- bindings/perl/t/01_methods.t | 18 ++++++++---------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/bindings/perl/lib/Collectd/MockDaemon.pm b/bindings/perl/lib/Collectd/MockDaemon.pm index 9d784b7c..300d2c4a 100644 --- a/bindings/perl/lib/Collectd/MockDaemon.pm +++ b/bindings/perl/lib/Collectd/MockDaemon.pm @@ -55,10 +55,20 @@ sub daemon { } sub listval { - my $trunc_now = substr(time, 0, -1); - my $toggle; + my @timevals = ( + 1479835353.75, + 1479835354.434, + 1479835356, + 1479835354, + 1479835354, + 1479835350.820, + 1479835351, + 1479835354.2, + 1479835353, + ); + my $i = 0; return print_nvalues(scalar @metrics) . - join('', map { $trunc_now . int(rand(10)) . ($toggle=!$toggle ? ".".int(rand(1000)) : '') . " $_\n" } @metrics); + join('', map { $timevals[$i++ % @timevals] . " $_\n" } @metrics); } sub getval { diff --git a/bindings/perl/t/01_methods.t b/bindings/perl/t/01_methods.t index 4e94f8e8..4a4822ae 100644 --- a/bindings/perl/t/01_methods.t +++ b/bindings/perl/t/01_methods.t @@ -9,8 +9,6 @@ use Collectd::MockDaemon; my $path = mockd_start(); END { mockd_stop(); } -sub filter_time { return map { delete $_->{time}; $_ } @_ } - sub test_query { my ($s, $attr, $results) = @_; my ($nresults, $resultdata) = @$results; @@ -33,24 +31,24 @@ test_query($s, $_, $queries{$_}) for sort keys %queries; my @values = $s->listval; is(scalar @values, 4984, "Correct number of results from LISTVAL"); -delete $values[1234]{time}; # won't be constant is_deeply($values[1234], { type_instance => 'nice', plugin_instance => 21, plugin => 'cpu', type => 'cpu', - host => 'h2gdf6120' + host => 'h2gdf6120', + time => 1479835354.434, }, "Correct data returned for select element"); @values = (); -is_deeply([ filter_time $s->listval_filter() ] , [ filter_time $s->listval ], "listval_filter() w/o filter equivalent to listval()"); +is_deeply([ $s->listval_filter() ] , [ $s->listval ], "listval_filter() w/o filter equivalent to listval()"); is_deeply( - [ filter_time $s->listval_filter(host => 'a1d8f6310', plugin => 'disk', plugin_instance => 'vda6') ], + [ $s->listval_filter(host => 'a1d8f6310', plugin => 'disk', plugin_instance => 'vda6') ], [ - { 'plugin_instance' => 'vda6', 'type' => 'disk_merged', 'plugin' => 'disk', 'host' => 'a1d8f6310' }, - { 'host' => 'a1d8f6310', 'plugin' => 'disk', 'plugin_instance' => 'vda6', 'type' => 'disk_octets' }, - { 'type' => 'disk_ops', 'plugin_instance' => 'vda6', 'plugin' => 'disk', 'host' => 'a1d8f6310' }, - { 'plugin' => 'disk', 'host' => 'a1d8f6310', 'type' => 'disk_time', 'plugin_instance' => 'vda6' } + { 'plugin_instance' => 'vda6', 'type' => 'disk_merged', 'plugin' => 'disk', 'host' => 'a1d8f6310', time => 1479835354.434 }, + { 'host' => 'a1d8f6310', 'plugin' => 'disk', 'plugin_instance' => 'vda6', 'type' => 'disk_octets', time => 1479835356 }, + { 'type' => 'disk_ops', 'plugin_instance' => 'vda6', 'plugin' => 'disk', 'host' => 'a1d8f6310', time => 1479835354 }, + { 'plugin' => 'disk', 'host' => 'a1d8f6310', 'type' => 'disk_time', 'plugin_instance' => 'vda6', time => 1479835354 } ], "Correct result from listval_filter on , and " ); -- 2.11.0