def test_check_pending_upload_abandoned(app): """check_pending_upload deletes an abandoned pending upload when it's very old""" with app.app_context(): pu_row, file_row = add_pending_upload_and_file_row( len(DATA), DATA_DIGEST, datetime(1999, 1, 1), 'us-west-2') session = app.db.session('relengapi') grooming.check_pending_upload(session, pu_row) session.commit() eq_(tables.PendingUpload.query.all(), []) # PU is deleted
def test_check_pending_upload_bad_region(app): """check_pending_upload deletes a pending upload with a bad region""" with app.app_context(), set_time(): expires = time.now() - timedelta(seconds=90) pu_row, file_row = add_pending_upload_and_file_row( len(DATA), DATA_DIGEST, expires, 'us-west-1') session = app.db.session('relengapi') grooming.check_pending_upload(session, pu_row) session.commit() eq_(tables.PendingUpload.query.all(), []) # PU is deleted
def test_check_pending_upload_not_expired(app): """check_pending_upload doesn't check anything if the URL isn't expired yet""" with app.app_context(), set_time(): expires = time.now() + timedelta(seconds=10) # 10s shy pu_row, file_row = add_pending_upload_and_file_row( len(DATA), DATA_DIGEST, expires, 'us-west-2') session = app.db.session('relengapi') grooming.check_pending_upload(session, pu_row) session.commit() eq_(len(tables.PendingUpload.query.all()), 1) # PU still exists
def test_check_pending_upload_no_upload(app): """check_pending_upload leaves the PU in place if the upload is not complete""" with app.app_context(), set_time(): expires = time.now() - timedelta(seconds=90) pu_row, file_row = add_pending_upload_and_file_row( len(DATA), DATA_DIGEST, expires, 'us-west-2') session = app.db.session('relengapi') grooming.check_pending_upload(session, pu_row) session.commit() # PU has not been deleted assert tables.PendingUpload.query.first().file.sha512 == DATA_DIGEST
def test_check_pending_upload_success(app): """check_pending_upload deletes the PU and adds a FileInstance if valid""" with app.app_context(), set_time(): expires = time.now() - timedelta(seconds=90) pu_row, file_row = add_pending_upload_and_file_row( len(DATA), DATA_DIGEST, expires, 'us-west-2') make_key(app, 'us-west-2', 'tt-usw2', DATA_KEY, DATA) session = app.db.session('relengapi') grooming.check_pending_upload(session, pu_row) session.commit() eq_(tables.PendingUpload.query.all(), []) # PU is deleted eq_(len(tables.File.query.first().instances), 1) # FileInstance exists assert key_exists(app, 'us-west-2', 'tt-usw2', DATA_KEY)
def test_check_pending_upload_not_valid(app): """check_pending_upload deletes the PU and the key if the upload is invalid.""" with app.app_context(), set_time(): expires = time.now() - timedelta(seconds=90) pu_row, file_row = add_pending_upload_and_file_row( len(DATA), DATA_DIGEST, expires, 'us-west-2') make_key(app, 'us-west-2', 'tt-usw2', DATA_KEY, 'xxx') session = app.db.session('relengapi') grooming.check_pending_upload(session, pu_row) session.commit() eq_(tables.PendingUpload.query.all(), []) # PU is deleted assert not key_exists(app, 'us-west-2', 'tt-usw2', DATA_KEY)
def test_check_pending_upload_race(app): """If check_pending_upload fails to add a file instance because it already exists, as might happen when the function races with itself, the function still succeeds.""" with app.app_context(), set_time(): expires = time.now() - timedelta(seconds=90) pu_row, file_row = add_pending_upload_and_file_row( len(DATA), DATA_DIGEST, expires, 'us-west-2') make_key(app, 'us-west-2', 'tt-usw2', DATA_KEY, DATA) session = app.db.session('relengapi') def test_shim(): session.add(tables.FileInstance(file=file_row, region='us-west-2')) session.commit() grooming.check_pending_upload(session, pu_row, _test_shim=test_shim) session.commit() eq_(tables.PendingUpload.query.all(), []) # PU is deleted eq_(len(tables.File.query.first().instances), 1) # FileInstance exists assert key_exists(app, 'us-west-2', 'tt-usw2', DATA_KEY)