From 26b657adbcf1624d5e9091b640359d2c1d8ff6ed Mon Sep 17 00:00:00 2001 From: Eric Enns <492127+ericenns@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:48:22 -0600 Subject: [PATCH] chore: fix some flaky tests --- .../projects/samples_controller_test.rb | 7 +++++ test/services/groups/destroy_service_test.rb | 28 ++++++------------- .../workflow_executions/submissions_test.rb | 7 +++++ 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/test/controllers/projects/samples_controller_test.rb b/test/controllers/projects/samples_controller_test.rb index 37b5238ab5..cc73d9f9ba 100644 --- a/test/controllers/projects/samples_controller_test.rb +++ b/test/controllers/projects/samples_controller_test.rb @@ -10,6 +10,13 @@ class SamplesControllerTest < ActionDispatch::IntegrationTest @sample23 = samples(:sample23) @project = projects(:project1) @namespace = groups(:group_one) + + Sample.reindex + Searchkick.enable_callbacks + end + + teardown do + Searchkick.enable_callbacks end test 'should get index where member in parent group' do diff --git a/test/services/groups/destroy_service_test.rb b/test/services/groups/destroy_service_test.rb index 6598b705ec..d0982ac33c 100644 --- a/test/services/groups/destroy_service_test.rb +++ b/test/services/groups/destroy_service_test.rb @@ -18,7 +18,6 @@ def setup assert_difference -> { Group.count } => -1 do Groups::DestroyService.new(@group, @user).execute end - assert @group.errors.empty? end test 'delete group with incorrect permissions' do @@ -47,18 +46,14 @@ def setup # group12 < subgroup12b (project30 > sample 33) # | # ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35) - assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12aa.metadata_summary) - assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, @subgroup12a.metadata_summary) - assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12b.metadata_summary) - assert_equal({ 'metadatafield1' => 3, 'metadatafield2' => 3 }, @group12.metadata_summary) - - assert_no_changes -> { @subgroup12b.reload.metadata_summary } do + assert_difference -> { @subgroup12a.reload.metadata_summary['metadatafield1'] } => -1, + -> { @subgroup12a.reload.metadata_summary['metadatafield2'] } => -1, + -> { @group12.reload.metadata_summary['metadatafield1'] } => -1, + -> { @group12.reload.metadata_summary['metadatafield2'] } => -1 do Groups::DestroyService.new(@subgroup12aa, @user).execute end - assert(@subgroup12aa.reload.deleted?) - assert_equal({ 'metadatafield1' => 1, 'metadatafield2' => 1 }, @subgroup12a.reload.metadata_summary) - assert_equal({ 'metadatafield1' => 2, 'metadatafield2' => 2 }, @group12.reload.metadata_summary) + assert @subgroup12aa.reload.deleted? end test 'samples count updated after group deletion' do @@ -66,18 +61,13 @@ def setup # group12 < subgroup12b (project30 > sample 33) # | # ---- < subgroup12a (project29 > sample 32) < subgroup12aa (project31 > sample34 + 35) - assert_equal(2, @subgroup12aa.samples_count) - assert_equal(3, @subgroup12a.samples_count) - assert_equal(1, @subgroup12b.samples_count) - assert_equal(4, @group12.samples_count) - - assert_no_changes -> { @subgroup12b.reload.samples_count } do + assert_difference -> { @subgroup12a.reload.samples_count } => -2, + -> { @group12.reload.samples_count } => -2, + -> { @subgroup12b.reload.samples_count } => 0 do Groups::DestroyService.new(@subgroup12aa, @user).execute end - assert(@subgroup12aa.reload.deleted?) - assert_equal(1, @subgroup12a.reload.samples_count) - assert_equal(2, @group12.reload.samples_count) + assert @subgroup12aa.reload.deleted? end end end diff --git a/test/system/workflow_executions/submissions_test.rb b/test/system/workflow_executions/submissions_test.rb index 751344ce28..eedb2a9993 100644 --- a/test/system/workflow_executions/submissions_test.rb +++ b/test/system/workflow_executions/submissions_test.rb @@ -13,6 +13,13 @@ class SubmissionsTest < ApplicationSystemTestCase @namespace = groups(:group_sixteen) Project.reset_counters(@project.id, :samples_count) + + Sample.reindex + Searchkick.enable_callbacks + end + + teardown do + Searchkick.disable_callbacks end test 'should display a pipeline selection modal for project samples as owner' do