Fix session runtime reset
This commit is contained in:
parent
f447c0f37a
commit
4374119f9e
@ -1822,13 +1822,15 @@ export class DownloadManager extends EventEmitter {
|
||||
}
|
||||
|
||||
public resetSessionStats(): void {
|
||||
const now = nowMs();
|
||||
this.session.totalDownloadedBytes = 0;
|
||||
this.sessionDownloadedBytes = 0;
|
||||
this.sessionCompletedFiles = 0;
|
||||
this.session.runStartedAt = this.session.running ? nowMs() : 0;
|
||||
this.session.runStartedAt = this.session.running ? now : 0;
|
||||
this.appSessionStartedAt = now;
|
||||
this.session.summaryText = "";
|
||||
this.lastGlobalProgressBytes = 0;
|
||||
this.lastGlobalProgressAt = nowMs();
|
||||
this.lastGlobalProgressAt = now;
|
||||
this.speedEvents = [];
|
||||
this.speedEventsHead = 0;
|
||||
this.speedBytesLastWindow = 0;
|
||||
|
||||
@ -6978,6 +6978,35 @@ describe("download manager", () => {
|
||||
expect(savedSettings.totalRuntimeAllTimeMs || 0).toBeGreaterThanOrEqual(2 * 60 * 60 * 1000 + 100);
|
||||
}, 10000);
|
||||
|
||||
it("resets session runtime without affecting all-time runtime", async () => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-dm-"));
|
||||
tempDirs.push(root);
|
||||
|
||||
const manager = new DownloadManager(
|
||||
{
|
||||
...defaultSettings(),
|
||||
token: "rd-token",
|
||||
outputDir: path.join(root, "downloads"),
|
||||
extractDir: path.join(root, "extract"),
|
||||
totalRuntimeAllTimeMs: 90 * 60 * 1000
|
||||
},
|
||||
emptySession(),
|
||||
createStoragePaths(path.join(root, "state"))
|
||||
);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 120));
|
||||
|
||||
const beforeReset = manager.getStats();
|
||||
expect(beforeReset.sessionRuntimeMs).toBeGreaterThanOrEqual(100);
|
||||
|
||||
manager.resetSessionStats();
|
||||
|
||||
const afterReset = manager.getStats();
|
||||
expect(afterReset.sessionRuntimeMs).toBeLessThan(beforeReset.sessionRuntimeMs);
|
||||
expect(afterReset.sessionRuntimeMs).toBeLessThan(100);
|
||||
expect(afterReset.totalRuntimeMs).toBeGreaterThanOrEqual(90 * 60 * 1000);
|
||||
}, 10000);
|
||||
|
||||
it("writes auto-rename details into rename and item logs", async () => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-dm-"));
|
||||
tempDirs.push(root);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user