Commit c08beb50 authored by João Cunha's avatar João Cunha

Don't use sleep in feature specs

parent 34d837b5
...@@ -31,6 +31,8 @@ describe 'Clusters Applications', :js do ...@@ -31,6 +31,8 @@ describe 'Clusters Applications', :js do
let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) } let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
it 'user can install applications' do it 'user can install applications' do
wait_for_requests
page.within('.js-cluster-application-row-helm') do page.within('.js-cluster-application-row-helm') do
expect(page.find(:css, '.js-cluster-application-install-button')['disabled']).to be_nil expect(page.find(:css, '.js-cluster-application-install-button')['disabled']).to be_nil
expect(page).to have_css('.js-cluster-application-install-button', exact_text: 'Install') expect(page).to have_css('.js-cluster-application-install-button', exact_text: 'Install')
...@@ -44,6 +46,8 @@ describe 'Clusters Applications', :js do ...@@ -44,6 +46,8 @@ describe 'Clusters Applications', :js do
page.within('.js-cluster-application-row-helm') do page.within('.js-cluster-application-row-helm') do
page.find(:css, '.js-cluster-application-install-button').click page.find(:css, '.js-cluster-application-install-button').click
end end
wait_for_requests
end end
it 'they see status transition' do it 'they see status transition' do
...@@ -52,8 +56,6 @@ describe 'Clusters Applications', :js do ...@@ -52,8 +56,6 @@ describe 'Clusters Applications', :js do
expect(page.find(:css, '.js-cluster-application-install-button')['disabled']).to eq('true') expect(page.find(:css, '.js-cluster-application-install-button')['disabled']).to eq('true')
expect(page).to have_css('.js-cluster-application-install-button', exact_text: 'Installing') expect(page).to have_css('.js-cluster-application-install-button', exact_text: 'Installing')
wait_until_app_created!('helm')
Clusters::Cluster.last.application_helm.make_installing! Clusters::Cluster.last.application_helm.make_installing!
# FE starts polling and update the buttons to "Installing" # FE starts polling and update the buttons to "Installing"
...@@ -113,7 +115,7 @@ describe 'Clusters Applications', :js do ...@@ -113,7 +115,7 @@ describe 'Clusters Applications', :js do
click_button 'Install' click_button 'Install'
wait_until_app_created!('knative') wait_for_requests
expect(page).to have_css('.js-cluster-application-install-button', exact_text: 'Installing') expect(page).to have_css('.js-cluster-application-install-button', exact_text: 'Installing')
...@@ -143,7 +145,7 @@ describe 'Clusters Applications', :js do ...@@ -143,7 +145,7 @@ describe 'Clusters Applications', :js do
click_button 'Save changes' click_button 'Save changes'
wait_until_app_updated!(cluster.application_knative) wait_for_requests
expect(domainname_form_value).to eq('new.domain.example.org') expect(domainname_form_value).to eq('new.domain.example.org')
end end
...@@ -202,6 +204,8 @@ describe 'Clusters Applications', :js do ...@@ -202,6 +204,8 @@ describe 'Clusters Applications', :js do
page.within('.js-cluster-application-row-ingress') do page.within('.js-cluster-application-row-ingress') do
expect(page).to have_css('.js-cluster-application-install-button:not([disabled])') expect(page).to have_css('.js-cluster-application-install-button:not([disabled])')
page.find(:css, '.js-cluster-application-install-button').click page.find(:css, '.js-cluster-application-install-button').click
wait_for_requests
end end
end end
...@@ -238,25 +242,4 @@ describe 'Clusters Applications', :js do ...@@ -238,25 +242,4 @@ describe 'Clusters Applications', :js do
end end
end end
end end
def wait_until_app_created!(app)
retries = 0
while Clusters::Cluster.last.send("application_#{app}").nil?
raise "Timed out waiting for #{app} application to be created in DB" if (retries += 1) > 3
sleep(1)
end
end
def wait_until_app_updated!(app)
retries = 0
updated_at = app.updated_at
while updated_at == app.reload.updated_at
raise "Timed out waiting for #{app} application to be created in DB" if (retries += 1) > 3
sleep(1)
end
end
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