diff --git a/packages/shell-api/src/database.ts b/packages/shell-api/src/database.ts index fc2d0d320..ea52b93ef 100644 --- a/packages/shell-api/src/database.ts +++ b/packages/shell-api/src/database.ts @@ -1602,7 +1602,7 @@ export class Database< if (startOptimeDate) { nodeResult.syncedTo = node.optimeDate.toString(); } - const ago = (node.optimeDate - startOptimeDate) / 1000; + const ago = (startOptimeDate - node.optimeDate) / 1000; const hrs = Math.round(ago / 36) / 100; let suffix = ''; if (primary) { diff --git a/packages/shell-api/src/replica-set.spec.ts b/packages/shell-api/src/replica-set.spec.ts index 55d8b3b2f..eb581f852 100644 --- a/packages/shell-api/src/replica-set.spec.ts +++ b/packages/shell-api/src/replica-set.spec.ts @@ -895,8 +895,17 @@ describe('ReplicaSet', function () { expect(result.ismaster).to.be.true; }); it('returns StatsResult for print secondary replication info', async function () { + const coll = db.getCollection('cstest'); + await coll.insertOne({ i: 42 }); + const result = await rs.printSecondaryReplicationInfo(); expect(result.type).to.equal('StatsResult'); + for (const value of Object.values( + result.value as Record + )) { + // just check that the value is not negative + expect(value.replLag).to.match(/^\d+ sec/); + } }); it('returns StatsResult for print replication info', async function () { const result = await rs.printReplicationInfo();