These changes were motivated by switching to a mechanism of loading data that isn't dependent on the big advisory lock that prevents more than one revision from being processed at a time. Since INSERT ... RETURNING id; is used, this can block if another transaction inserts the same data, and then cause an error when that transaction commits. The solution is to use ON CONFLICT DO NOTHING, but you have to handle the case when the INSERT doesn't return an id since the other transaction has inserted it. This commit rewrites insert-missing-data-and-return-all-ids to do as described above, as well as being more efficient in how existing data is detected and to use more vectors. Other utilities for inserting data are added as well.
44 lines
1.1 KiB
Scheme
44 lines
1.1 KiB
Scheme
(define-module (tests model-license)
|
|
#:use-module (srfi srfi-64)
|
|
#:use-module (guix utils)
|
|
#:use-module (guix tests)
|
|
#:use-module (guix-data-service database)
|
|
#:use-module (guix-data-service model license))
|
|
|
|
(test-begin "test-model-license")
|
|
|
|
(define license-data
|
|
'#((("License 1"
|
|
"https://gnu.org/licenses/test-1.html"
|
|
"https://example.com/why-license-1"))
|
|
(("License 1"
|
|
"https://gnu.org/licenses/test-1.html"
|
|
#f)
|
|
("License 2"
|
|
"https://gnu.org/licenses/test-2.html"
|
|
#f)
|
|
("License 3"
|
|
#f
|
|
#f))))
|
|
|
|
(with-postgresql-connection
|
|
"test-model-license"
|
|
(lambda (conn)
|
|
(check-test-database! conn)
|
|
|
|
(with-postgresql-transaction
|
|
conn
|
|
(lambda (conn)
|
|
(test-assert "works"
|
|
(inferior-packages->license-id-lists conn license-data)))
|
|
#:always-rollback? #t)
|
|
|
|
(with-postgresql-transaction
|
|
conn
|
|
(lambda (conn)
|
|
(test-equal "works repeatedly"
|
|
(inferior-packages->license-id-lists conn license-data)
|
|
(inferior-packages->license-id-lists conn license-data)))
|
|
#:always-rollback? #t)))
|
|
|
|
(test-end)
|