Closed stephenyeargin closed 10 years ago
Donated by @rick - https://gist.github.com/rick/e31788fa2d1be67e5910
# Public: provide debugging information for tests which are known to fail intermittently
#
# issue_link - url of GitHub issue documenting this intermittent test failure
# args - Hash of debugging information (names => values) to output on a failure
# block - block which intermittently fails
#
# Example
#
# fails_intermittently('https://github.com/github/github/issues/27807',
# '@repo' => @repo, 'shas' => shas, 'expected' => expected) do
# assert_equal expected, shas
# end
#
# Re-raises any MiniTest::Assertion from a failing test assertion in the block.
#
# Returns the value of the yielded block when no test assertion fails.
def fails_intermittently(issue_link, args = {}, &block)
raise ArgumentError, "provide a GitHub issue link" unless issue_link
raise ArgumentError, "a block is required" unless block_given?
yield
rescue MiniTest::Assertion, StandardError => boom # we have a test failure!
STDERR.puts "\n\nIntermittent test failure! See: #{issue_link}"
if args.empty?
STDERR.puts "No further debugging information available."
else
STDERR.puts "Debugging information:\n"
args.keys.sort.each do |key|
STDERR.puts "#{key} => #{args[key].inspect}"
end
end
raise boom
end
Another one:
1) Failure:
EventTest#test_new_event_has_attributes [/home/runner/seatshare-rails/test/models/event_test.rb:20]:
new event date/time string matches
https://github.com/seatshare/seatshare-rails/blob/master/test/models/event_test.rb#L4-L21 -- again, it's most likely a TimeZone getting set in one test and not being reset to its default status.
Suggestion is to use an after_tests
or setup
method to reset the Timezone before each test.
Now if that subject didn't scare you completely away from this ticket ...
Something in the test runner is allowing a Timezone to be set to Eastern even if the user should be default to Central. This manifests itself in two tests in particular:
TicketNotifierTest#test_ticket_assigned_to_user [/Users/stephen/Sites/seatshare-rails/test/mailers/ticket_notifier_test.rb:17]:
TicketNotifierTest#test_ticket_requested_from_user [/Users/stephen/Sites/seatshare-rails/test/mailers/ticket_notifier_test.rb:33]:
The relevant bits:
To reproduce:
I'm not sure if it's because
Test::Unit
is prone to running the tests in an arbitrary order and something is getting reset between tests or what.