Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #301 #302

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

fix #301 #302

wants to merge 6 commits into from

Conversation

mr-git
Copy link

@mr-git mr-git commented Feb 1, 2024

My humble attempt to fix premature closing, though I am challenged by Scala.js

For local testing, I had to change Scala versions to latests (I am using only JDK 21), but I can drop those changes, if this will compile.

Not sure, but IMHO it would be nice to update to latest Cats Effect 3.5.x, thus I updated version from 0.5 to 0.6.

I can drop all of those updates!

@mr-git
Copy link
Author

mr-git commented Feb 1, 2024

If you mind the updates, I can revert them all and hope for best

Copy link
Collaborator

@TimWSpence TimWSpence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mr-git thanks so much for taking this on and for fixing the dependency updates, etc at the same time! I'm new to the project but have done my best to review it.

I hope it doesn't look like too much - most of the comments are just aimed at making the tests easier to read. Please let me know if any of them don't make sense!

),
mimaBinaryIssueFilters := Seq(
ProblemFilters.exclude[DirectMissingMethodProblem]("io.chrisdavenport.circuit.CircuitBreaker#SyncCircuitBreaker.this")
),
).jsSettings(
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule)},
).nativeSettings(
tlVersionIntroduced := List("2.12", "2.13", "3").map(_ -> "0.5.1").toMap
tlVersionIntroduced := List("2.12", "2.13", "3").map(_ -> "1.15.0").toMap
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be changed? I thought this was set to whatever version at which we first introduced scala native support

closed <- Ref[IO].of(false)
cb = cb1.doOnOpen(opened.set(true)).doOnClosed(closed.set(true)).doOnHalfOpen(halfOpened.set(true))
dummy = new RuntimeException("dummy")
taskInError = cb.protect(IO[Int](throw dummy))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More idiomatically this would be IO.raiseError(dummy)

taskSlowSucceeds = cb.protect(IO.sleep(slowDuration))
_ <- taskSlowSucceeds.start
_ <- cb.state.map {
case _: CircuitBreaker.Closed => assert(true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll get better error messages if this is cb.state.map(st => assertEquals(st, CircuitBreaker.Closed))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, seeing the other assertions that you have, you could extract a

def expectState(expected: CircuitBreaker.State) = cb.state.assertEquals(expected)

That might make these tests a bit easier to read

backoff = Backoff.constant(resetTimeout),
maxResetTimeout = resetTimeout
)
opened <- Ref[IO].of(false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these used?

_ <- taskSlowSucceeds.attempt
_ <- cb.state.map {
case _: CircuitBreaker.Closed => assert(true)
case x => println(x); assert(false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

println 😉

case Left(_: CircuitBreaker.RejectedExecution) => assert(true)
case _ => assert(false)
}
_ <- IO.sleep(slowDuration + 10.milliseconds) // `taskSlowSucceeds` finishes after expiration and closes `cb`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of sleeping here, we could actually save a handle to the fiber of the initial taskSlowSucceeds and then we could call fiber.join to wait the minimum amount of time here

test
}

test("Validate behaviour for one slow call followed by fast calls"){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as above. Maybe if we renamed taskSlowSucceeds to something like taskFasterThanResetTimeout (still a bit wordy - maybe we can do better) then the intention would be clearer? I initially assumed that taskSlowSucceeds would take longer than the reset timeout and got confused what this was testing

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be named something like Should not close circuit again before reset timeout has elapsed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants