Skip to content

Commit c3f8c40

Browse files
jpengstJP Engstrom
andauthored
Fixes flaky specs (#1674)
Co-authored-by: JP Engstrom <jpengstrom@MWPF1YC393.yu.yale.edu>
1 parent 096296a commit c3f8c40

4 files changed

Lines changed: 22 additions & 18 deletions

File tree

spec/datatables/users_datatable_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
columns = ['netid', 'email', 'deactivated']
99

1010
describe 'user data tables' do
11+
# Datatables get_raw_records returns User.all, any stale User records from other tests in the suite will cause flaky specs.
12+
before { User.destroy_all }
13+
1114
it 'can handle an empty model set' do
1215
output = UserDatatable.new(datatable_sample_params(columns)).data
1316

spec/models/preservica/preservica_child_sync_spec.rb

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,12 @@
106106

107107
it 'can reingest child objects and keep oids, captions and labels but replace image source location' do
108108
allow(S3Service).to receive(:s3_exists?).and_return(false)
109-
expect(ParentObject.count).to eq 1
110-
expect(ChildObject.count).to eq 3
111-
po_first = ParentObject.first
112-
co_first = ChildObject.first
113-
expect(co_first.oid).to eq 1_002_533
114-
expect(co_first.caption).to eq 'original first caption'
115-
expect(co_first.label).to eq 'original first label'
116-
expect(co_first.checksum).to eq 'c314697a5b0fd444e26e7c12a1d8d487545dacfc'
117-
expect(po_first.last_preservica_update).to be nil
109+
expect(aspace_parent.child_objects.count).to eq 3
110+
expect(co_1.oid).to eq 1_002_533
111+
expect(co_1.caption).to eq 'original first caption'
112+
expect(co_1.label).to eq 'original first label'
113+
expect(co_1.checksum).to eq 'c314697a5b0fd444e26e7c12a1d8d487545dacfc'
114+
expect(aspace_parent.last_preservica_update).to be nil
118115
expect(ptf_1.access_primary_path).to eq "spec/fixtures/images/access_primaries/03/33/10/02/53/1002533.tif"
119116
expect(ptf_2.access_primary_path).to eq "spec/fixtures/images/access_primaries/03/34/10/02/53/1002534.tif"
120117
expect(ptf_3.access_primary_path).to eq "spec/fixtures/images/access_primaries/03/35/10/02/53/1002535.tif"
@@ -124,12 +121,12 @@
124121
reingest_batch_process.file = preservica_reingest
125122
reingest_batch_process.save!
126123
end.not_to change { ChildObject.count }
127-
po_first = ParentObject.first
128-
co_first = ChildObject.first
129-
co_second = ChildObject.all[1]
130-
co_third = ChildObject.last
124+
aspace_parent.reload
125+
co_first = co_1.reload
126+
co_second = co_2.reload
127+
co_third = co_3.reload
131128

132-
expect(po_first.last_preservica_update).not_to be nil
129+
expect(aspace_parent.last_preservica_update).not_to be nil
133130
expect(co_first.last_preservica_update).not_to be nil
134131
expect(co_first.sha512_checksum).to eq '1932c08c4670d5010fac6fa363ad5d9be7a4e7d743757ba5eefbbe8e3f9b2fb89b1604c1e527cfae6f47a91a60845268e91d2723aa63a90dd4735f75017569f7'
135132
expect(co_first.oid).to eq 1_002_533

spec/models/preservica/preservica_owp_import_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@
7272
expect do
7373
batch_process.file = preservica_owp_parent_with_children
7474
batch_process.save
75-
end.to change { ChildObject.count }.from(0).to(3)
76-
po_first = ParentObject.first
77-
co_first = ChildObject.first
75+
end.to change { ChildObject.count }.by(3)
76+
po_first = ParentObject.find(200_000_000)
77+
co_first = po_first.child_objects.order(:order).first
7878
expect(co_first.oid).to eq 200_000_001
7979
expect(co_first.parent_object_oid).to eq 200_000_000
8080
expect(co_first.order).to eq 1
81-
co_last = ChildObject.last
81+
co_last = po_first.child_objects.order(:order).last
8282
expect(co_last.order).to eq 3
8383
expect(po_first.last_preservica_update).not_to eq nil
8484
expect(po_first.visibility).to eq "Open with Permission"

spec/system/parent_object_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@
8282
expect(page.body).to include "continuous"
8383
end
8484

85+
# adds an additional expectation to ensure capybara does not visit the showpage before the update has posted. Classic race condition.
8586
it "can set the rights statement via the UI" do
8687
click_on("Create Parent object")
88+
expect(page).to have_content("Parent object was successfully created")
8789
click_on("Edit")
8890
expect(page).to have_field("Rights statement")
8991
fill_in("Rights statement", with: "This is a rights statement")
@@ -199,6 +201,8 @@
199201
click_on("Edit")
200202
select 'Sterling', from: "parent_object[admin_set]"
201203
click_on(UPDATE_PARENT_OBJECT_BUTTON)
204+
# adds an additional expectation to ensure capybara does not visit the showpage before the update has posted. Classic race condition.
205+
expect(page).to have_content("Parent object was successfully saved")
202206

203207
visit parent_object_path(2_012_036)
204208
expect(page).to have_content "Sterling"

0 commit comments

Comments
 (0)