From bbe8a9295e8e309b3c240808ba7e2ad491dbf82c Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Tue, 9 Apr 2019 17:34:16 -0400 Subject: [PATCH] lp1145213 avoid race condition in bib merge test Signed-off-by: Jason Etheridge --- ...p1145213_test_func_asset.merge_record_assets.pg | 94 ++++++++++++++++++++ ...p1145213_test_func_asset.merge_record_assets.pg | 94 -------------------- 2 files changed, 94 insertions(+), 94 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/live_t/lp1145213_test_func_asset.merge_record_assets.pg delete mode 100644 Open-ILS/src/sql/Pg/t/lp1145213_test_func_asset.merge_record_assets.pg diff --git a/Open-ILS/src/sql/Pg/live_t/lp1145213_test_func_asset.merge_record_assets.pg b/Open-ILS/src/sql/Pg/live_t/lp1145213_test_func_asset.merge_record_assets.pg new file mode 100644 index 0000000..5eae39e --- /dev/null +++ b/Open-ILS/src/sql/Pg/live_t/lp1145213_test_func_asset.merge_record_assets.pg @@ -0,0 +1,94 @@ +BEGIN; + +SELECT plan(5); + +---------------------------------- +-- +-- Setup Test environment and data +-- +---------------------------------- + +-- create mock bib records to be merged: +-- Data: +-- bib 60000 (new lead), org 4 acn 'F Cline' copy 1 +-- bib 60001 (merged from target), org 5 acn 'JF cline' copy 2, org 6 acn 'JF Cline' copy 3, org 4 acn 'F Cline' copy 4 +-- +-- copy 2 ACN + +-- create bib 60,000 +INSERT into biblio.record_entry (id, marc, last_xact_id) + VALUES (60000, + $$ + 00934njm a2200241 a 450003-000374519991118131708.0971016n nyuuuu eng 4539Bartók, Béla,1881-1945.Concertos,piano,no. 1,Sz. 83(1926) Concertos,piano,no. 1,Sz. 83,(1926)Piano concerto no. 1 (1926) ; Rhapsody, op. 1 (1904)New York, NY :Vox1 sound disc :33 1/3 rpm, stereo.PHONO RECORDGyörgy Sándor, piano ; Sudwest[rund]funkorchester, Baden-Baden ; Rolf Reinhardt, conductor.Sándor, György,1912-Reinhardt, RolfSudwestrundfunkorchester (Baden-Baden, Germany)Rhapsodies,piano, orchestra,op. 1,Sz. 27,(1904)a339398Sirsi_Auto339398 + $$, + 'PGTAP' + ); + + +-- create bib 60,001 +INSERT into biblio.record_entry (id, marc, last_xact_id) + VALUES (60001, + $$ + 00863njm a2200253 a 450003-000468919991127191346.0971027r19631952nyuuuu eng 4578Telemann, Georg Philipp,1681-1767Viola concerto in G majorNew York, NY :Vox,19631 sound disc :33 1/3 rpm, mono.PHONO RECORDViola concerto / Telemann -- Viola concerto in D major / Stamitz.Heinz Wigand, viola ; Pro Musica Orchestra, Stuttgart ; Rolf Reinhardt, conductor.Concertos (Viola)Stamitz, Carl,1745-1801Reinhardt, RolfWigand, HeinzPro Musica Orchestra (Stuttgart)a340312Sirsi_Auto340312 + $$, + 'PGTAP' + ); + + +INSERT into asset.call_number(id, record, creator, editor, owning_lib, label, label_class, prefix) + VALUES (999999, 60000, 1, 1, 4, 'Cline', 1, 9986), + (1000000,60001, 1, 1, 5, 'Cline', 1, 9987), + (1000001,60001, 1, 1, 6, 'Cline', 1, 9988), + (1000002,60001, 1, 1, 4, 'Cline', 1, 9986); + +INSERT into asset.call_number_prefix(id, owning_lib, label) VALUES + (9986, 4, 'F'), + (9987, 5, 'F'), + (9988, 6, 'JF'); + +-- circ_lib for copy == the same as acn +INSERT INTO asset.copy(id, circ_lib, creator, call_number, editor, copy_number, loan_duration, fine_level, barcode) VALUES + (905555, 4, 1, 999999, 1, 1, 1, 1, '1copycopycopy'), + (906666, 5, 1, 1000000, 1, 1, 1, 1, '2copycopycopy'), + (907777, 6, 1, 1000001, 1, 1, 1, 1, '3copycopycopy'), + (908888, 4, 1, 1000002, 1, 1, 1, 1, '4copycopycopy'); + +COMMIT; + +----------------------------------- +-- Test asset.merge_record_assets() +----------------------------------- + +-- do merge +SELECT is(asset.merge_record_assets(60000, 60001), 4, 'Record assets merged!'); + +-- check if copy 4's acn was updated +SELECT is( + (SELECT call_number from asset.copy where id=908888)::BIGINT, + 999999::BIGINT, + 'LP 1145213 asset.merge_record_assets() messing up call numbers. copy 4 should have acn -> 999999' +); + +-- acn #1,000,002 should be deleted +SELECT is( + (SELECT deleted FROM asset.call_number WHERE id=1000002)::BOOLEAN, + TRUE, + 'LP 1145213 asset.merge_record_assets() should have deleted acn #1000002' +); + +-- all non-deleted acn should point to source bib record #60,000 +SELECT is( + (SELECT count(*) FROM asset.call_number WHERE record=60001 AND not deleted=true)::INT, + 0::INT, + 'LP 1145213 asset.merge_record_assets() all call_numbers should point to bib record #60,000 ' +); + +-- test copies to make sure none point to stale acn +SELECT is( + (SELECT count(*) from asset.copy where call_number=1000002)::INT, + 0::INT, + 'LP 1145213 asset.merge_record_assets() all copies should point to acn #999999 which is for bib record #60,000 ' +); + +SELECT * FROM finish(); + diff --git a/Open-ILS/src/sql/Pg/t/lp1145213_test_func_asset.merge_record_assets.pg b/Open-ILS/src/sql/Pg/t/lp1145213_test_func_asset.merge_record_assets.pg deleted file mode 100644 index c6adcb3..0000000 --- a/Open-ILS/src/sql/Pg/t/lp1145213_test_func_asset.merge_record_assets.pg +++ /dev/null @@ -1,94 +0,0 @@ -BEGIN; - -SELECT plan(5); - ----------------------------------- --- --- Setup Test environment and data --- ----------------------------------- - --- create mock bib records to be merged: --- Data: --- bib 60000 (new lead), org 4 acn 'F Cline' copy 1 --- bib 60001 (merged from target), org 5 acn 'JF cline' copy 2, org 6 acn 'JF Cline' copy 3, org 4 acn 'F Cline' copy 4 --- --- copy 2 ACN - --- create bib 60,000 -INSERT into biblio.record_entry (id, marc, last_xact_id) - VALUES (60000, - $$ - 00934njm a2200241 a 450003-000374519991118131708.0971016n nyuuuu eng 4539Bartók, Béla,1881-1945.Concertos,piano,no. 1,Sz. 83(1926) Concertos,piano,no. 1,Sz. 83,(1926)Piano concerto no. 1 (1926) ; Rhapsody, op. 1 (1904)New York, NY :Vox1 sound disc :33 1/3 rpm, stereo.PHONO RECORDGyörgy Sándor, piano ; Sudwest[rund]funkorchester, Baden-Baden ; Rolf Reinhardt, conductor.Sándor, György,1912-Reinhardt, RolfSudwestrundfunkorchester (Baden-Baden, Germany)Rhapsodies,piano, orchestra,op. 1,Sz. 27,(1904)a339398Sirsi_Auto339398 - $$, - 'PGTAP' - ); - - --- create bib 60,001 -INSERT into biblio.record_entry (id, marc, last_xact_id) - VALUES (60001, - $$ - 00863njm a2200253 a 450003-000468919991127191346.0971027r19631952nyuuuu eng 4578Telemann, Georg Philipp,1681-1767Viola concerto in G majorNew York, NY :Vox,19631 sound disc :33 1/3 rpm, mono.PHONO RECORDViola concerto / Telemann -- Viola concerto in D major / Stamitz.Heinz Wigand, viola ; Pro Musica Orchestra, Stuttgart ; Rolf Reinhardt, conductor.Concertos (Viola)Stamitz, Carl,1745-1801Reinhardt, RolfWigand, HeinzPro Musica Orchestra (Stuttgart)a340312Sirsi_Auto340312 - $$, - 'PGTAP' - ); - - -INSERT into asset.call_number(id, record, creator, editor, owning_lib, label, label_class, prefix) - VALUES (999999, 60000, 1, 1, 4, 'Cline', 1, 9986), - (1000000,60001, 1, 1, 5, 'Cline', 1, 9987), - (1000001,60001, 1, 1, 6, 'Cline', 1, 9988), - (1000002,60001, 1, 1, 4, 'Cline', 1, 9986); - -INSERT into asset.call_number_prefix(id, owning_lib, label) VALUES - (9986, 4, 'F'), - (9987, 5, 'F'), - (9988, 6, 'JF'); - --- circ_lib for copy == the same as acn -INSERT INTO asset.copy(id, circ_lib, creator, call_number, editor, copy_number, loan_duration, fine_level, barcode) VALUES - (905555, 4, 1, 999999, 1, 1, 1, 1, '1copycopycopy'), - (906666, 5, 1, 1000000, 1, 1, 1, 1, '2copycopycopy'), - (907777, 6, 1, 1000001, 1, 1, 1, 1, '3copycopycopy'), - (908888, 4, 1, 1000002, 1, 1, 1, 1, '4copycopycopy'); - ------------------------------------ --- Test asset.merge_record_assets() ------------------------------------ - --- do merge -SELECT is(asset.merge_record_assets(60000, 60001), 4, 'Record assets merged!'); - --- check if copy 4's acn was updated -SELECT is( - (SELECT call_number from asset.copy where id=908888)::BIGINT, - 999999::BIGINT, - 'LP 1145213 asset.merge_record_assets() messing up call numbers. copy 4 should have acn -> 999999' -); - --- acn #1,000,002 should be deleted -SELECT is( - (SELECT deleted FROM asset.call_number WHERE id=1000002)::BOOLEAN, - TRUE, - 'LP 1145213 asset.merge_record_assets() should have deleted acn #1000002' -); - --- all non-deleted acn should point to source bib record #60,000 -SELECT is( - (SELECT count(*) FROM asset.call_number WHERE record=60001 AND not deleted=true)::INT, - 0::INT, - 'LP 1145213 asset.merge_record_assets() all call_numbers should point to bib record #60,000 ' -); - --- test copies to make sure none point to stale acn -SELECT is( - (SELECT count(*) from asset.copy where call_number=1000002)::INT, - 0::INT, - 'LP 1145213 asset.merge_record_assets() all copies should point to acn #999999 which is for bib record #60,000 ' -); - -SELECT * FROM finish(); - -ROLLBACK; - -- 1.7.2.5