Skip to content

Commit

Permalink
Update dependencies (hazelcast#1274)
Browse files Browse the repository at this point in the history
* Fix tests with fake timers failures due to wrong usage
  • Loading branch information
srknzl committed Apr 14, 2022
1 parent 6c26900 commit c461d33
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/node": "~10.17.60",
"@typescript-eslint/eslint-plugin": "~5.13.0",
"@typescript-eslint/parser": "~5.13.0",
"@typescript-eslint/eslint-plugin": "~5.19.0",
"@typescript-eslint/parser": "~5.19.0",
"chai": "~4.3.6",
"chai-as-promised": "~7.1.1",
"eslint": "~8.10.0",
"eslint": "~8.13.0",
"eslint-plugin-mocha": "~9.0.0",
"husky": "~6.0.0",
"jsonschema": "~1.4.0",
"markdown-link-check": "~3.9.3",
"markdown-link-check": "~3.10.0",
"markdownlint-cli": "~0.31.1",
"mocha": "~8.4.0",
"mocha-jenkins-reporter": "~0.4.7",
Expand All @@ -35,11 +35,11 @@
"sinon-chai": "~3.7.0",
"source-map-support": "~0.5.21",
"thrift": "~0.16.0",
"ts-node": "~10.5.0",
"ts-node": "~10.7.0",
"typedoc": "~0.22.10",
"typescript": "~4.5.5",
"winston": "~3.6.0",
"yargs": "~17.3.1"
"yargs": "~17.4.1"
},
"engines": {
"node": ">=10.4.0"
Expand Down
8 changes: 4 additions & 4 deletions test/unit/proxy/cpsubsystem/CPSessionManagerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,25 @@ describe('CPSessionManagerTest', function () {
});

it('isValid: should consider current acquire count', function () {
sandbox.useFakeTimers(0);
const clock = sandbox.useFakeTimers();
const state = new SessionState(Long.fromNumber(42), null, 1000);

// session should be expired now
sandbox.useFakeTimers(2000);
clock.tick(2000);
expect(state.isValid()).to.be.false;

state.acquire(1);
expect(state.isValid()).to.be.true;
});

it('isValid: should consider current time', function () {
sandbox.useFakeTimers(0);
const clock = sandbox.useFakeTimers();
const state = new SessionState(Long.fromNumber(42), null, 1000);

expect(state.isValid()).to.be.true;

// session should be expired now
sandbox.useFakeTimers(2000);
clock.tick(2000);
expect(state.isValid()).to.be.false;
});
});
Expand Down
8 changes: 4 additions & 4 deletions test/unit/proxy/cpsubsystem/FencedLockProxyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,27 +168,27 @@ describe('FencedLockProxyTest', function () {
});

it('tryLock: should return undefined on expired session error and no timeout', async function () {
sandbox.useFakeTimers(0);
const clock = sandbox.useFakeTimers();
prepareAcquireSession(1);
stubRequestTryLock(2, new SessionExpiredError());

const promise = proxy.tryLock();
// advance time as if requests were real
sandbox.useFakeTimers(100);
clock.tick(100);
const fence = await promise;

expect(fence).to.be.undefined;
expect(cpSessionManagerStub.invalidateSession.calledOnce).to.be.true;
});

it('tryLock: should keep trying on expired session error and specified timeout', async function () {
sandbox.useFakeTimers(0);
const clock = sandbox.useFakeTimers();
prepareAcquireSession(1);
stubRequestTryLock(2, new SessionExpiredError());

const promise = proxy.tryLock(1000);
// advance time as if requests were real
sandbox.useFakeTimers(100);
clock.tick(100);
const fence = await promise;

expect(fence.toNumber()).to.be.equal(2);
Expand Down
8 changes: 4 additions & 4 deletions test/unit/proxy/cpsubsystem/SessionAwareSemaphoreProxyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,27 @@ describe('SessionAwareSemaphoreProxyTest', function () {
});

it('tryAcquire: should return false on expired session error and no timeout', async function () {
sandbox.useFakeTimers(0);
const clock = sandbox.useFakeTimers();
prepareAcquireSession(1);
stubRequestAcquire(true, new SessionExpiredError());

const promise = proxy.tryAcquire(1);
// advance time as if requests were real
sandbox.useFakeTimers(100);
clock.tick(100);
const result = await promise;

expect(result).to.be.false;
expect(cpSessionManagerStub.invalidateSession.calledOnce).to.be.true;
});

it('tryAcquire: should keep trying on expired session error and specified timeout', async function () {
sandbox.useFakeTimers(0);
const clock = sandbox.useFakeTimers();
prepareAcquireSession(1);
stubRequestAcquire(true, new SessionExpiredError());

const promise = proxy.tryAcquire(1, 1000);
// advance time as if requests were real
sandbox.useFakeTimers(100);
clock.tick(100);
const result = await promise;

expect(result).to.be.true;
Expand Down

0 comments on commit c461d33

Please sign in to comment.