Skip to content

Commit a216541

Browse files
committed
fix: changed discovery test should force discovery on recently processed vertices to expect 2 calls instead of 3 on the 2nd attempt
fix: changed NodesAuditEventsGet to not skip the first value anymore because we want seek to be inclusive. fixed its tests to match these changes
1 parent eaeadd3 commit a216541

File tree

4 files changed

+14
-25
lines changed

4 files changed

+14
-25
lines changed

src/nodes/NodeManager.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,9 @@ class NodeManager {
12711271
seek: claimIdEncoded,
12721272
},
12731273
ctx,
1274+
12741275
)) {
1276+
console.log("Processing claim id:", agentClaim.claimIdEncoded);
12751277
ctx.signal.throwIfAborted();
12761278
// Need to re-construct each claim
12771279
const claimId: ClaimId = claimsUtils.decodeClaimId(

src/nodes/agent/handlers/NodesAuditEventsGet.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ class NodesAuditEventsGet extends ServerHandler<
5757
tran,
5858
)) {
5959
ctx.signal.throwIfAborted();
60-
// Skip the seek event to ensure exclusivity if given an AuditEventId
61-
// This assumes that ids are unique
62-
if (seek_ !== undefined) {
63-
if (typeof seek_ !== 'number' && auditEvent.id.equals(seek_)) {
64-
continue;
65-
}
66-
}
6760
yield {
6861
id: auditUtils.encodeAuditEventId(auditEvent.id),
6962
path: auditEvent.path,

tests/discovery/Discovery.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ describe('Discovery', () => {
698698
await discovery.stop();
699699
await discovery.destroy();
700700
});
701-
test('should force discovery on recently processed vertices', async () => {
701+
test.only('should force discovery on recently processed vertices', async () => {
702702
const discovery = await Discovery.createDiscovery({
703703
db,
704704
keyRing,
@@ -724,7 +724,7 @@ describe('Discovery', () => {
724724
await discovery.queueDiscoveryByNode(nodeA.keyRing.getNodeId(), Date.now());
725725
await waitForAllDiscoveryTasks(discovery);
726726
// All vertices should be reprocessed
727-
expect(processVertexMock).toHaveBeenCalledTimes(3);
727+
expect(processVertexMock).toHaveBeenCalledTimes(2);
728728

729729
await taskManager.stopProcessing();
730730
await discovery.stop();

tests/nodes/agent/handlers/nodesAuditsGet.test.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -291,18 +291,15 @@ describe('nodesAuditEventsGet', () => {
291291
auditIds.push(result.id);
292292
}
293293

294-
// We expect everything AFTER the seekIndex event
295-
// => from (seekIndex+1) to the end
294+
// We expect everything AFTER the seekIndex event INCLUDING the seekIndex event
295+
// => from (seekIndex) to the end
296296
const expectedIds = eventIds
297-
.slice(seekIndex + 1)
297+
.slice(seekIndex)
298298
.map((id) => auditUtils.encodeAuditEventId(id));
299299

300-
// Check that we only get the tail portion
300+
// Check that we only get the tail portion including the seekIndex event
301301
expect(auditIds).toEqual(expectedIds);
302302

303-
// Confirm the event at "seekIndex" is excluded
304-
expect(auditIds).not.toContain(seekValueEncoded);
305-
306303
// Reset DB so subsequent runs in this property-based test
307304
// don't accumulate leftover events.
308305
await db.clear();
@@ -312,7 +309,7 @@ describe('nodesAuditEventsGet', () => {
312309
test.prop([
313310
testNodesUtils.randomAuditEventsArb(2), // At least 2 so there's a valid seek index
314311
])(
315-
'should get audit events with specific seek at index 0 (exclude the first event) [property-based]',
312+
'should get audit events with specific seek at index 0 [property-based]',
316313
async (events) => {
317314
const eventIds: Array<AuditEventId> = [];
318315
for (const e of events) {
@@ -346,13 +343,12 @@ describe('nodesAuditEventsGet', () => {
346343
auditIds.push(result.id);
347344
}
348345

349-
// We expect everything from index 1 onward
346+
// We expect everything from index 1 onward including the seekIndex event
350347
const expectedIds = eventIds
351-
.slice(seekIndex + 1)
348+
.slice(seekIndex)
352349
.map((id) => auditUtils.encodeAuditEventId(id));
353350

354351
expect(auditIds).toEqual(expectedIds);
355-
expect(auditIds).not.toContain(seekIdEncoded);
356352

357353
// Clear DB for the next run
358354
await db.clear();
@@ -362,7 +358,7 @@ describe('nodesAuditEventsGet', () => {
362358
test.prop([
363359
testNodesUtils.randomAuditEventsArb(1), // At least 1 event, so "last index" = length-1 is valid
364360
])(
365-
'should get audit events with specific seek at last index (exclude the last event) [property-based]',
361+
'should get audit events with specific seek at last index [property-based]',
366362
async (events) => {
367363
// 1) Insert them all
368364
const eventIds: Array<AuditEventId> = [];
@@ -395,10 +391,8 @@ describe('nodesAuditEventsGet', () => {
395391
auditIds.push(result.id);
396392
}
397393

398-
// We expect an EMPTY result, because there's nothing after the last event
399-
expect(auditIds).toHaveLength(0);
400-
// Confirm the last event’s ID is not present
401-
expect(auditIds).not.toContain(seekIdEncoded);
394+
// We expect a SINGLE result, because it should only return the seekIndex event
395+
expect(auditIds).toHaveLength(1);
402396

403397
// Clear DB for the next run
404398
await db.clear();

0 commit comments

Comments
 (0)