Harden traffic history worker lifecycle and query performance
Build and Deploy Gateway / build-and-push (push) Successful in 37s
Build and Deploy Gateway / deploy (push) Successful in 19s

This commit is contained in:
2026-09-19 09:58:54 +03:00
parent 74c5b66482
commit 4c58384056
14 changed files with 509 additions and 89 deletions
+32
View File
@@ -297,3 +297,35 @@ test('high-churn sample measures closed-lifecycle storage and epoch reclamation'
db.close();
t.diagnostic(JSON.stringify({ closedLifecycles: 100_000, writeMs, queryMs, bytes, reusableBytes }));
});
test('history searches each destination once, and cached periods stay exact after late data and rollback', (t) => {
const f = fixture(t); let clock = base;
let searched = 0;
const registerFunction = DatabaseSync.prototype.function;
t.mock.method(DatabaseSync.prototype, 'function', function (name, options, callback) {
return registerFunction.call(this, name, options, name === 'lower_unicode'
? (value) => { searched++; return callback(value); } : callback);
});
const store = f.register(openTrafficHistoryStore(f.file, () => clock));
store.ingest([batch(clock, [], true)], 'live');
for (let minute = 0; minute < 60; minute++) {
clock = base + minute * 60_000 + 1_000;
store.ingest([batch(clock, [connection('a', (minute + 1) * 10, (minute + 1) * 20)])], 'live');
}
clock = base + 60 * 60_000;
const searchedQuery = query({ search: 'яндекс' });
assert.deepEqual(store.query(searchedQuery).totals, { uploadBytes: '600', downloadBytes: '1200' });
assert.ok(searched <= 2, `one destination must not be searched per time bucket (${searched} calls)`);
store.ingest([batch(clock + 1, [connection('a', 601, 1202)])], 'live');
assert.equal(store.query(searchedQuery).totals.uploadBytes, '600');
store.ingest([batch(base + 30_000, [connection('late', 7, 9)])], 'live');
assert.deepEqual(store.query(searchedQuery).totals, { uploadBytes: '607', downloadBytes: '1209' });
assert.throws(() => store.ingest([batch(base + 40_000, [
connection('rolled-back', 50, 80), connection('invalid', 'invalid', 1),
])], 'live'));
assert.equal(store.query(searchedQuery).totals.uploadBytes, '607');
clock += 60_000;
assert.deepEqual(store.query(searchedQuery).totals, { uploadBytes: '608', downloadBytes: '1211' });
store.maintain();
assert.equal(store.query(searchedQuery).totals.uploadBytes, '608');
});