Skip to content

test: new tables that don't use the scache are not immediately available - #5121

Closed
steve-chavez wants to merge 2 commits into
PostgREST:mainfrom
steve-chavez:4613
Closed

test: new tables that don't use the scache are not immediately available#5121
steve-chavez wants to merge 2 commits into
PostgREST:mainfrom
steve-chavez:4613

Conversation

@steve-chavez

Copy link
Copy Markdown
Member

Proves the problem in #4613.

Comment on lines +126 to +149
def test_new_table_is_immediately_available(defaultenv):
"new table that don't use the schema cache should be immediately available"

psql_as_superuser("CALL bigdata.create_tables(5000);")

env = {
**defaultenv,
"PGRST_DB_SCHEMAS": "bigdata",
"PGRST_DB_POOL": "2",
"PGRST_DB_ANON_ROLE": "postgrest_test_anonymous",
}

with run(env=env, wait_max_seconds=30) as postgrest:
response = postgrest.session.get("/data_1?col=eq.1")
assert response.status_code == 200

response = postgrest.session.post("/rpc/create_random_table")
assert response.status_code == 200
table_name = response.json()

response = postgrest.session.get(f"/{table_name}?col=eq.1")
if response.status_code == 404:
pytest.xfail("new table returns 404 ")
assert response.status_code == 200

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main idea here is:

  • Create a good amount of tables at the beginning, so the scache load is slow
  • Create a random table (including notify pgrst) and obtain the name.
  • Request the new table and watch it take some time to stop replying with 404.

I manually tested this with 120K tables (mentioned on #4462, same case as #4613) and was able to see the request failing with 404 for a good time. But for test speed 5000 was enough.

Also I load this bunch of tables on a procedure at the beginning to avoid slowing down the other tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main idea here is:

  • Create a good amount of tables at the beginning, so the scache load is slow
  • Create a random table (including notify pgrst) and obtain the name.
  • Request the new table and watch it take some time to stop replying with 404.

I did not look at the code at all, but this reads an awful lot like a test that will be heavily timing dependent... which I am really not looking forward to.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I wasn't clear but no, there's no timing (no sleep call) in the test right now and won't expect it to be after the fix.

If #5120 is merged this is expected to pass as it is (without xfail).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no timing (no sleep call) in the test

"timing dependent" does not mean "it has a sleep call". It means that whether the test passes or fails depends on how fast the machine running the test operates.

Run this test on a machine that does not make "the scache load [...] slow" and you might not have the desired test result. That's the problematic timing dependence.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test does accurately capture what #4613 is about.

To not make it timing dependent I guess we need to capture if a simple request like /table?id=eq.1 doesn't use the schema cache. For that we'd need some schema cache metric like schema_cache_use but it doesn't seem generally useful or worth it.

Any other ideas?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we just need to:

  • load the schema cache
  • create a new table dynamically, without reloading the schema cache
  • make a request

That should already show the "problem", right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • load the schema cache
  • create a new table dynamically, without reloading the schema cache
  • make a request

Yeah, this should be it. I am also confused on why we are creating a lot of tables.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, I can add a simpler test.

Although this simple test doesn't prove a subproblem of #4613, that is that with a big number of tables the scache load takes a good amount of time leading to that 404. If the number of tables was small this problem wouldn't be noticeable.

I added some setup code here to prove that and I think that's valuable but I can't see an immediate need for it.

So I'll just open a new PR and leave this one as is in case this setup can be reused later.

@steve-chavez

steve-chavez commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

CI is failing with some weird error:

Unexpected response 404 for http://objects-us-east-1.dream.io/hackage-mirror/root.json

Looks like hackage is down

@steve-chavez

Copy link
Copy Markdown
Member Author

Hackage is up again so all the tests pass now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants