Skip to content

Commit 91abcd4

Browse files
taimoorzaeemsteve-chavez
authored andcommitted
test(io): move resource embedding tests to test_io.py
- Adds fixtures to `test/io/fixtures.sql` to test resource embedding related queries. - Moves the resource embedding related tests that no longer require big schema from `test_big_schema.py` to `test_io.py`. Closes #4417. Signed-off-by: Taimoor Zaeem <[email protected]>
1 parent 770c404 commit 91abcd4

File tree

6 files changed

+213
-53
lines changed

6 files changed

+213
-53
lines changed
Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
1-
[]
1+
- - - qiName: directors
2+
qiSchema: public
3+
- public
4+
- - relCardinality:
5+
relColumns:
6+
- - id
7+
- director_id
8+
relCons: fk_director
9+
tag: O2M
10+
relFTableIsView: false
11+
relForeignTable:
12+
qiName: films
13+
qiSchema: public
14+
relIsSelf: false
15+
relTable:
16+
qiName: directors
17+
qiSchema: public
18+
relTableIsView: false
19+
tag: Relationship
20+
21+
- - - qiName: films
22+
qiSchema: public
23+
- public
24+
- - relCardinality:
25+
relColumns:
26+
- - director_id
27+
- id
28+
relCons: fk_director
29+
tag: M2O
30+
relFTableIsView: false
31+
relForeignTable:
32+
qiName: directors
33+
qiSchema: public
34+
relIsSelf: false
35+
relTable:
36+
qiName: films
37+
qiSchema: public
38+
relTableIsView: false
39+
tag: Relationship

test/io/__snapshots__/test_cli/test_schema_cache_snapshot[dbRoutines].yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@
106106
pdSchema: public
107107
pdVolatility: Volatile
108108

109+
- - qiName: notify_pgrst
110+
qiSchema: public
111+
- - pdDescription: null
112+
pdFuncSettings: []
113+
pdHasVariadic: false
114+
pdName: notify_pgrst
115+
pdParams: []
116+
pdReturnType:
117+
contents:
118+
contents:
119+
qiName: void
120+
qiSchema: pg_catalog
121+
tag: Scalar
122+
tag: Single
123+
pdSchema: public
124+
pdVolatility: Volatile
125+
109126
- - qiName: migrate_function
110127
qiSchema: public
111128
- - pdDescription: null

test/io/__snapshots__/test_cli/test_schema_cache_snapshot[dbTables].yaml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,37 @@
7171
tableSchema: public
7272
tableUpdatable: true
7373

74+
- - qiName: directors
75+
qiSchema: public
76+
- tableColumns:
77+
id:
78+
colDefault: null
79+
colDescription: null
80+
colEnum: []
81+
colMaxLen: null
82+
colName: id
83+
colNominalType: integer
84+
colNullable: false
85+
colType: integer
86+
name:
87+
colDefault: null
88+
colDescription: null
89+
colEnum: []
90+
colMaxLen: null
91+
colName: name
92+
colNominalType: text
93+
colNullable: true
94+
colType: text
95+
tableDeletable: true
96+
tableDescription: null
97+
tableInsertable: true
98+
tableIsView: false
99+
tableName: directors
100+
tablePKCols:
101+
- id
102+
tableSchema: public
103+
tableUpdatable: true
104+
74105
- - qiName: projects
75106
qiSchema: public
76107
- tableColumns: {}
@@ -95,6 +126,46 @@
95126
tableSchema: public
96127
tableUpdatable: false
97128

129+
- - qiName: films
130+
qiSchema: public
131+
- tableColumns:
132+
director_id:
133+
colDefault: null
134+
colDescription: null
135+
colEnum: []
136+
colMaxLen: null
137+
colName: director_id
138+
colNominalType: integer
139+
colNullable: true
140+
colType: integer
141+
id:
142+
colDefault: null
143+
colDescription: null
144+
colEnum: []
145+
colMaxLen: null
146+
colName: id
147+
colNominalType: integer
148+
colNullable: false
149+
colType: integer
150+
title:
151+
colDefault: null
152+
colDescription: null
153+
colEnum: []
154+
colMaxLen: null
155+
colName: title
156+
colNominalType: text
157+
colNullable: true
158+
colType: text
159+
tableDeletable: true
160+
tableDescription: null
161+
tableInsertable: true
162+
tableIsView: false
163+
tableName: films
164+
tablePKCols:
165+
- id
166+
tableSchema: public
167+
tableUpdatable: true
168+
98169
- - qiName: items
99170
qiSchema: public
100171
- tableColumns:

test/io/fixtures.sql

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,41 @@ select * from infinite_recursion;
260260
create or replace function "true"() returns boolean as $_$
261261
select true;
262262
$_$ language sql;
263+
264+
create or replace function notify_pgrst() returns void as $$
265+
notify pgrst;
266+
$$ language sql;
267+
268+
-- directors and films table can be used for resource embedding tests
269+
create table directors (
270+
id int primary key,
271+
name text
272+
);
273+
274+
create table films (
275+
id int primary key,
276+
title text,
277+
director_id int,
278+
279+
constraint fk_director
280+
foreign key (director_id) references directors (id)
281+
on update cascade
282+
on delete cascade
283+
);
284+
285+
-- data to test resource embedding
286+
truncate table directors cascade;
287+
insert into directors
288+
values (1, 'quentin tarantino'),
289+
(2, 'christopher nolan'),
290+
(3, 'yorgos lathinmos');
291+
292+
truncate table films cascade;
293+
insert into films
294+
values (1, 'pulp fiction', 1),
295+
(2, 'intersteller',2),
296+
(3, 'dogtooth',3),
297+
(4, 'reservoir dogs', 1);
298+
299+
300+
GRANT SELECT ON directors, films TO postgrest_test_anonymous, postgrest_test_w_superuser_settings;

