mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
fix(updater): honor launcher recovery locks during initialization
This commit is contained in:
1 parent
6bbc292056
commit
462bab57d2
2 files changed
+25
-1
No files matched your search
@@ -618,6 +618,30 @@ test("initialization keeps a live task but reconciles it once its process is gon
|
||||
assert.equal(restarted.getStatus().task?.errorCode, "UPDATE_INTERRUPTED");
|
||||
});
|
||||
|
||||
test("initialization preserves an interrupted tree while a launcher recovery owns the lock", t => {
|
||||
const fixture = createService(t, [], new Map());
|
||||
const taskId = "upd_launcher_recovery";
|
||||
const updates = path.join(fixture.dataDir, "updates");
|
||||
const staged = path.join(updates, "tasks", taskId, "staged");
|
||||
createPackageFiles(staged, "0.4.0");
|
||||
const backup = path.join(updates, "backups", taskId);
|
||||
swapCode(fixture.rootDir, staged, backup);
|
||||
writeUpdateState(path.join(updates, "state.json"), { schemaVersion: 1, task: {
|
||||
id: taskId, status: "restarting", fromVersion: "0.3.2", targetVersion: "0.4.0",
|
||||
startedAt: "2026-01-01T00:00:00.000Z", updatedAt: "2026-01-01T00:00:00.000Z", finishedAt: null,
|
||||
errorCode: null, errorMessage: null, rolledBack: false, steps: [],
|
||||
} });
|
||||
const lockPath = path.join(updates, "update.lock");
|
||||
const release = acquireUpdateLock(lockPath, "recovery_other_launcher");
|
||||
t.after(release);
|
||||
const owner = readFileSync(lockPath, "utf8");
|
||||
fixture.service.initialize();
|
||||
assert.equal(readFileSync(lockPath, "utf8"), owner);
|
||||
assert.equal(fixture.service.getStatus().task?.status, "restarting");
|
||||
assert.equal(JSON.parse(readFileSync(path.join(fixture.rootDir, "package.json"), "utf8")).version, "0.4.0");
|
||||
assert.equal(JSON.parse(readFileSync(path.join(backup, "package.json"), "utf8")).version, "0.3.2");
|
||||
});
|
||||
|
||||
test("a replacement app can update again after the runner finishes its cached task", async t => {
|
||||
const fixture = createService(t, [], new Map());
|
||||
const statePath = path.join(fixture.dataDir, "updates", "state.json");
|
||||
|
||||
@@ -162,7 +162,7 @@ export class UpdateService {
|
||||
const task = this.state.task;
|
||||
// A live lock owner (for example a second process starting by mistake)
|
||||
// must not have its in-flight task reconciled as interrupted.
|
||||
if (!task || !isActiveTaskStatus(task.status) || !updateLockIsHeld(this.lockPath, task.id)) {
|
||||
if (!task || !isActiveTaskStatus(task.status) || !updateLockIsHeld(this.lockPath)) {
|
||||
const recovered = task && isActiveTaskStatus(task.status) ? this.recoverInterruptedSwap(task) : null;
|
||||
const changed = recovered !== null || reconcileInterruptedState(this.state, this.options.currentVersion, this.now().toISOString());
|
||||
if (changed) writeUpdateState(this.statePath, this.state);
|
||||
|
||||
Reference in new issue
Block a user