Skip to content

Commit 25b7ffe

Browse files
authored
fix(shell-api): replication lag reported negative value MONGOSH-3063 (#2624)
1 parent 16830fc commit 25b7ffe

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/shell-api/src/database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,7 @@ export class Database<
16021602
if (startOptimeDate) {
16031603
nodeResult.syncedTo = node.optimeDate.toString();
16041604
}
1605-
const ago = (node.optimeDate - startOptimeDate) / 1000;
1605+
const ago = (startOptimeDate - node.optimeDate) / 1000;
16061606
const hrs = Math.round(ago / 36) / 100;
16071607
let suffix = '';
16081608
if (primary) {

packages/shell-api/src/replica-set.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,17 @@ describe('ReplicaSet', function () {
895895
expect(result.ismaster).to.be.true;
896896
});
897897
it('returns StatsResult for print secondary replication info', async function () {
898+
const coll = db.getCollection('cstest');
899+
await coll.insertOne({ i: 42 });
900+
898901
const result = await rs.printSecondaryReplicationInfo();
899902
expect(result.type).to.equal('StatsResult');
903+
for (const value of Object.values(
904+
result.value as Record<string, any>
905+
)) {
906+
// just check that the value is not negative
907+
expect(value.replLag).to.match(/^\d+ sec/);
908+
}
900909
});
901910
it('returns StatsResult for print replication info', async function () {
902911
const result = await rs.printReplicationInfo();

0 commit comments

Comments
 (0)