Commit 41dadf19 authored by Patrick Steinhardt's avatar Patrick Steinhardt

Fix specs which test listing of stale branches in projects

With the preceding commit, the project tests which verify listing of
active and stale branches works as expected start to fail. This is not a
bug in the preceding commit, but rather a bug in the tests themselves:
while we were using `travel_to()` to create stale branches, they were
created via Gitaly's `UserCommitFiles()` RPE. This RPC doesn't accept
any timestamp and thus the resulting commits do not carry the timestamp
set by `travel_to()`. With the preceding commit, this now gets handled
correctly such that the commits do carry the expected timestamp, which
uncovers two issues:

    1. There is a race between creation of active branches and checking
       for stale branches. The oldest active branch is only a second
       younger than the stale-branch threshold. Thus, if we need longer
       than that second, it will be considered stale, too.

    2. We do expect stale branches to be sorted in descending recency
       order, but in fact they're ordered in ascending recency: the
       oldest branch is on top.

Fix the tests by incrementing branch creation times by an hour instead
of by a second, which extends the race window for the oldest active
branch to one hour. And second, by correctly sorting expected branches.
parent cf380f35
......@@ -21,11 +21,11 @@ RSpec.describe 'Branches' do
before do
# Add 4 stale branches
(1..4).reverse_each do |i|
travel_to((threshold + i).ago) { create_file(message: "a commit in stale-#{i}", branch_name: "stale-#{i}") }
travel_to((threshold + i.hours).ago) { create_file(message: "a commit in stale-#{i}", branch_name: "stale-#{i}") }
end
# Add 6 active branches
(1..6).each do |i|
travel_to((threshold - i).ago) { create_file(message: "a commit in active-#{i}", branch_name: "active-#{i}") }
travel_to((threshold - i.hours).ago) { create_file(message: "a commit in active-#{i}", branch_name: "active-#{i}") }
end
end
......@@ -34,7 +34,7 @@ RSpec.describe 'Branches' do
visit project_branches_path(project)
expect(page).to have_content(sorted_branches(repository, count: 5, sort_by: :updated_desc, state: 'active'))
expect(page).to have_content(sorted_branches(repository, count: 4, sort_by: :updated_desc, state: 'stale'))
expect(page).to have_content(sorted_branches(repository, count: 4, sort_by: :updated_asc, state: 'stale'))
expect(page).to have_link('Show more active branches', href: project_branches_filtered_path(project, state: 'active'))
expect(page).not_to have_content('Show more stale branches')
......@@ -50,10 +50,10 @@ RSpec.describe 'Branches' do
end
describe 'Stale branches page' do
it 'shows 4 active branches sorted by last updated' do
it 'shows 4 stale branches sorted by last updated' do
visit project_branches_filtered_path(project, state: 'stale')
expect(page).to have_content(sorted_branches(repository, count: 4, sort_by: :updated_desc, state: 'stale'))
expect(page).to have_content(sorted_branches(repository, count: 4, sort_by: :updated_asc, state: 'stale'))
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment