[yast-commit] <rest-service> master : added testcase
ref: refs/heads/master commit 2aede31036233d6d70f4ae2bd3485b10a8529f6c Author: Stefan Schubert <schubi@suse.de> Date: Wed Nov 25 09:53:12 2009 +0100 added testcase --- plugins/status/lib/status.rb | 7 ++++++- plugins/status/test/unit/status_test.rb | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletions(-) diff --git a/plugins/status/lib/status.rb b/plugins/status/lib/status.rb index 07a52f8..9c661fe 100644 --- a/plugins/status/lib/status.rb +++ b/plugins/status/lib/status.rb @@ -199,13 +199,18 @@ class Status return @data end + #get last entry of rrd database + def last_db_entry(file) + `/bin/sh -c "LC_ALL=C rrdtool last #{file}"` + end + # runs the rddtool on file with start time and end time # default last 5 minutes from now def run_rrdtool(file, start, stop) #checking if systemtime is BEHIND the last entry of collectd. #If yes, no data will be available. - timestamp = `/bin/sh -c "LC_ALL=C rrdtool last #{file}"` + timestamp = last_db_entry(file) raise CollectdOutOfSyncError.new(timestamp) if Time.now < Time.at(timestamp.to_i) stop = Time.now if stop.nil? diff --git a/plugins/status/test/unit/status_test.rb b/plugins/status/test/unit/status_test.rb index 96b64f3..b04794b 100644 --- a/plugins/status/test/unit/status_test.rb +++ b/plugins/status/test/unit/status_test.rb @@ -118,4 +118,20 @@ EOF assert_equal expected_response, status.fetch_metric("/var/lib/collectd/test/memory-free.rrd", start, stop) end + + def test_db_out_of_sync + stop = Time.now + start = Time.now - 300 + + status = Status.new + + # stub the checking db for last entry + status.stubs(:last_db_entry).with("/var/lib/collectd/test/memory-free.rrd").returns("1248092090") + Time.stubs(:now).returns(Time.at(1248000000)) + + assert_raise CollectdOutOfSyncError do + ret = status.fetch_metric("/var/lib/collectd/test/memory-free.rrd", start, stop) + end + end + end -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
Stefan Schubert