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

test_homepage intermittent failure #2092

Closed
simonw opened this issue Jun 29, 2023 · 2 comments
Closed

test_homepage intermittent failure #2092

simonw opened this issue Jun 29, 2023 · 2 comments
Labels

Comments

@simonw
Copy link
Owner

simonw commented Jun 29, 2023

e.g. in https://github.com/simonw/datasette/actions/runs/5413590227/jobs/9839373852

=================================== FAILURES ===================================
________________________________ test_homepage _________________________________
[gw0] linux -- Python 3.7.17 /opt/hostedtoolcache/Python/3.7.17/x64/bin/python

ds_client = <datasette.app.DatasetteClient object at 0x7f85d271ef50>

    @pytest.mark.asyncio
    async def test_homepage(ds_client):
        response = await ds_client.get("/.json")
        assert response.status_code == 200
        assert "application/json; charset=utf-8" == response.headers["content-type"]
        data = response.json()
        assert data.keys() == {"fixtures": 0}.keys()
        d = data["fixtures"]
        assert d["name"] == "fixtures"
        assert d["tables_count"] == 24
        assert len(d["tables_and_views_truncated"]) == 5
        assert d["tables_and_views_more"] is True
        # 4 hidden FTS tables + no_primary_key (hidden in metadata)
        assert d["hidden_tables_count"] == 6
        # 201 in no_primary_key, plus 6 in other hidden tables:
>       assert d["hidden_table_rows_sum"] == 207, data
E       AssertionError: {'fixtures': {'color': '9403e5', 'hash': None, 'hidden_table_rows_sum': 0, 'hidden_tables_count': 6, ...}}
E       assert 0 == 207

My guess is that this is a timing error, where very occasionally the "count rows but stop counting if it exceeds a time limit" thing fails.

@simonw
Copy link
Owner Author

simonw commented Jun 29, 2023

I'm going to remove this assertion entirely. The homepage JSON needs a refactor anyway.

@simonw
Copy link
Owner Author

simonw commented Jun 29, 2023

Felt lazy:

symbex test_homepage -f tests/test_api.py | \
  llm -m 4 --system 'Change all of the == some integer tests in this code to isinstance(thing, int) instead'

Output:

# File: tests/test_api.py Line: 26
@pytest.mark.asyncio
async def test_homepage(ds_client):
    response = await ds_client.get("/.json")
    assert response.status_code == 200
    assert "application/json; charset=utf-8" == response.headers["content-type"]
    data = response.json()
    assert isinstance(data.keys(), int)
    d = data["fixtures"]
    assert d["name"] == "fixtures"
    assert isinstance(d["tables_count"], int)
    assert isinstance(len(d["tables_and_views_truncated"]), int)
    assert d["tables_and_views_more"] is True
    # 4 hidden FTS tables + no_primary_key (hidden in metadata)
    assert isinstance(d["hidden_tables_count"], int)
    # 201 in no_primary_key, plus 6 in other hidden tables:
    assert isinstance(d["hidden_table_rows_sum"], int), data
    assert isinstance(d["views_count"], int)

I'll use most of that and delete the obsoleted comments.

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