FrameworkBenchmarks
FrameworkBenchmarks copied to clipboard
Fix Python Update Tests
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:
- Querying the database for a random ID
- Mapping the result of that query to an object
- Changing the
randomNumberfield to a new random number - Updating the database with the new value