-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: sanity tests for primary and replica
* new --replica option to `postgrest-with-postgresql-*` * new command `postgrest-test-replica` * new sanity tests on test_replica.py * add postgrest-test-replica to postgrest-check and postgrest-coverage
- Loading branch information
1 parent
cdb8771
commit d9a51f2
Showing
6 changed files
with
134 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
create schema replica; | ||
|
||
create or replace function replica.is_replica() returns bool as $$ | ||
select pg_is_in_recovery(); | ||
$$ language sql; | ||
|
||
create or replace function replica.get_replica_slot() returns name as $$ | ||
select slot_name from pg_replication_slots limit 1; | ||
$$ language sql; | ||
|
||
create table replica.items as select x as id from generate_series(1, 10) x; | ||
|
||
DROP ROLE IF EXISTS postgrest_test_anonymous; | ||
CREATE ROLE postgrest_test_anonymous; | ||
|
||
GRANT postgrest_test_anonymous TO :PGUSER; | ||
|
||
GRANT USAGE ON SCHEMA replica TO postgrest_test_anonymous; | ||
|
||
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA replica | ||
TO postgrest_test_anonymous; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"IO tests for PostgREST started on replicas" | ||
|
||
import pytest | ||
|
||
from config import * | ||
from util import * | ||
from postgrest import * | ||
|
||
|
||
def test_sanity_replica(replicaenv): | ||
"Test that primary and replica are working as intended" | ||
|
||
with run(env=replicaenv["primary"]) as postgrest: | ||
response = postgrest.session.get("/rpc/is_replica") | ||
assert response.text == "false" | ||
|
||
response = postgrest.session.get("/rpc/get_replica_slot") | ||
assert response.text == '"' + replicaenv["replica"]["PGREPLICASLOT"] + '"' | ||
|
||
response = postgrest.session.get("/items?select=count") | ||
assert response.text == '[{"count":10}]' | ||
|
||
with run(env=replicaenv["replica"]) as postgrest: | ||
response = postgrest.session.get("/rpc/is_replica") | ||
assert response.text == "true" | ||
|
||
response = postgrest.session.get("/items?select=count") | ||
assert response.text == '[{"count":10}]' |