Skip to content

Commit

Permalink
Fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tichon29 committed Apr 30, 2024
1 parent 48eb524 commit bd93e3c
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 33 deletions.
64 changes: 35 additions & 29 deletions .github/scripts/redis_test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const testRateLimitModule = async () => {
process.exit(1);
}
}
console.log('Testing Rate Limit Module - Result is OK');
}

const testSlidingCountBreakerModule = async () => {
Expand Down Expand Up @@ -147,6 +148,7 @@ const testSlidingCountBreakerModule = async () => {
check(slidingCountBreaker.state === Mollitia.BreakerState.CLOSED, 'Ok, circuit is closed', 'Circuit is not closed as expected...');
await failure(circuit2, { data: 'Circuit2' });
check(slidingCountBreaker2.state === Mollitia.BreakerState.OPENED, 'Ok, circuit is opened', 'Circuit is not opened as expected...');
console.log('Testing Sliding Count Breaker Module - Result is OK');
}
const testSlidingTimeBreakerModule = async () => {
console.log('Testing Sliding Time Breaker Module');
Expand Down Expand Up @@ -188,44 +190,48 @@ const testSlidingTimeBreakerModule = async () => {
check(slidingTimeBreaker3.state === Mollitia.BreakerState.CLOSED, 'Ok, circuit is closed', 'Circuit is not closed as expected...');
await failure(circuit3, { data: 'Circuit3' });
check(slidingTimeBreaker3.state === Mollitia.BreakerState.OPENED, 'Ok, circuit is opened', 'Circuit is not opened as expected...');
console.log('Testing Sliding Time Breaker Module - Result is OK');
}
const testSlidingTimeBreakerModuleSlowRequest = async () => {
console.log('Testing Sliding Time Breaker Module With Slow Requests');
const breakerData = {
failureRateThreshold: 50,
openStateDelay: 10,
slidingWindowSize: 1000,
minimumNumberOfCalls: 2,
permittedNumberOfCallsInHalfOpenState: 1,
slowCallDurationThreshold: 100,
slowCallRateThreshold: 50,
redis: {
use: true
},
name: 'mySlidingTimeBreakerSlow'
};
const slidingTimeBreaker = new Mollitia.SlidingTimeBreaker(breakerData);
const slidingTimeBreaker2 = new Mollitia.SlidingTimeBreaker(breakerData);
const circuit1 = new Mollitia.Circuit({ options: { modules: [slidingTimeBreaker] } });
const circuit2 = new Mollitia.Circuit({ options: { modules: [slidingTimeBreaker2] } });
await success(circuit1, { data: 'Circuit1', delay: 150 });
await success(circuit2, { data: 'Circuit2' });
// Even if 50% of slow requests, circuit is kept closed as last request is success
check(slidingTimeBreaker2.state === Mollitia.BreakerState.CLOSED, 'Ok, circuit is closed', 'Circuit is not closed as expected...');
await success(circuit1, { data: 'Circuit1', delay: 150 });
check(slidingTimeBreaker.state === Mollitia.BreakerState.OPENED, 'Ok, circuit is opened', 'Circuit is not opened as expected...');
await delay(150);
check(slidingTimeBreaker.state === Mollitia.BreakerState.HALF_OPENED, 'Ok, circuit is Half Opened', 'Circuit is not Half Opened as expected...');
await success(circuit2, { data: 'Circuit2', delay: 150 });
check(slidingTimeBreaker2.state === Mollitia.BreakerState.OPENED, 'Ok, circuit is opened', 'Circuit is not opened as expected...');
await delay(10);
await expect(circuit.fn(successAsync).execute('dummy')).resolves.toEqual('dummy');
expect(slidingTimeBreaker.state).toEqual(Mollitia.BreakerState.CLOSED);
failureRateThreshold: 50,
openStateDelay: 10,
slidingWindowSize: 1000,
minimumNumberOfCalls: 2,
permittedNumberOfCallsInHalfOpenState: 1,
slowCallDurationThreshold: 100,
slowCallRateThreshold: 50,
redis: {
use: true
},
name: 'mySlidingTimeBreakerSlow'
};
const slidingTimeBreaker = new Mollitia.SlidingTimeBreaker(breakerData);
const slidingTimeBreaker2 = new Mollitia.SlidingTimeBreaker(breakerData);
const circuit1 = new Mollitia.Circuit({ options: { modules: [slidingTimeBreaker] } });
const circuit2 = new Mollitia.Circuit({ options: { modules: [slidingTimeBreaker2] } });
await success(circuit1, { data: 'Circuit1', delay: 150 });
await success(circuit2, { data: 'Circuit2' });
// Even if 50% of slow requests, circuit is kept closed as last request is success
check(slidingTimeBreaker2.state === Mollitia.BreakerState.CLOSED, 'Ok, circuit is closed', 'Circuit is not closed as expected...');
await success(circuit1, { data: 'Circuit1', delay: 150 });
check(slidingTimeBreaker.state === Mollitia.BreakerState.OPENED, 'Ok, circuit is opened', 'Circuit is not opened as expected...');
await delay(150);
check(slidingTimeBreaker.state === Mollitia.BreakerState.HALF_OPENED, 'Ok, circuit is Half Opened', 'Circuit is not Half Opened as expected...');
await success(circuit2, { data: 'Circuit2', delay: 150 });
check(slidingTimeBreaker2.state === Mollitia.BreakerState.OPENED, 'Ok, circuit is opened', 'Circuit is not opened as expected...');
await delay(10);
await success(circuit1, { data: 'Circuit1' });
check(slidingTimeBreaker.state === Mollitia.BreakerState.CLOSED, 'Ok, circuit is closed', 'Circuit is not closed as expected...');
console.log('Testing Sliding Time Breaker Module With Slow Requests - Result is OK');
}

const main = async () => {
await testRateLimitModule();
await testSlidingCountBreakerModule();
await testSlidingTimeBreakerModule();
await testSlidingTimeBreakerModuleSlowRequest();
process.exit(0);
}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules
/.npmrc
**/node_modules
3 changes: 1 addition & 2 deletions docs/src/guide/customization/addons/redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ The `Mollitia` [Redis](https://redis.io/) addon adds redis for some modules of e
# Install mollitia
npm install mollitia --save
# Install Redis and the Redis addon
npm install redis --save
npm install @mollitia/redis --save
npm install @mollitia/redis redis --save
```

``` typescript
Expand Down
113 changes: 111 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"build": "nx run-many -t build --output-style=stream",
"test": "nx run-many -t test:unit --output-style=stream",
"lint": "nx run-many -t lint --output-style=stream",
"clean": "nx run-many -t clean --output-style=stream && rm -rf node_modules",
"preview": "nx preview docs",
"version": "lerna version",
"changelog": "vertis generate",
Expand Down

0 comments on commit bd93e3c

Please sign in to comment.