Skip to content

Commit

Permalink
Squirrel#1669 Improve progress reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
GeertvanHorrik committed Oct 13, 2020
1 parent eef3746 commit b5c8d0e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Update/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,14 @@ public async Task Update(string updateUrl, string appName = null)

retry:
try {
var updateInfo = await mgr.CheckForUpdate(intention: UpdaterIntention.Update, ignoreDeltaUpdates: ignoreDeltaUpdates, progress: x => Console.WriteLine(x / 3));
await mgr.DownloadReleases(updateInfo.ReleasesToApply, x => Console.WriteLine(33 + x / 3));
await mgr.ApplyReleases(updateInfo, x => Console.WriteLine(66 + x / 3));
// 3 % (3 stages)
var updateInfo = await mgr.CheckForUpdate(intention: UpdaterIntention.Update, ignoreDeltaUpdates: ignoreDeltaUpdates, progress: x => Console.WriteLine(UpdateManager.CalculateProgress(x, 0, 3)));

// 3 - 30 %
await mgr.DownloadReleases(updateInfo.ReleasesToApply, x => Console.WriteLine(UpdateManager.CalculateProgress(x, 3, 30)));

// 30 - 100 %
await mgr.ApplyReleases(updateInfo, x => Console.WriteLine(UpdateManager.CalculateProgress(x, 30, 100)));
} catch (Exception ex) {
if (ignoreDeltaUpdates) {
this.Log().ErrorException("Really couldn't apply updates!", ex);
Expand Down
38 changes: 38 additions & 0 deletions test/UpdateManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,44 @@ public void CalculatesPercentageCorrectly(int percentageOfCurrentStep, int stepS

Assert.Equal(expectedPercentage, percentage);
}

[Fact]
public void CalculatesPercentageCorrectlyForUpdateExe()
{
// Note: this mimicks the update.exe progress reporting of multiple steps

var progress = new List<int>();

// 3 % (3 stages), check for updates
foreach (var step in new [] { 0, 33, 66, 100 })
{
progress.Add(UpdateManager.CalculateProgress(step, 0, 3));

Assert.InRange(progress.Last(), 0, 3);
}

Assert.Equal(3, progress.Last());

// 3 - 30 %, download releases
for (var step = 0; step <= 100; step++)
{
progress.Add(UpdateManager.CalculateProgress(step, 3, 30));

Assert.InRange(progress.Last(), 3, 30);
}

Assert.Equal(30, progress.Last());

// 30 - 100 %, apply releases
for (var step = 0; step <= 100; step++)
{
progress.Add(UpdateManager.CalculateProgress(step, 30, 100));

Assert.InRange(progress.Last(), 30, 100);
}

Assert.Equal(100, progress.Last());
}
}
}
}

0 comments on commit b5c8d0e

Please sign in to comment.