Reduce the number of proposals in pagination spec

We're getting a failure on Travis in one of these tests. Debugging shows
the AJAX request rendering the first page (after clicking the "Previous"
link) takes too long and sometimes it exceeds Capybara's timeout.

After running the test thousands of times, the only way I've found to
clearly reduce the number of times the test fails is to reduce the
number of records shown on the first page. Other experiments, like
adding an `includes(:author)` to the query getting the proposals in the
controller, or adding `author: user` to the `create_list` part of the
test (so only one author needs to be fetched when rendering the
proposals) show inconsistent results regarding performance.

Note we still need at least 10 proposals for the test for several users,
to guarantee two users will never get the same records during the test
(or at least the probability they get the same records is one in
millions).
This commit is contained in:
Javi Martín
2019-09-08 20:26:56 +02:00
parent 64166b34a2
commit 1c071b5ff0

View File

@@ -4,7 +4,6 @@ require "sessions_helper"
describe "Legislation Proposals" do
let(:user) { create(:user) }
let(:user2) { create(:user) }
let(:process) { create(:legislation_process) }
let(:proposal) { create(:legislation_proposal) }
@@ -21,8 +20,10 @@ describe "Legislation Proposals" do
end
describe "Random pagination" do
let(:per_page) { 4 }
before do
allow(Legislation::Proposal).to receive(:default_per_page).and_return(12)
allow(Legislation::Proposal).to receive(:default_per_page).and_return(per_page)
create_list(
:legislation_proposal,
@@ -31,6 +32,10 @@ describe "Legislation Proposals" do
)
end
context "for several users" do
let(:user2) { create(:user) }
let(:per_page) { 12 }
scenario "Each user has a different and consistent random proposals order", :js do
in_browser(:one) do
login_as user
@@ -56,6 +61,7 @@ describe "Legislation Proposals" do
expect(legislation_proposals_order).to eq(@second_user_proposals_order)
end
end
end
scenario "Random order maintained with pagination", :js do
login_as user