mirror of
https://github.com/zotero/zotero.git
synced 2026-09-30 01:51:36 +00:00
Merge 7b34f22ddf into cc951f9916
This commit is contained in:
commit
6e742fa5c6
3 changed files with 39 additions and 4 deletions
|
|
@ -49,9 +49,9 @@ Zotero.Server.Connector.SessionManager = {
|
|||
var ttl = this._sessions.size >= 10 ? 60 : 600;
|
||||
var deleteBefore = new Date() - ttl * 1000;
|
||||
|
||||
for (let session of this._sessions) {
|
||||
for (let [id, session] of this._sessions) {
|
||||
if (session.created < deleteBefore) {
|
||||
this._session.delete(session.id);
|
||||
this._sessions.delete(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -147,7 +147,7 @@ Zotero.Server.Connector.SaveSession = class {
|
|||
}
|
||||
|
||||
remove() {
|
||||
delete Zotero.Server.Connector.SessionManager._sessions[this.id];
|
||||
Zotero.Server.Connector.SessionManager._sessions.delete(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -513,7 +513,7 @@ Zotero.Server.RequestHandler.prototype._processEndpoint = async function (method
|
|||
}
|
||||
} catch(e) {
|
||||
Zotero.debug(e);
|
||||
this._requestFinished(this._generateResponse(500), "text/plain", "An error occurred\n");
|
||||
this._requestFinished(this._generateResponse(500, "text/plain", "An error occurred\n"));
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -93,6 +93,41 @@ describe("Connector Server", function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe("SaveSession.SessionManager", function () {
|
||||
var SessionManager = Zotero.Server.Connector.SessionManager;
|
||||
|
||||
it("should expire sessions older than the TTL when gc() runs", function () {
|
||||
var id = "gcOld_" + Zotero.Utilities.randomString();
|
||||
var session = SessionManager.create(id, 'saveItems', {});
|
||||
// Backdate creation beyond the 10-minute TTL
|
||||
session.created = new Date(Date.now() - 11 * 60 * 1000);
|
||||
|
||||
SessionManager.gc();
|
||||
|
||||
assert.isUndefined(SessionManager.get(id), "stale session should be removed by gc()");
|
||||
});
|
||||
|
||||
it("should keep sessions newer than the TTL when gc() runs", function () {
|
||||
var id = "gcNew_" + Zotero.Utilities.randomString();
|
||||
var session = SessionManager.create(id, 'saveItems', {});
|
||||
|
||||
SessionManager.gc();
|
||||
|
||||
assert.strictEqual(SessionManager.get(id), session, "fresh session should survive gc()");
|
||||
session.remove();
|
||||
});
|
||||
|
||||
it("should remove a session via SaveSession#remove()", function () {
|
||||
var id = "remove_" + Zotero.Utilities.randomString();
|
||||
var session = SessionManager.create(id, 'saveItems', {});
|
||||
assert.strictEqual(SessionManager.get(id), session);
|
||||
|
||||
session.remove();
|
||||
|
||||
assert.isUndefined(SessionManager.get(id), "remove() should delete the session from the manager");
|
||||
});
|
||||
});
|
||||
|
||||
describe('/connector/getTranslatorCode', function () {
|
||||
it('should respond with translator code', async function () {
|
||||
var code = 'function detectWeb() {}\nfunction doImport() {}';
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue