summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2015-04-16 16:12:16 +0100
committerSteve Kemp <steve@steve.org.uk>2015-04-16 16:12:16 +0100
commit3040da983f5c5a48419905ad7dccc8180ac851d4 (patch)
tree2a6e0bdb332a5631db5459237d2c09fd316b577e
parent1c9796068cdf0afe4af1b781a8b8b20b0c8a26d3 (diff)
Work with the new return-type from tests.
Now tests will no longe return "true" or "false", instead they will return "TEST_FAILED" or "TEST_PASSED". There is a third return-value of "TEST_SKIPPED" which essentially ignores a test.
-rw-r--r--lib/custodian/worker.rb47
1 files changed, 40 insertions, 7 deletions
diff --git a/lib/custodian/worker.rb b/lib/custodian/worker.rb
index 7016d51..a6995f9 100644
--- a/lib/custodian/worker.rb
+++ b/lib/custodian/worker.rb
@@ -154,15 +154,15 @@ module Custodian
# The count of times this test has run, the result, and the start-time
#
count = 1
- result = false
start_time = Time.now
+ run = true
#
# If a job fails we'll repeat it, but no more than MAX times.
#
# We exit here if we receive a single success.
#
- while (count < (@retry_count + 1)) && (result == false)
+ while (count < (@retry_count + 1)) && (run == true)
log_message("Running test - [#{count}/#{@retry_count}]")
@@ -170,11 +170,41 @@ module Custodian
# Run the test - inverting the result if we should
#
result = test.run_test
- result = !result if test.inverted
- if result
+
+ #
+ # TODO: This is temporary
+ #
+ if (result.is_a?(TrueClass)) ||
+ (result.is_a?(FalseClass))
+ puts 'ERROR: Class returned boolean'
+ end
+
+
+ #
+ # Invert the test, if the result was pass/fail
+ #
+ if test.inverted?
+ puts "The test was inverted - old result was : #{result}"
+
+ if (result == Custodian::TestResult::TEST_FAILED)
+ result = Custodian::TestResult::TEST_PASSED
+ else
+
+ # rubocop:disable BlockNesting
+ if (result == Custodian::TestResult::TEST_PASSED)
+ result = Custodian::TestResult::TEST_FAILED
+ end
+ end
+ puts "The test was inverted - new result is : #{result}"
+ end
+
+
+
+ if (result == Custodian::TestResult::TEST_PASSED)
log_message('Test succeeed - clearing alert')
do_clear(test)
+ run = false
end
#
@@ -186,7 +216,7 @@ module Custodian
# The intention here is that if the test passes then there will
# be no delay. If the test fails then we'll sleep.
#
- if (result == false) && (@retry_delay > 0) && (count < @retry_count)
+ if (run == true) && (@retry_delay > 0) && (count < @retry_count)
log_message("Sleeping #{@retry_delay} before retry - failure: #{test.error}")
sleep(@retry_delay)
end
@@ -212,13 +242,16 @@ module Custodian
# Record that, if we have any alerters that are interested
# in run-times.
#
- do_duration(test, duration)
+ if (result == Custodian::TestResult::TEST_FAILED) ||
+ (result == Custodian::TestResult::TEST_PASSED)
+ do_duration(test, duration)
+ end
#
# If we didn't succeed on any of the attempts raise the alert.
#
- if !result
+ if (result == Custodian::TestResult::TEST_FAILED)
#
# Raise the alert, passing the error message.