Skip to content

Commit

Permalink
chore: fix some flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ericenns committed Nov 27, 2024
1 parent 7f958dc commit 26b657a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
7 changes: 7 additions & 0 deletions test/controllers/projects/samples_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 9 additions & 19 deletions test/services/groups/destroy_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,37 +46,28 @@ 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
# Reference group/projects descendants tree:
# 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
7 changes: 7 additions & 0 deletions test/system/workflow_executions/submissions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 26b657a

Please sign in to comment.