MCPcopy
hub / github.com/mongodb/node-mongodb-native / compareEvents

Function compareEvents

test/tools/unified-spec-runner/match.ts:537–680  ·  view source on GitHub ↗
(
  actual: CommandEvent[] | CmapEvent[] | SdamEvent[],
  expected: (ExpectedCommandEvent & ExpectedCmapEvent & ExpectedSdamEvent)[],
  entities: EntitiesMap
)

Source from the content-addressed store, hash-verified

535}
536
537function compareEvents(
538 actual: CommandEvent[] | CmapEvent[] | SdamEvent[],
539 expected: (ExpectedCommandEvent & ExpectedCmapEvent & ExpectedSdamEvent)[],
540 entities: EntitiesMap
541) {
542 if (actual.length !== expected.length) {
543 failOnMismatchedCount(actual, expected);
544 }
545 for (const [index, actualEvent] of actual.entries()) {
546 const expectedEvent = expected[index];
547 const rootPrefix = `events[${index}]`;
548
549 if (expectedEvent.commandStartedEvent) {
550 const path = `${rootPrefix}.commandStartedEvent`;
551 expectInstanceOf(actualEvent, CommandStartedEvent);
552 compareCommandStartedEvents(actualEvent, expectedEvent.commandStartedEvent, entities, path);
553 if (expectedEvent.commandStartedEvent.hasServerConnectionId) {
554 expect(actualEvent).property('serverConnectionId').to.be.a('bigint');
555 } else if (expectedEvent.commandStartedEvent.hasServerConnectionId === false) {
556 expect(actualEvent).property('serverConnectionId').to.be.null;
557 }
558 } else if (expectedEvent.commandSucceededEvent) {
559 const path = `${rootPrefix}.commandSucceededEvent`;
560 expectInstanceOf(actualEvent, CommandSucceededEvent);
561 compareCommandSucceededEvents(
562 actualEvent,
563 expectedEvent.commandSucceededEvent,
564 entities,
565 path
566 );
567 if (expectedEvent.commandSucceededEvent.hasServerConnectionId) {
568 expect(actualEvent).property('serverConnectionId').to.be.a('bigint');
569 } else if (expectedEvent.commandSucceededEvent.hasServerConnectionId === false) {
570 expect(actualEvent).property('serverConnectionId').to.be.null;
571 }
572 } else if (expectedEvent.commandFailedEvent) {
573 const path = `${rootPrefix}.commandFailedEvent`;
574 expectInstanceOf(actualEvent, CommandFailedEvent);
575 compareCommandFailedEvents(actualEvent, expectedEvent.commandFailedEvent, entities, path);
576 if (expectedEvent.commandFailedEvent.hasServerConnectionId) {
577 expect(actualEvent).property('serverConnectionId').to.be.a('bigint');
578 } else if (expectedEvent.commandFailedEvent.hasServerConnectionId === false) {
579 expect(actualEvent).property('serverConnectionId').to.be.null;
580 }
581 } else if (expectedEvent.connectionClosedEvent) {
582 expect(actualEvent).to.be.instanceOf(ConnectionClosedEvent);
583 if (expectedEvent.connectionClosedEvent.hasServiceId) {
584 expect(actualEvent).property('serviceId').to.exist;
585 }
586 } else if (expectedEvent.poolClearedEvent) {
587 expect(actualEvent).to.be.instanceOf(ConnectionPoolClearedEvent);
588 if (expectedEvent.poolClearedEvent.hasServiceId) {
589 expect(actualEvent).property('serviceId').to.exist;
590 }
591 if (expectedEvent.poolClearedEvent.interruptInUseConnections != null) {
592 expect(actualEvent)
593 .property('interruptInUseConnections')
594 .to.equal(expectedEvent.poolClearedEvent.interruptInUseConnections);

Callers 1

matchesEventsFunction · 0.85

Calls 8

failOnMismatchedCountFunction · 0.85
expectInstanceOfFunction · 0.85
validEmptyCmapEventFunction · 0.85
failMethod · 0.80
inspectFunction · 0.50

Tested by

no test coverage detected