Skip to content

Commit

Permalink
Undo accidental changes
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson committed Oct 3, 2022
1 parent bcfe1c2 commit e5975d0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 23 deletions.
2 changes: 1 addition & 1 deletion test/integration/change-streams/change_stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { gte, lt } from 'semver';
import * as sinon from 'sinon';
import { PassThrough } from 'stream';
import { setTimeout } from 'timers';
import { inspect, promisify } from 'util';
import { promisify } from 'util';

import {
AbstractCursor,
Expand Down
74 changes: 52 additions & 22 deletions test/unit/sdam/monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,41 +400,71 @@ describe('monitoring', function () {
});
});

context('when it has been < minHeartbeatFrequencyMS since fn() last completed', function () {
context(
'when it has been < minHeartbeatFrequencyMS and >= 0 since fn() last completed',
function () {
beforeEach(function () {
executor = new MonitorInterval(fnSpy, {
minHeartbeatFrequencyMS: 10,
heartbeatFrequencyMS: 30
});

// call fn() once
clock.tick(30);
expect(fnSpy.calledOnce).to.be.true;

fnSpy.callCount = 0;

// advance less than minHeartbeatFrequency
clock.tick(5);

executor.wake();
});

it('reschedules fn() to minHeartbeatFrequencyMS after the last call', function () {
expect(fnSpy.callCount).to.equal(0);
clock.tick(5);
expect(fnSpy.calledOnce).to.be.true;
});

context('when wake() is called more than once', function () {
it('schedules fn() minHeartbeatFrequencyMS after the last call to fn()', function () {
executor.wake();
executor.wake();
executor.wake();

expect(fnSpy.callCount).to.equal(0);
clock.tick(5);
expect(fnSpy.calledOnce).to.be.true;
});
});
}
);

context('when it has been <0 since fn() has last executed', function () {
beforeEach(function () {
executor = new MonitorInterval(fnSpy, {
minHeartbeatFrequencyMS: 10,
heartbeatFrequencyMS: 30
});

// call fn() once
clock.tick(30);
expect(fnSpy.calledOnce).to.be.true;

fnSpy.callCount = 0;

// advance less than minHeartbeatFrequency
clock.tick(5);

// negative ticks aren't supported, so manually set execution time
executor.lastExecutionEnded = Infinity;
executor.wake();
});

it('reschedules fn() to minHeartbeatFrequencyMS after the last call', function () {
expect(fnSpy.callCount).to.equal(0);
clock.tick(5);
it('executes fn() immediately', function () {
expect(fnSpy.calledOnce).to.be.true;
});

context('when wake() is called more than once', function () {
it('schedules fn() minHeartbeatFrequencyMS after the last call to fn()', function () {
executor.wake();
executor.wake();
executor.wake();
it('reschedules fn() to minHeartbeatFrequency away', function () {
fnSpy.callCount = 0;

expect(fnSpy.callCount).to.equal(0);
clock.tick(5);
expect(fnSpy.calledOnce).to.be.true;
});
clock.tick(29);
expect(fnSpy.callCount).to.equal(0);

clock.tick(1);
expect(fnSpy.calledOnce).to.be.true;
});
});
});
Expand Down

0 comments on commit e5975d0

Please sign in to comment.