mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 14:31:57 -05:00
make test dvla response file timestamps in a random order
since there'll be a bunch of threads running functional test tasks at the same time, there's no point always trying to start from the same second and then stepping back to the same one-second-back file each time. Also, this leads us to an increased risk of race conditions. This change takes the same thirty second range, but shuffles it. The tests, since they're no longer deterministic, now use a new Matcher object (w/ credit to alexey) to match any filename from within that thirty second range
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import random
|
||||
from datetime import datetime, timedelta
|
||||
import json
|
||||
|
||||
@@ -125,8 +126,8 @@ def create_fake_letter_response_file(self, reference):
|
||||
now = datetime.utcnow()
|
||||
dvla_response_data = '{}|Sent|0|Sorted'.format(reference)
|
||||
|
||||
# try and find a filename that hasn't been taken yet - going back in time 60 seconds
|
||||
for i in range(30):
|
||||
# try and find a filename that hasn't been taken yet - from a random time within the last 30 seconds
|
||||
for i in sorted(range(30), key=lambda _: random.random()):
|
||||
upload_file_name = 'NOTIFY-{}-RSP.TXT'.format((now - timedelta(seconds=i)).strftime('%Y%m%d%H%M%S'))
|
||||
if not file_exists(current_app.config['DVLA_RESPONSE_BUCKET_NAME'], upload_file_name):
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user