• Dylan Griffith's avatar
    Fix flaky epics_finder_spec race condition · 55c2a9bd
    Dylan Griffith authored
    As per https://gitlab.com/gitlab-org/gitlab/-/issues/321511 we've seen
    one of these tests fail. It seems likely the problem is caused by the
    use of `X.days.ago` throughout and then filtering with date ranges. The
    likely explanation is that when the test is running just before midnight
    then `2.days.ago` actually ends up being "3 days ago" from a date
    perspective by the time the assertion is made about it.
    
    Even though it's not easy to replicate this exact failure mode and this
    flakiness has never happened for this spec before (to my knowledge) in 3
    years it still is not a good way to write these kinds of tests as this
    is theoretically a problem.
    
    Instead of making all the times relative to "now" (which changes) I've
    just made everything relative to some arbitrary fixed time. This works
    fine, without any need for freezing time, as none of the methods being
    tested actually refer to the current time.
    
    The test is still quite difficult to read due to many different dates
    and times and the fact that the examples are separated from the test
    setup but I don't think this change makes it less clear.
    55c2a9bd
epics_finder_spec.rb 27.1 KB