Commit 5c37c7ba authored by Luke Duncalfe's avatar Luke Duncalfe Committed by Thong Kuah

Avoid design flaky specs

Some specs that create a design with a `with_file` trait would fail
intermittently with a Gitaly error `A file with this name already
exists`. This signalled that a collision in the design.full_path in
the spec. The full_path is made from the id of the issue and its name.

The failing tests would fail when a `create(:design, :with_file)` was

- created in a `before` block
- its issue was created in a `set`
-  and it was setting a specific filename for the design.

In this situation, if a capybara spec failed once, it would retry again,
and would try to create a design with the same name and save it against
the same issue from the last time it ran. This would lead to a full_path
conflict.

The fix is a combination of:
- using the default (dynamically sequenced) filenames for designs that
  are generated by FactoryBot where possible
- if we do set a design that has a `with_file` trait (meaning it will
  create an underlying commit in Gitaly for the design version) then the
  issue must be created at the same time as the design is within the
  test

See https://gitlab.com/gitlab-org/gitlab/issues/32620#note_222564584
parent 85109c4e
...@@ -9,8 +9,7 @@ describe 'User paginates issue designs', :js do ...@@ -9,8 +9,7 @@ describe 'User paginates issue designs', :js do
before do before do
enable_design_management enable_design_management
create(:design, :with_file, issue: issue, filename: 'world.png') create_list(:design, 2, :with_file, issue: issue)
create(:design, :with_file, issue: issue, filename: 'dk.png')
visit project_issue_path(project, issue) visit project_issue_path(project, issue)
......
...@@ -5,12 +5,11 @@ describe 'User views issue designs', :js do ...@@ -5,12 +5,11 @@ describe 'User views issue designs', :js do
set(:project) { create(:project_empty_repo, :public) } set(:project) { create(:project_empty_repo, :public) }
set(:issue) { create(:issue, project: project) } set(:issue) { create(:issue, project: project) }
set(:design) { create(:design, :with_file, issue: issue) }
before do before do
enable_design_management enable_design_management
create(:design, :with_file, issue: issue, filename: 'world.png')
visit project_issue_path(project, issue) visit project_issue_path(project, issue)
click_link 'Designs' click_link 'Designs'
...@@ -22,7 +21,7 @@ describe 'User views issue designs', :js do ...@@ -22,7 +21,7 @@ describe 'User views issue designs', :js do
find('.js-design-list-item', match: :first).click find('.js-design-list-item', match: :first).click
page.within(find('.js-design-header')) do page.within(find('.js-design-header')) do
expect(page).to have_content('world.png') expect(page).to have_content(design.filename)
end end
expect(page).to have_selector('.js-design-image') expect(page).to have_selector('.js-design-image')
......
...@@ -5,11 +5,10 @@ describe 'User views issue designs', :js do ...@@ -5,11 +5,10 @@ describe 'User views issue designs', :js do
set(:project) { create(:project_empty_repo, :public) } set(:project) { create(:project_empty_repo, :public) }
set(:issue) { create(:issue, project: project) } set(:issue) { create(:issue, project: project) }
set(:design) { create(:design, :with_file, issue: issue) }
before do before do
enable_design_management enable_design_management
create(:design, :with_file, issue: issue)
end end
context 'navigates from the issue view' do context 'navigates from the issue view' do
......
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