test/io/test_big_schema.py

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,58 +7,6 @@
77
from postgrest import run
88

99

10-
def test_requests_with_resource_embedding_wait_for_schema_cache_reload(defaultenv):
11-
"requests that use the schema cache with resource embedding wait long for the schema cache to reload"
12-
13-
env = {
14-
**defaultenv,
15-
"PGRST_DB_SCHEMAS": "apflora",
16-
"PGRST_DB_POOL": "2",
17-
"PGRST_DB_ANON_ROLE": "postgrest_test_anonymous",
18-
"PGRST_INTERNAL_SCHEMA_CACHE_RELATIONSHIP_LOAD_SLEEP": "5100",
19-
}
20-
21-
with run(env=env, wait_max_seconds=30) as postgrest:
22-
# reload the schema cache
23-
response = postgrest.session.get("/rpc/notify_pgrst")
24-
assert response.status_code == 204
25-
26-
postgrest.wait_until_scache_starts_loading()
27-
28-
response = postgrest.session.get("/tpopmassn?select=*,tpop(*)")
29-
assert response.status_code == 200
30-
31-
assert response.elapsed.total_seconds() > 5
32-
33-
34-
def test_requests_without_resource_embedding_wait_for_schema_cache_reload(defaultenv):
35-
"requests that use the schema cache without resource embedding wait less for the schema cache to reload"
36-
37-
env = {
38-
**defaultenv,
39-
"PGRST_DB_SCHEMAS": "apflora",
40-
"PGRST_DB_POOL": "2",
41-
"PGRST_DB_ANON_ROLE": "postgrest_test_anonymous",
42-
"PGRST_INTERNAL_SCHEMA_CACHE_LOAD_SLEEP": "1100",
43-
"PGRST_INTERNAL_SCHEMA_CACHE_RELATIONSHIP_LOAD_SLEEP": "5000",
44-
}
45-
46-
with run(env=env, wait_max_seconds=30) as postgrest:
47-
# reload the schema cache
48-
response = postgrest.session.get("/rpc/notify_pgrst")
49-
assert response.status_code == 204
50-
51-
postgrest.wait_until_scache_starts_loading()
52-
53-
response = postgrest.session.get("/tpopmassn")
54-
assert response.status_code == 200
55-
56-
assert (
57-
response.elapsed.total_seconds() > 1
58-
and response.elapsed.total_seconds() < 5
59-
)
60-
61-
6210
def test_schema_cache_load_max_duration(defaultenv):
6311
"schema cache load should not surpass a max_duration of elapsed milliseconds"
6412

test/io/test_io.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,3 +2072,51 @@ def test_db_pre_config_with_pg_reserved_words(defaultenv):
20722072
in line
20732073
for line in output
20742074
)
2075+
2076+
2077+
def test_requests_with_resource_embedding_wait_for_schema_cache_reload(defaultenv):
2078+
"requests that use the schema cache with resource embedding wait long for the schema cache to reload"
2079+
2080+
env = {
2081+
**defaultenv,
2082+
"PGRST_DB_POOL": "2",
2083+
"PGRST_INTERNAL_SCHEMA_CACHE_RELATIONSHIP_LOAD_SLEEP": "5100",
2084+
}
2085+
2086+
with run(env=env, wait_max_seconds=30) as postgrest:
2087+
# reload the schema cache
2088+
response = postgrest.session.get("/rpc/notify_pgrst")
2089+
assert response.status_code == 204
2090+
2091+
postgrest.wait_until_scache_starts_loading()
2092+
2093+
response = postgrest.session.get("/directors?select=id,name,films(title)")
2094+
assert response.status_code == 200
2095+
2096+
assert response.elapsed.total_seconds() > 5
2097+
2098+
2099+
def test_requests_without_resource_embedding_wait_for_schema_cache_reload(defaultenv):
2100+
"requests that use the schema cache without resource embedding wait less for the schema cache to reload"
2101+
2102+
env = {
2103+
**defaultenv,
2104+
"PGRST_DB_POOL": "2",
2105+
"PGRST_INTERNAL_SCHEMA_CACHE_LOAD_SLEEP": "1100",
2106+
"PGRST_INTERNAL_SCHEMA_CACHE_RELATIONSHIP_LOAD_SLEEP": "5000",
2107+
}
2108+
2109+
with run(env=env, wait_max_seconds=30) as postgrest:
2110+
# reload the schema cache
2111+
response = postgrest.session.get("/rpc/notify_pgrst")
2112+
assert response.status_code == 204
2113+
2114+
postgrest.wait_until_scache_starts_loading()
2115+
2116+
response = postgrest.session.get("/films")
2117+
assert response.status_code == 200
2118+
2119+
assert (
2120+
response.elapsed.total_seconds() > 1
2121+
and response.elapsed.total_seconds() < 5
2122+
)

0 commit comments

Comments
 (0)