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.
59 lines
1.8 KiB
Scheme
59 lines
1.8 KiB
Scheme
(define-module (tests model-lint-warning-message)
|
|
#:use-module (srfi srfi-64)
|
|
#:use-module (ice-9 match)
|
|
#:use-module (guix-data-service database)
|
|
#:use-module (guix-data-service model lint-warning-message))
|
|
|
|
(test-begin "test-model-lint-warning-message")
|
|
|
|
(define data
|
|
'(("en" . "Test message")
|
|
("es" . "Test message in Spanish")))
|
|
|
|
(with-postgresql-connection
|
|
"test-model-lint-checker"
|
|
(lambda (conn)
|
|
(check-test-database! conn)
|
|
|
|
(test-assert "single insert"
|
|
(with-postgresql-transaction
|
|
conn
|
|
(lambda (conn)
|
|
(match (lint-warning-message-data->lint-warning-message-ids conn data)
|
|
(#((? number? id1) (? number? id2))
|
|
#t)))
|
|
#:always-rollback? #t))
|
|
|
|
(test-assert "double insert"
|
|
(with-postgresql-transaction
|
|
conn
|
|
(lambda (conn)
|
|
(match (lint-warning-message-data->lint-warning-message-ids conn data)
|
|
(#((? number? id1) (? number? id2))
|
|
(match (lint-warning-message-data->lint-warning-message-ids conn data)
|
|
(#((? number? second-id1) (? number? second-id2))
|
|
(and (= id1 second-id1)
|
|
(= id2 second-id2)))))))
|
|
#:always-rollback? #t))
|
|
|
|
(test-assert "single set insert"
|
|
(with-postgresql-transaction
|
|
conn
|
|
(lambda (conn)
|
|
(match (lint-warning-message-data->lint-warning-message-set-id conn data)
|
|
((? number? id1)
|
|
#t)))
|
|
#:always-rollback? #t))
|
|
|
|
(test-assert "double set insert"
|
|
(with-postgresql-transaction
|
|
conn
|
|
(lambda (conn)
|
|
(match (lint-warning-message-data->lint-warning-message-set-id conn data)
|
|
((? number? id)
|
|
(match (lint-warning-message-data->lint-warning-message-set-id conn data)
|
|
((? number? second-id)
|
|
(= id second-id))))))
|
|
#:always-rollback? #t))))
|
|
|
|
(test-end)
|