backend: confirm a registered update by itself after a delay when auto update is switched on [CI]
This commit is contained in:
1 parent
4e7a8c2ba3
commit
49e787a7a5
4 files changed
+138
No files matched your search
@@ -69,6 +69,33 @@ public sealed class BackendUpdateTests : IAsyncLifetime
|
||||
Assert.Equal(HttpStatusCode.Conflict, replay.StatusCode);
|
||||
}
|
||||
|
||||
/// <summary>自动更新默认关;打开之后只在新版本登记满设定的时间才确认,走的是和手动一样的路径(先备份)。</summary>
|
||||
[Fact]
|
||||
public async Task AutoUpdate_IsOffByDefault_AndConfirmsOnlyAfterTheOfferHasAged()
|
||||
{
|
||||
BackendOptions options = _backend.Services.GetRequiredService<BackendOptions>();
|
||||
var updater = _backend.Services.GetRequiredService<BackendAutoUpdater>();
|
||||
using HttpResponseMessage old = await PublishAsync(10); // seq 是发布时间(秒):1970 年,早就过了等待时间
|
||||
Assert.Equal(HttpStatusCode.Created, old.StatusCode);
|
||||
|
||||
Assert.False(await updater.RunOnceAsync(default)); // 默认关
|
||||
Assert.Equal(0, _backend.Restarts.Count);
|
||||
|
||||
options.AutoUpdate = true;
|
||||
options.AutoUpdateDelayMinutes = 10;
|
||||
using HttpResponseMessage fresh = await PublishAsync(TimeProvider.System.GetUtcNow().ToUnixTimeSeconds());
|
||||
Assert.Equal(HttpStatusCode.Created, fresh.StatusCode);
|
||||
Assert.False(await updater.RunOnceAsync(default)); // 刚登记的版本还要等
|
||||
Assert.Equal(0, _backend.Restarts.Count);
|
||||
|
||||
options.AutoUpdateDelayMinutes = 0;
|
||||
Assert.True(await updater.RunOnceAsync(default));
|
||||
Assert.Equal(1, _backend.Restarts.Count);
|
||||
Assert.Single(Directory.GetFiles(Path.Combine(_backend.DataDirectory, "backups"), "pre-update-*.db")); // 先备份
|
||||
Assert.False(await updater.RunOnceAsync(default)); // 已经在更新,不会再确认第二次
|
||||
Assert.Equal(1, _backend.Restarts.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Confirm_BacksUpTheDatabase_ThenExits_AndRejectsASupersededSequence()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user