Skip to content
This repository has been archived by the owner on Oct 22, 2023. It is now read-only.

Commit

Permalink
Add workaround for issue reported in #1527.
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskorn committed May 19, 2023
1 parent 5b12d27 commit 18d7a7e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ class ImageBuildProgressAggregator {
return calculateCurrentProgress()
}

private fun processStepDownloadProgressUpdate(progressUpdate: StepDownloadProgressUpdate): AggregatedImageBuildProgress {
val previousValue = activeSteps.getValue(progressUpdate.stepNumber)
private fun processStepDownloadProgressUpdate(progressUpdate: StepDownloadProgressUpdate): AggregatedImageBuildProgress? {
val previousValue = activeSteps[progressUpdate.stepNumber] ?: return null
val totalBytes = if (progressUpdate.totalBytes <= 0) null else progressUpdate.totalBytes
val updatedValue = previousValue.copy(detail = StepDetail.Downloading(progressUpdate.bytesDownloaded, totalBytes))
activeSteps[progressUpdate.stepNumber] = updatedValue

return calculateCurrentProgress()
}

private fun processStepPullProgressUpdate(progressUpdate: StepPullProgressUpdate): AggregatedImageBuildProgress {
val previousValue = activeSteps.getValue(progressUpdate.stepNumber)
private fun processStepPullProgressUpdate(progressUpdate: StepPullProgressUpdate): AggregatedImageBuildProgress? {
val previousValue = activeSteps[progressUpdate.stepNumber] ?: return null
val aggregator = if (previousValue.detail is StepDetail.PullingImage) previousValue.detail.aggregator else ImagePullProgressAggregator()
val updatedAggregation = aggregator.processProgressUpdate(progressUpdate.pullProgress)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,5 +289,30 @@ object ImageBuildProgressAggregatorSpec : Spek({
)
}
}

// This case covers the issue reported in https://github.com/batect/batect/issues/1527
on("a step reporting image pull progress before reporting that it has started") {
val aggregator by createForEachTest { ImageBuildProgressAggregator() }

val nextUpdate by runNullableForEachTest {
aggregator.processProgressUpdate(StepPullProgressUpdate(1, ImagePullProgressUpdate("Downloading", ImagePullProgressDetail(123, 456), "abc123")))
}

it("does not emit a new update") {
assertThat(nextUpdate, absent())
}
}

on("a step reporting download progress before reporting that it has started") {
val aggregator by createForEachTest { ImageBuildProgressAggregator() }

val nextUpdate by runNullableForEachTest {
aggregator.processProgressUpdate(StepDownloadProgressUpdate(1, 5, 100))
}

it("does not emit a new update") {
assertThat(nextUpdate, absent())
}
}
}
})

0 comments on commit 18d7a7e

Please sign in to comment.