FrameworkBenchmarks icon indicating copy to clipboard operation
FrameworkBenchmarks copied to clipboard

Fix Python Update Tests

Open NateBrady23 opened this issue 6 years ago • 0 comments

As noted in #5079 some of the Python tests are going about the Updates test implementation incorrectly.

async def database_updates(
    req: MultipleDatabaseRequest
) -> MultipleDatabaseResponse:
    num_queries = get_num_queries(req.query['queries'])
    updates = [(randint(1, 10000), randint(1, 10000)) for _ in range(num_queries)]
    worlds = [{'id': row_id, 'randomNumber': number} for row_id, number in updates]

    async with connection_pool.acquire() as connection:
        statement = await connection.prepare(READ_ROW_SQL)
        for row_id, number in updates:
            await statement.fetchval(row_id)
        await connection.executemany(WRITE_ROW_SQL, updates)

    return MultipleDatabaseResponse(
        status_code=HTTPStatus.OK,
        body=worlds
    )

In the code above, the updates array of objects is created with random ids and numbers. The database is queried for all those ids (results never read), and then an update is made based on the original array of objects. This is out of order, and the result of the queries is never used. In fact, statement.fetchval(row_id) could not do anything, and this test would still pass.

To remedy this, python updates tests should be:

  1. Querying the database for a random ID
  2. Mapping the result of that query to an object
  3. Changing the randomNumber field to a new random number
  4. Updating the database with the new value

NateBrady23 avatar Sep 24 '19 17:09 NateBrady23