Alan Guo Xiang Tan 4dd053a69c
DEV: Call MessageBus.stop() after each system test (#21848)
## What is the problem?

MessageBus by default uses long polling which keeps a connection
open for 25 seconds by default. The problem here is that Capybara does not know about these
connections being kept opened by MessageBus and hence does not know how
to stop these connections at the end of each test. As a result, the long polling MessageBus connections are kept opened by the browser and we hit chrome's limit of 6 concurrent requests per host, new request made in the browser is marked as "pending" until a request is freed up. Since we keep a MessageBus long polling connection opened for 25 seconds, our finders in Capybara end up hitting Capybara's wait time out causing the tests to fail.  

## What is the fix?

Since we can't rely on Capybara to close all the existing Capybara
connections, we manually execute a script to stop all MessageBus
connections after each system test.

```
for i in {1..10}; do
  echo "Running iteration $i"
  PARALLEL_TEST_PROCESSORS=8 CAPYBARA_DEFAULT_MAX_WAIT_TIME=10 bin/turbo_rspec --seed=34908 --profile --verbose --format documentation spec/system
  if [ $? -ne 0 ]; then
    echo "Error encountered on iteration $i"
    exit 1
  fi
done
echo "All 10 iterations completed successfully"
```

Without the fix, the script fails consistently in the first few iterations. Running in non-headless mode with the "network" tab opened will reveal the requests that are marked as pending.
2023-05-31 21:00:35 +08:00

90 lines
2.3 KiB
Ruby

# frozen_string_literal: true
module PageObjects
module Pages
class FormTemplate < PageObjects::Pages::Base
def visit
page.visit("/admin/customize/form-templates")
self
end
def visit_new
page.visit("/admin/customize/form-templates/new")
self
end
# Form Template Index
def has_form_template_table?
page.has_selector?("table.form-templates__table")
end
def click_view_form_template
find(".form-templates__table tr:first-child .btn-view-template").click
end
def click_toggle_preview
find(".d-toggle-switch .d-toggle-switch__checkbox-slider", visible: false).click
self
end
def has_form_template?(name)
find(".form-templates__table tbody tr td", text: name).present?
end
def has_category_in_template_row?(category_name)
find(".form-templates__table .categories .category-name", text: category_name).present?
end
def has_template_structure?(structure)
find("code", text: structure).present?
end
# Form Template new/edit form related
def type_in_template_name(input)
find(".form-templates__form-name-input").fill_in(with: input)
self
end
def click_save_button
find(".form-templates__form .footer-buttons .btn-primary:enabled", visible: :all).click
end
def click_quick_insert(field_type)
find(".form-templates__form .quick-insert-#{field_type}").click
end
def click_validations_button
find(".form-templates__validations-modal-button").click
end
def click_preview_button
find(".form-templates__preview-button:enabled").click
end
def has_input_field?(type)
find(".form-template-field__#{type}").present?
end
def has_preview_modal?
find(".form-template-form-preview-modal").present?
end
def has_validations_modal?
find(".admin-form-template-validation-options-modal").present?
end
def has_name_value?(name)
find(".form-templates__form-name-input").value == name
end
def has_save_button_with_state?(disabled:)
find_button("Save", disabled:)
end
def has_preview_button_with_state?(disabled:)
find_button("Preview", disabled:)
end
end
end
end