Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intermittent test_delete_row test failure #1919

Open
simonw opened this issue Nov 30, 2022 · 1 comment
Open

Intermittent test_delete_row test failure #1919

simonw opened this issue Nov 30, 2022 · 1 comment
Labels

Comments

@simonw
Copy link
Owner

simonw commented Nov 30, 2022

https://github.com/simonw/datasette/actions/runs/3580503393/jobs/6022689591

        delete_response = await ds_write.client.post(
            "/data/{}/{}/-/delete".format(table, delete_path),
            headers={
                "Authorization": "***".format(write_token(ds_write)),
            },
        )
>       assert delete_response.status_code == 200
E       assert 404 == 200
E        +  where 404 = <Response [404 Not Found]>.status_code

/home/runner/work/datasette/datasette/tests/test_api_write.py:396: AssertionError
=========================== short test summary info ============================
FAILED tests/test_api_write.py::test_delete_row[compound_pk_table-row_for_create2-pks2-article,k] - assert 404 == 200
 +  where 404 = <Response [404 Not Found]>.status_code

This passes most of the time, but very occasionally fails - in this case in Python 3.7

It seems to only fail for the article,k compound primary key test.

@simonw
Copy link
Owner Author

simonw commented Nov 30, 2022

This is the test:

@pytest.mark.asyncio
@pytest.mark.parametrize(
"table,row_for_create,pks,delete_path",
(
("rowid_table", {"name": "rowid row"}, None, None),
("pk_table", {"id": 1, "name": "ID table"}, "id", "1"),
(
"compound_pk_table",
{"type": "article", "key": "k"},
["type", "key"],
"article,k",
),
),
)
async def test_delete_row(ds_write, table, row_for_create, pks, delete_path):
# First create the table with that example row
create_data = {
"table": table,
"row": row_for_create,
}
if pks:
if isinstance(pks, str):
create_data["pk"] = pks
else:
create_data["pks"] = pks
create_response = await ds_write.client.post(
"/data/-/create",
json=create_data,
headers={
"Authorization": "Bearer {}".format(write_token(ds_write)),
},
)
assert create_response.status_code == 201, create_response.json()
# Should be a single row
assert (
await ds_write.client.get(
"/data.json?_shape=arrayfirst&sql=select+count(*)+from+{}".format(table)
)
).json() == [1]
# Now delete the row
if delete_path is None:
# Special case for that rowid table
delete_path = (
await ds_write.client.get(
"/data.json?_shape=arrayfirst&sql=select+rowid+from+{}".format(table)
)
).json()[0]
delete_response = await ds_write.client.post(
"/data/{}/{}/-/delete".format(table, delete_path),
headers={
"Authorization": "Bearer {}".format(write_token(ds_write)),
},
)
assert delete_response.status_code == 200
assert (
await ds_write.client.get(
"/data.json?_shape=arrayfirst&sql=select+count(*)+from+{}".format(table)
)
).json() == [0]

I'm suspicious that there's a timing error of some sort but I can't think what it might be.

@simonw simonw changed the title Intermittent test failure Intermittent test_delete_row test failure Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant