Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal class EventDownSyncTask @Inject constructor(
.catch {
// Track a case when event stream is closed due to a parser error,
// but the exception is handled gracefully and channel is closed correctly.
errorType = it.toString()
errorType = it.javaClass.simpleName
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can add a test to prevent regression if someone updates this code (and same for the EventUpSyncTask)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ybourgery Makes sense, added.

}
.collect {
batchOfEventsToProcess.add(it)
Expand Down Expand Up @@ -105,7 +105,7 @@ internal class EventDownSyncTask @Inject constructor(
}

Simber.d(t)
errorType = t.toString()
errorType = t.javaClass.simpleName

lastOperation = processBatchedEvents(operation, batchOfEventsToProcess, lastOperation)
emitProgress(lastOperation, count, count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ internal class EventUpSyncTask @Inject constructor(
endedAt = timeHelper.now(),
requestId = requestId,
responseStatus = result?.status,
errorType = ex.toString(),
errorType = ex.javaClass.simpleName,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import java.util.UUID
import kotlin.coroutines.cancellation.CancellationException

class EventDownSyncTaskTest {

Expand Down Expand Up @@ -241,6 +242,48 @@ class EventDownSyncTaskTest {
coVerify { enrolmentRecordRepository.performActions(listOf(Deletion(event.payload.subjectId))) }
}

@Test
fun downSync_shouldAddEventWithExceptionClassSimpleNameIfDownloadFails() = runTest {
val expectedException = Exception("Test")
coEvery { eventRemoteDataSource.getEvents(any(), any(), any()) } throws expectedException

eventDownSyncTask.downSync(this, projectOp, eventScope).toList()

coVerify(exactly = 1) {
eventRepository.addOrUpdateEvent(
eventScope,
match {
it is EventDownSyncRequestEvent &&
it.payload.errorType == expectedException.javaClass.simpleName
}
)
}
}

@Test
fun downSync_shouldAddEventWithExceptionClassSimpleNameIfEventStreamFails() = runTest {
val expectedException = CancellationException("Test")
downloadEventsChannel = Channel(capacity = Channel.UNLIMITED)
coEvery { eventRemoteDataSource.getEvents(any(), any(), any()) } returns EventDownSyncResult(
0,
status = 200,
downloadEventsChannel
)
downloadEventsChannel.cancel(expectedException)

eventDownSyncTask.downSync(this, projectOp, eventScope).toList()

coVerify(exactly = 1) {
eventRepository.addOrUpdateEvent(
eventScope,
match {
it is EventDownSyncRequestEvent &&
it.payload.errorType == expectedException.javaClass.simpleName
}
)
}
}

@Test
fun moveSubjectFromModulesUnderSyncing_theOriginalModuleSyncShouldDoNothing() = runTest {
val eventToMoveToModule2 = ENROLMENT_RECORD_MOVE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,30 @@ internal class EventUpSyncTaskTest {
}
}

@Test
fun `upSync should add event with exception class simple name if upload fails`() = runTest {
setUpSyncKind(UpSynchronizationConfiguration.UpSynchronizationKind.ALL)

coEvery { eventRepo.getClosedEventScopes(any()) } returns emptyList()
coEvery { eventRepo.getClosedEventScopes(EventScopeType.SESSION) } returns listOf(
createSessionScope(GUID1),
)
coEvery {
eventRepo.getEventsFromScope(any())
} returns listOf(createEventWithSessionId(GUID1, GUID1))
val expectedException = NetworkConnectionException("Test", Throwable())
coEvery { eventRemoteDataSource.post(any(), any(), any()) } throws expectedException

eventUpSyncTask.upSync(operation, eventScope).toList()

coVerify(exactly = 1) {
eventRepo.addOrUpdateEvent(any(), match {
it is EventUpSyncRequestEvent &&
it.payload.errorType == expectedException.javaClass.simpleName
})
}
}

@Test
fun `upload should save request event for each upload request`() = runTest {
setUpSyncKind(UpSynchronizationConfiguration.UpSynchronizationKind.ALL)
Expand Down