This repository has been archived on 2025-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
lwb6/legacyworlds-server-data/db-structure/tests/dirty/000-dirty-tests-self-check/prepare.sql
Emmanuel BENOîT c18bdc2d1f Dirty SQL test system
* Added a system that allows "dirty" tests to be written. These tests
actually need to change the database, so a temporary test database must
be created to run them.
2012-01-14 09:02:24 +01:00

23 lines
525 B
PL/PgSQL

/*
* Dirty test system self-check
*
* Insert an address, it should exist during the main test. Also create a
* function and a table which are used to synchronise execution.
*/
BEGIN;
INSERT INTO users.addresses ( address )
VALUES ( 'prepare@example.org' );
CREATE TABLE _barriers( _barrier BIGINT );
CREATE FUNCTION _synchronise_tests( _lock BIGINT )
RETURNS VOID
AS $$
BEGIN
WHILE pg_try_advisory_lock( _lock )
LOOP
PERFORM pg_advisory_unlock( _lock );
END LOOP;
END;
$$ LANGUAGE PLPGSQL;
COMMIT;