Skip to content

Commit

Permalink
test: adjust circuit breaker state manager tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelJCamara committed May 2, 2024
1 parent 0ac8468 commit 2db1171
Showing 1 changed file with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ describe("circuit state manager", () => {
);
//Act
//Assert
expect(circuitStateManager.isCurrentStateClosed).toBeTruthy();
expect(circuitStateManager.isCurrentStateClosed()).toBe(true);
});

test("moving from closed to open", () => {
test("moving from closed to open and then to half-opened should be allowed", () => {
//Arrange
const circuitStateManager = new CircuitBreakerStateManager({
onHalfOpen: () => {},
Expand All @@ -21,31 +21,50 @@ describe("circuit state manager", () => {
circuitStateManager.moveStateToOpen();

//Assert
expect(circuitStateManager.isCurrentStateOpen).toBeTruthy();
expect(circuitStateManager.isCurrentStateOpen()).toBeTruthy();

//move to half-open
circuitStateManager.moveStateToHalfOpen();
expect(circuitStateManager.isCurrentStateHalfOpen()).toBe(true);
});

test("moving from closed to half", () => {
test("moving from closed to open and then to half-opened and then to closed should be allowed", () => {
//Arrange
const circuitStateManager = new CircuitBreakerStateManager({
onHalfOpen: () => {},
} as CircuitBreakerPolicyType);
//Act
circuitStateManager.moveStateToHalfOpen();
circuitStateManager.moveStateToOpen();

//Assert
expect(circuitStateManager.isCurrentStateHalfOpen).toBeTruthy();
expect(circuitStateManager.isCurrentStateOpen).toBeTruthy();

//move to half-open
circuitStateManager.moveStateToHalfOpen();
expect(circuitStateManager.isCurrentStateHalfOpen()).toBe(true);

//move to closed
circuitStateManager.moveStateToClosed();
expect(circuitStateManager.isCurrentStateClosed()).toBe(true);
});

test("moving from closed to half and then to closed", () => {
test("moving from closed to open and then to half-opened and then to opened should be allowed", () => {
//Arrange
const circuitStateManager = new CircuitBreakerStateManager({
onHalfOpen: () => {},
} as CircuitBreakerPolicyType);
//Act
circuitStateManager.moveStateToHalfOpen();
circuitStateManager.moveStateToOpen();

//Assert
expect(circuitStateManager.isCurrentStateClosed).toBeTruthy();
expect(circuitStateManager.isCurrentStateOpen).toBeTruthy();

//move to half-open
circuitStateManager.moveStateToHalfOpen();
expect(circuitStateManager.isCurrentStateHalfOpen()).toBe(true);

//move to open
circuitStateManager.moveStateToOpen();
expect(circuitStateManager.isCurrentStateOpen()).toBe(true);
});
});

0 comments on commit 2db1171

Please sign in to comment.