seatshare / seatshare-rails

🎟 Primary SeatShare application in Ruby on Rails.
https://www.myseatshare.com
MIT License
2 stars 1 forks source link

Intermittent test failures because of timezones #109

Closed stephenyeargin closed 10 years ago

stephenyeargin commented 10 years ago

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:

The relevant bits:

[...]
<td>Nashville Predators vs. St. Louis Blues : Saturday, October 26, 2013 - 3:00 pm EDT</td>
[...]
to include "<td>Nashville Predators vs. St. Louis Blues : Saturday, October 26, 2013 - 2:00 pm CDT</td>".

To reproduce:

  1. Run the test suite
  2. Run it again
  3. Keep running it until you hit the failure

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.

stephenyeargin commented 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
stephenyeargin commented 10 years ago

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.

stephenyeargin commented 10 years ago

Suggestion is to use an after_tests or setup method to reset the Timezone before each test.