lp1145213 avoid race condition in bib merge test
authorJason Etheridge <jason@EquinoxInitiative.org>
Tue, 9 Apr 2019 21:34:16 +0000 (17:34 -0400)
committerMike Rylander <mrylander@gmail.com>
Wed, 10 Apr 2019 16:43:56 +0000 (12:43 -0400)
Signed-off-by: Jason Etheridge <jason@EquinoxInitiative.org>
Open-ILS/src/sql/Pg/live_t/lp1145213_test_func_asset.merge_record_assets.pg [new file with mode: 0644]
Open-ILS/src/sql/Pg/t/lp1145213_test_func_asset.merge_record_assets.pg [deleted file]

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 (file)
index 0000000..5eae39e
--- /dev/null
@@ -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, 
+  $$
+  <record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" xmlns="http://www.loc.gov/MARC21/slim"><leader>00934njm a2200241 a 4500</leader><controlfield tag="001">03-0003745</controlfield><controlfield tag="005">19991118131708.0</controlfield><controlfield tag="008">971016n nyuuuu eng </controlfield><datafield tag="050" ind1=" " ind2=" "><subfield code="a">4539</subfield></datafield><datafield tag="100" ind1="1" ind2=" "><subfield code="a">Bart&#xF3;k, B&#xE9;la,</subfield><subfield code="d">1881-1945.</subfield></datafield><datafield tag="240" ind1=" " ind2=" "><subfield code="t">Concertos,</subfield><subfield code="m">piano,</subfield><subfield code="n">no. 1,</subfield><subfield code="n">Sz. 83</subfield><subfield code="f">(1926) </subfield><subfield code="a">Concertos,</subfield><subfield code="m">piano,</subfield><subfield code="n">no. 1,</subfield><subfield code="n">Sz. 83,</subfield><subfield code="n">(1926)</subfield></datafield><datafield tag="245" ind1=" " ind2=" "><subfield code="a">Piano concerto no. 1 (1926) ; Rhapsody, op. 1 (1904)</subfield></datafield><datafield tag="260" ind1=" " ind2=" "><subfield code="a">New York, NY :</subfield><subfield code="b">Vox</subfield></datafield><datafield tag="300" ind1=" " ind2=" "><subfield code="a">1 sound disc :</subfield><subfield code="b">33 1/3 rpm, stereo.</subfield></datafield><datafield tag="349" ind1=" " ind2=" "><subfield code="a">PHONO RECORD</subfield></datafield><datafield tag="511" ind1=" " ind2=" "><subfield code="a">Gy&#xF6;rgy S&#xE1;ndor, piano ; Sudwest[rund]funkorchester, Baden-Baden ; Rolf Reinhardt, conductor.</subfield></datafield><datafield tag="700" ind1="1" ind2=" "><subfield code="a">S&#xE1;ndor, Gy&#xF6;rgy,</subfield><subfield code="d">1912-</subfield></datafield><datafield tag="700" ind1="1" ind2=" "><subfield code="a">Reinhardt, Rolf</subfield></datafield><datafield tag="710" ind1=" " ind2=" "><subfield code="a">Sudwestrundfunkorchester (Baden-Baden, Germany)</subfield></datafield><datafield tag="730" ind1=" " ind2=" "><subfield code="a">Rhapsodies,</subfield><subfield code="m">piano, orchestra,</subfield><subfield code="n">op. 1,</subfield><subfield code="n">Sz. 27,</subfield><subfield code="n">(1904)</subfield></datafield><datafield tag="901" ind1=" " ind2=" "><subfield code="a">a339398</subfield><subfield code="b">Sirsi_Auto</subfield><subfield code="c">339398</subfield></datafield></record>
+  $$,
+  'PGTAP'
+  );
+
+
+-- create bib 60,001
+INSERT into biblio.record_entry (id, marc, last_xact_id)
+  VALUES (60001,
+  $$
+  <record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" xmlns="http://www.loc.gov/MARC21/slim"><leader>00863njm a2200253 a 4500</leader><controlfield tag="001">03-0004689</controlfield><controlfield tag="005">19991127191346.0</controlfield><controlfield tag="008">971027r19631952nyuuuu eng </controlfield><datafield tag="050" ind1=" " ind2=" "><subfield code="a">4578</subfield></datafield><datafield tag="100" ind1="1" ind2=" "><subfield code="a">Telemann, Georg Philipp,</subfield><subfield code="d">1681-1767</subfield></datafield><datafield tag="245" ind1=" " ind2=" "><subfield code="a">Viola concerto in G major</subfield></datafield><datafield tag="260" ind1=" " ind2=" "><subfield code="a">New York, NY :</subfield><subfield code="b">Vox,</subfield><subfield code="c">1963</subfield></datafield><datafield tag="300" ind1=" " ind2=" "><subfield code="a">1 sound disc :</subfield><subfield code="b">33 1/3 rpm, mono.</subfield></datafield><datafield tag="349" ind1=" " ind2=" "><subfield code="a">PHONO RECORD</subfield></datafield><datafield tag="505" ind1=" " ind2=" "><subfield code="a">Viola concerto / Telemann -- Viola concerto in D major / Stamitz.</subfield></datafield><datafield tag="511" ind1=" " ind2=" "><subfield code="a">Heinz Wigand, viola ; Pro Musica Orchestra, Stuttgart ; Rolf Reinhardt, conductor.</subfield></datafield><datafield tag="650" ind1=" " ind2="0"><subfield code="a">Concertos (Viola)</subfield></datafield><datafield tag="700" ind1="1" ind2=" "><subfield code="a">Stamitz, Carl,</subfield><subfield code="d">1745-1801</subfield></datafield><datafield tag="700" ind1="1" ind2=" "><subfield code="a">Reinhardt, Rolf</subfield></datafield><datafield tag="700" ind1=" " ind2=" "><subfield code="a">Wigand, Heinz</subfield></datafield><datafield tag="710" ind1="2" ind2=" "><subfield code="a">Pro Musica Orchestra (Stuttgart)</subfield></datafield><datafield tag="901" ind1=" " ind2=" "><subfield code="a">a340312</subfield><subfield code="b">Sirsi_Auto</subfield><subfield code="c">340312</subfield></datafield></record>
+  $$,
+  '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 (file)
index c6adcb3..0000000
+++ /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, 
-  $$
-  <record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" xmlns="http://www.loc.gov/MARC21/slim"><leader>00934njm a2200241 a 4500</leader><controlfield tag="001">03-0003745</controlfield><controlfield tag="005">19991118131708.0</controlfield><controlfield tag="008">971016n nyuuuu eng </controlfield><datafield tag="050" ind1=" " ind2=" "><subfield code="a">4539</subfield></datafield><datafield tag="100" ind1="1" ind2=" "><subfield code="a">Bart&#xF3;k, B&#xE9;la,</subfield><subfield code="d">1881-1945.</subfield></datafield><datafield tag="240" ind1=" " ind2=" "><subfield code="t">Concertos,</subfield><subfield code="m">piano,</subfield><subfield code="n">no. 1,</subfield><subfield code="n">Sz. 83</subfield><subfield code="f">(1926) </subfield><subfield code="a">Concertos,</subfield><subfield code="m">piano,</subfield><subfield code="n">no. 1,</subfield><subfield code="n">Sz. 83,</subfield><subfield code="n">(1926)</subfield></datafield><datafield tag="245" ind1=" " ind2=" "><subfield code="a">Piano concerto no. 1 (1926) ; Rhapsody, op. 1 (1904)</subfield></datafield><datafield tag="260" ind1=" " ind2=" "><subfield code="a">New York, NY :</subfield><subfield code="b">Vox</subfield></datafield><datafield tag="300" ind1=" " ind2=" "><subfield code="a">1 sound disc :</subfield><subfield code="b">33 1/3 rpm, stereo.</subfield></datafield><datafield tag="349" ind1=" " ind2=" "><subfield code="a">PHONO RECORD</subfield></datafield><datafield tag="511" ind1=" " ind2=" "><subfield code="a">Gy&#xF6;rgy S&#xE1;ndor, piano ; Sudwest[rund]funkorchester, Baden-Baden ; Rolf Reinhardt, conductor.</subfield></datafield><datafield tag="700" ind1="1" ind2=" "><subfield code="a">S&#xE1;ndor, Gy&#xF6;rgy,</subfield><subfield code="d">1912-</subfield></datafield><datafield tag="700" ind1="1" ind2=" "><subfield code="a">Reinhardt, Rolf</subfield></datafield><datafield tag="710" ind1=" " ind2=" "><subfield code="a">Sudwestrundfunkorchester (Baden-Baden, Germany)</subfield></datafield><datafield tag="730" ind1=" " ind2=" "><subfield code="a">Rhapsodies,</subfield><subfield code="m">piano, orchestra,</subfield><subfield code="n">op. 1,</subfield><subfield code="n">Sz. 27,</subfield><subfield code="n">(1904)</subfield></datafield><datafield tag="901" ind1=" " ind2=" "><subfield code="a">a339398</subfield><subfield code="b">Sirsi_Auto</subfield><subfield code="c">339398</subfield></datafield></record>
-  $$,
-  'PGTAP'
-  );
-
-
--- create bib 60,001
-INSERT into biblio.record_entry (id, marc, last_xact_id)
-  VALUES (60001,
-  $$
-  <record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" xmlns="http://www.loc.gov/MARC21/slim"><leader>00863njm a2200253 a 4500</leader><controlfield tag="001">03-0004689</controlfield><controlfield tag="005">19991127191346.0</controlfield><controlfield tag="008">971027r19631952nyuuuu eng </controlfield><datafield tag="050" ind1=" " ind2=" "><subfield code="a">4578</subfield></datafield><datafield tag="100" ind1="1" ind2=" "><subfield code="a">Telemann, Georg Philipp,</subfield><subfield code="d">1681-1767</subfield></datafield><datafield tag="245" ind1=" " ind2=" "><subfield code="a">Viola concerto in G major</subfield></datafield><datafield tag="260" ind1=" " ind2=" "><subfield code="a">New York, NY :</subfield><subfield code="b">Vox,</subfield><subfield code="c">1963</subfield></datafield><datafield tag="300" ind1=" " ind2=" "><subfield code="a">1 sound disc :</subfield><subfield code="b">33 1/3 rpm, mono.</subfield></datafield><datafield tag="349" ind1=" " ind2=" "><subfield code="a">PHONO RECORD</subfield></datafield><datafield tag="505" ind1=" " ind2=" "><subfield code="a">Viola concerto / Telemann -- Viola concerto in D major / Stamitz.</subfield></datafield><datafield tag="511" ind1=" " ind2=" "><subfield code="a">Heinz Wigand, viola ; Pro Musica Orchestra, Stuttgart ; Rolf Reinhardt, conductor.</subfield></datafield><datafield tag="650" ind1=" " ind2="0"><subfield code="a">Concertos (Viola)</subfield></datafield><datafield tag="700" ind1="1" ind2=" "><subfield code="a">Stamitz, Carl,</subfield><subfield code="d">1745-1801</subfield></datafield><datafield tag="700" ind1="1" ind2=" "><subfield code="a">Reinhardt, Rolf</subfield></datafield><datafield tag="700" ind1=" " ind2=" "><subfield code="a">Wigand, Heinz</subfield></datafield><datafield tag="710" ind1="2" ind2=" "><subfield code="a">Pro Musica Orchestra (Stuttgart)</subfield></datafield><datafield tag="901" ind1=" " ind2=" "><subfield code="a">a340312</subfield><subfield code="b">Sirsi_Auto</subfield><subfield code="c">340312</subfield></datafield></record>
-  $$,
-  '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;
-