From 306f5565542c8033551b05c3660690531302bdda Mon Sep 17 00:00:00 2001 From: konnorrogers Date: Thu, 17 Oct 2024 11:26:18 -0400 Subject: [PATCH] implement retry --- .../test/system/attachment_galleries_test.rb | 87 +++++++++++-------- 1 file changed, 50 insertions(+), 37 deletions(-) diff --git a/tests/rails/test/system/attachment_galleries_test.rb b/tests/rails/test/system/attachment_galleries_test.rb index f7da759c..e0fa4242 100644 --- a/tests/rails/test/system/attachment_galleries_test.rb +++ b/tests/rails/test/system/attachment_galleries_test.rb @@ -132,57 +132,70 @@ def check end test "Should not allow to insert multiple attachments in the gallery in sequence" do - page.get_by_role('link', name: /New Post/i).click + def run_test + page.get_by_role('link', name: /New Post/i).click - wait_for_network_idle + wait_for_network_idle - files = [ - "screenshot-1.png", - ] + files = [ + "screenshot-1.png", + ] - attach_files(files) - page.wait_for_selector(".attachment-gallery .attachment[sgid]", state: "visible") + attach_files(files) + page.wait_for_selector(".attachment-gallery .attachment[sgid]", state: "visible") - files = [ - "addresses.csv" - ] + files = [ + "addresses.csv" + ] - attach_files(files) - page.wait_for_selector(":not(.attachment-gallery) .attachment[sgid]", state: "visible") + attach_files(files) + page.wait_for_selector(":not(.attachment-gallery) .attachment[sgid]", state: "visible") - def check - wait_for_network_idle + def check + wait_for_network_idle - page.locator("body").click - assert page.locator(".attachment-gallery .attachment").nth(0).wait_for(state: 'visible') - assert page.locator(".attachment").nth(1).wait_for(state: 'visible') + page.locator("body").click + assert page.locator(".attachment-gallery .attachment").nth(0).wait_for(state: 'visible') + assert page.locator(".attachment").nth(1).wait_for(state: 'visible') - assert_equal page.locator(".attachment-gallery .attachment").count, 1 - assert_equal page.locator(".attachment").count, 2 - page.locator("body").click - end + assert_equal page.locator(".attachment-gallery .attachment").count, 1 + assert_equal page.locator(".attachment").count, 2 + page.locator("body").click + end - check + check - # Save the attachment, make sure we render properly. - page.get_by_role('button', name: /Create Post/i).click + # Save the attachment, make sure we render properly. + page.get_by_role('button', name: /Create Post/i).click - assert page.get_by_text("Post was successfully created") - check + assert page.get_by_text("Post was successfully created") + check - # Go back and edit the file and make sure it renders properly in editor - page.get_by_role('link', name: /Edit this post/i).click + # Go back and edit the file and make sure it renders properly in editor + page.get_by_role('link', name: /Edit this post/i).click - assert page.get_by_text("Editing post") + assert page.get_by_text("Editing post") - check + check - # Go back and edit the file and make sure it renders properly in editor - page.get_by_role('link', name: /Show this post/i).click - wait_for_network_idle - page.locator("body").click - page.get_by_role('link', name: /Edit raw post/i).click - assert page.get_by_text("Editing raw post") - check + # Go back and edit the file and make sure it renders properly in editor + page.get_by_role('link', name: /Show this post/i).click + wait_for_network_idle + page.locator("body").click + page.get_by_role('link', name: /Edit raw post/i).click + assert page.get_by_text("Editing raw post") + check + end + + count = 0 + + # Hacky retry + begin + run_test + rescue => e + count += 1 + raise e if count > 2 + run_test + end end end