| 165 | successful = 0 |
| 166 | |
| 167 | async def process_request(connection, request): |
| 168 | nonlocal iterations |
| 169 | iterations += 1 |
| 170 | # Retriable errors |
| 171 | if iterations == 1: |
| 172 | await asyncio.sleep(3 * MS) |
| 173 | elif iterations == 2: |
| 174 | connection.transport.close() |
| 175 | elif iterations == 3: |
| 176 | return connection.respond(http.HTTPStatus.SERVICE_UNAVAILABLE, "🚒") |
| 177 | # Fatal error |
| 178 | elif iterations == 6: |
| 179 | return connection.respond(http.HTTPStatus.PAYMENT_REQUIRED, "💸") |
| 180 | |
| 181 | async with serve(*args, process_request=process_request) as server: |
| 182 | with self.assertRaises(InvalidStatus) as raised: |