-
Notifications
You must be signed in to change notification settings - Fork 140
RUMM-1439 discard batches on invalid Client Token #535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RUMM-1439 discard batches on invalid Client Token #535
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you will need an unit test for this also ?
@mariusc83 unfortunately there's no UT already on this mechanism. I'll try and see if I can set it up but it looks that a refactor might be needed to make that class testable :/ |
Let's add tests for that as this was a reason why we let this bug enter 🙂. Although it can't be tested directly (it's a private API), we can add two behaviour tests, each observing if the data was deleted / preserved:
We can mock func testGivenDataToUpload_whenUploadFinishesWithAcceptableStatusCode_thenDataIsDeleted() {
func test(statusCode: Int) {
let server = ServerMock(delivery: .success(response: .mockResponseWith(statusCode: statusCode)))
let dataUploader = DataUploader(
urlProvider: .mockAny(),
httpClient: HTTPClient(session: server.getInterceptedURLSession()),
httpHeaders: .mockAny()
)
// Given
writer.write(value: ["key": "value"])
XCTAssertEqual(try temporaryDirectory.files().count, 1)
// When
let worker = DataUploadWorker(
queue: uploaderQueue,
fileReader: reader,
dataUploader: dataUploader,
uploadConditions: DataUploadConditions.alwaysUpload(),
delay: DataUploadDelay(performance: UploadPerformanceMock.veryQuick),
featureName: .mockAny()
)
_ = server.waitAndReturnRequests(count: 1)
// Then
worker.cancelSynchronously()
XCTAssertEqual(try temporaryDirectory.files().count, 0, "When status code \(statusCode) is received, data should be deleted")
}
test(statusCode: (200...299).randomElement()!)
test(statusCode: (300...399).randomElement()!)
test(statusCode: (400...499).randomElement()!)
test(statusCode: 403)
}
func testGivenDataToUpload_whenUploadFinishesWithServerErrorStatusCode_thenDataIsPreserved() {
let statusCode = (500...599).randomElement()!
let server = ServerMock(delivery: .success(response: .mockResponseWith(statusCode: statusCode)))
let dataUploader = DataUploader(
urlProvider: .mockAny(),
httpClient: HTTPClient(session: server.getInterceptedURLSession()),
httpHeaders: .mockAny()
)
// Given
writer.write(value: ["key": "value"])
XCTAssertEqual(try temporaryDirectory.files().count, 1)
// When
let worker = DataUploadWorker(
queue: uploaderQueue,
fileReader: reader,
dataUploader: dataUploader,
uploadConditions: DataUploadConditions.alwaysUpload(),
delay: DataUploadDelay(performance: UploadPerformanceMock.veryQuick),
featureName: .mockAny()
)
_ = server.waitAndReturnRequests(count: 1)
// Then
worker.cancelSynchronously()
XCTAssertEqual(try temporaryDirectory.files().count, 1, "When status code \(statusCode) is received, data should be preserved")
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs tests #535 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG 🚀
What and why?
When an application is configured with an invalid Client Token, discard the batch to avoid retrying endlessly with the same invalid token.