Skip to content

Commit

Permalink
Fixed some infix warnings for Span's scaledBy by changing it to the n…
Browse files Browse the repository at this point in the history
…ormal method invocation syntax.
  • Loading branch information
cheeseng committed Mar 4, 2024
1 parent 157c30b commit 59d0774
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 56 deletions.
Expand Up @@ -1111,7 +1111,7 @@ trait Conductors extends PatienceConfiguration {
private def detectDeadlock(): Unit = {
// Should never get to >= before ==, but just playing it safe
if (deadlockCount >= MaxDeadlockDetectionsBeforeDeadlock) {
val errorMessage = Resources.suspectedDeadlock(MaxDeadlockDetectionsBeforeDeadlock.toString, (clockInterval scaledBy MaxDeadlockDetectionsBeforeDeadlock).prettyString)
val errorMessage = Resources.suspectedDeadlock(MaxDeadlockDetectionsBeforeDeadlock.toString, (clockInterval.scaledBy(MaxDeadlockDetectionsBeforeDeadlock)).prettyString)
firstExceptionThrown offer new RuntimeException(errorMessage)

// The mainThread is likely joined to some test thread, so wake it up. It will look and
Expand Down
Expand Up @@ -182,7 +182,7 @@ trait ScaledTimeSpans {
* @throws IllegalArgumentException if the value returned from <code>spanScaleFactor</code>
* is less than zero
*/
final def scaled(span: Span): Span = span scaledBy spanScaleFactor
final def scaled(span: Span): Span = span.scaledBy(spanScaleFactor)

/**
* The factor by which the <code>scaled</code> method will scale <code>Span</code>s.
Expand Down
10 changes: 5 additions & 5 deletions jvm/core/src/main/scala/org/scalatest/enablers/Retrying.scala
Expand Up @@ -78,7 +78,7 @@ object Retrying {
def retry(timeout: Span, interval: Span, pos: source.Position)(fun: => Future[T]): Future[T] = {
val startNanos = System.nanoTime

val initialInterval = Span(interval.totalNanos * 0.1, Nanoseconds) // config.interval scaledBy 0.1
val initialInterval = Span(interval.totalNanos * 0.1, Nanoseconds)

// Can't make this tail recursive. TODO: Document that fact.
def tryTryAgain(attempt: Int): Future[T] = {
Expand Down Expand Up @@ -120,7 +120,7 @@ object Retrying {
promise.future
}
else { // Timed out so return a failed Future
val durationSpan = Span(1, Nanosecond) scaledBy duration // Use scaledBy to get pretty units
val durationSpan = Span(1, Nanosecond).scaledBy(duration) // Use scaledBy to get pretty units
Future.failed(
new TestFailedDueToTimeoutException(
(_: StackDepthException) =>
Expand Down Expand Up @@ -150,7 +150,7 @@ object Retrying {
Thread.sleep(interval.millisPart, interval.nanosPart)
}
else {
val durationSpan = Span(1, Nanosecond) scaledBy duration // Use scaledBy to get pretty units
val durationSpan = Span(1, Nanosecond).scaledBy(duration) // Use scaledBy to get pretty units
throw new TestFailedDueToTimeoutException(
(_: StackDepthException) =>
Some(
Expand Down Expand Up @@ -189,7 +189,7 @@ object Retrying {
}
}

val initialInterval = Span(interval.totalNanos * 0.1, Nanoseconds) // config.interval scaledBy 0.1
val initialInterval = Span(interval.totalNanos * 0.1, Nanoseconds)

@tailrec
def tryTryAgain(attempt: Int): T = {
Expand All @@ -204,7 +204,7 @@ object Retrying {
Thread.sleep(interval.millisPart, interval.nanosPart)
}
else {
val durationSpan = Span(1, Nanosecond) scaledBy duration // Use scaledBy to get pretty units
val durationSpan = Span(1, Nanosecond).scaledBy(duration) // Use scaledBy to get pretty units
throw new TestFailedDueToTimeoutException(
(_: StackDepthException) =>
Some(
Expand Down
98 changes: 49 additions & 49 deletions jvm/scalatest-test/src/test/scala/org/scalatest/time/SpanSpec.scala
Expand Up @@ -737,263 +737,263 @@ class SpanSpec extends AnyFunSpec with Matchers with SpanMatchers {
describe("when scaled via the scaleBy method") {
it("should throw IllegalArgumentException when a negative number is passed") {
intercept[IllegalArgumentException] {
Span(1, Second) scaledBy -1
Span(1, Second).scaledBy(-1)
}
intercept[IllegalArgumentException] {
Span(1, Second) scaledBy -1.0
Span(1, Second).scaledBy(-1.0)
}
}
it("should return the exact same Span when 1 is passed") {
val span = Span(1, Second)
assert(span scaledBy 1 eq span)
assert(span scaledBy 1.0 eq span)
assert(span.scaledBy(1) eq span)
assert(span.scaledBy(1.0) eq span)
}
it("should return an zero-length Span when 0 is passed") {
assert((Span(1, Second) scaledBy 0) === Span.Zero)
assert((Span(1, Second) scaledBy 0.0) === Span.Zero)
assert((Span(1, Second).scaledBy(0)) === Span.Zero)
assert((Span(1, Second).scaledBy(0.0)) === Span.Zero)
}
it("should give correct results when only operating in the nanosPart") {
assert((Span(1, Nanosecond) scaledBy 100) === Span(100, Nanoseconds))
assert((Span(1, Nanosecond) scaledBy 100.0) === Span(100, Nanoseconds))
assert((Span(1, Nanosecond).scaledBy(100)) === Span(100, Nanoseconds))
assert((Span(1, Nanosecond).scaledBy(100.0)) === Span(100, Nanoseconds))
}
it("should give correct results when only operating in the millisPart") {
assert((Span(1, Millisecond) scaledBy 100) === Span(100, Milliseconds))
assert((Span(1, Millisecond) scaledBy 100.0) === Span(100, Milliseconds))
assert((Span(1, Millisecond).scaledBy(100)) === Span(100, Milliseconds))
assert((Span(1, Millisecond).scaledBy(100.0)) === Span(100, Milliseconds))
}
it("should give Span.Max when overflow occurs") {
assert((Span.Max scaledBy 2) === Span.Max)
assert((Span.Max scaledBy 2.0) === Span.Max)
assert((Span.Max.scaledBy(2)) === Span.Max)
assert((Span.Max.scaledBy(2.0)) === Span.Max)
}
it("should give Span.Zero if less than 1 nanosecond") {
assert((Span(1, Nanosecond) scaledBy 0.1) === Span.Zero)
assert((Span(1, Nanosecond).scaledBy(0.1)) === Span.Zero)
}
it("should be 0 Nanoseconds if zero length span") {
{
val span = Span(1, Day) scaledBy 0
val span = Span(1, Day).scaledBy(0)
assert(span === Span(0, Nanoseconds))
assert(span.toString === "Span(0, Nanoseconds)")
assert(span.prettyString === "0 nanoseconds")
}
{
val span = Span(0, Nanoseconds) scaledBy 100
val span = Span(0, Nanoseconds).scaledBy(100)
assert(span === Span(0, Nanoseconds))
assert(span.toString === "Span(0, Nanoseconds)")
assert(span.prettyString === "0 nanoseconds")
}
}
it("should have nanosecond units if < 1000 nanoseconds") {
{
val span = Span(100, Nanoseconds) scaledBy 0.01
val span = Span(100, Nanoseconds).scaledBy(0.01)
assert(span === Span(1, Nanosecond))
assert(span.toString === "Span(1, Nanosecond)")
assert(span.prettyString === "1 nanosecond")
}
{
val span = Span(100, Nanoseconds) scaledBy 5
val span = Span(100, Nanoseconds).scaledBy(5)
assert(span === Span(500, Nanoseconds))
assert(span.toString === "Span(500, Nanoseconds)")
assert(span.prettyString === "500 nanoseconds")
}
{
val span = Span(100, Nanoseconds) scaledBy 5.001
val span = Span(100, Nanoseconds).scaledBy(5.001)
assert(span === Span(500.1, Nanoseconds))
assert(span.toString === "Span(500.1, Nanoseconds)")
assert(span.prettyString === "500.1 nanoseconds")
}
{
val span = Span(1, Nanosecond) scaledBy 999
val span = Span(1, Nanosecond).scaledBy(999)
assert(span === Span(999, Nanoseconds))
assert(span.toString === "Span(999, Nanoseconds)")
assert(span.prettyString === "999 nanoseconds")
}
}
it("should have microsecond units if > 1 and < 1000 microseconds") {
{
val span = Span(1, Nanosecond) scaledBy 1000
val span = Span(1, Nanosecond).scaledBy(1000)
assert(span === Span(1, Microsecond))
assert(span.toString === "Span(1, Microsecond)")
assert(span.prettyString === "1 microsecond")
}
{
val span = Span(100, Microseconds) scaledBy 0.01
val span = Span(100, Microseconds).scaledBy(0.01)
assert(span === Span(1, Microsecond))
assert(span.toString === "Span(1, Microsecond)")
assert(span.prettyString === "1 microsecond")
}
{
val span = Span(100, Microseconds) scaledBy 5
val span = Span(100, Microseconds).scaledBy(5)
assert(span === Span(500, Microseconds))
assert(span.toString === "Span(500, Microseconds)")
assert(span.prettyString === "500 microseconds")
}
{
val span = Span(3, Microseconds) scaledBy 0.5
val span = Span(3, Microseconds).scaledBy(0.5)
assert(span === Span(1.5, Microseconds))
assert(span.toString === "Span(1.5, Microseconds)")
assert(span.prettyString === "1.5 microseconds")
}
{
val span = Span(1, Microsecond) scaledBy 999
val span = Span(1, Microsecond).scaledBy(999)
assert(span === Span(999, Microseconds))
assert(span.toString === "Span(999, Microseconds)")
assert(span.prettyString === "999 microseconds")
}
}
it("should have millisecond units if > 1 and < 1000 milliseconds") {
{
val span = Span(1, Microsecond) scaledBy 1000
val span = Span(1, Microsecond).scaledBy(1000)
assert(span === Span(1, Millisecond))
assert(span.toString === "Span(1, Millisecond)")
assert(span.prettyString === "1 millisecond")
}
{
val span = Span(100, Millis) scaledBy 0.01
val span = Span(100, Millis).scaledBy(0.01)
assert(span === Span(1, Millisecond))
assert(span.toString === "Span(1, Millisecond)")
assert(span.prettyString === "1 millisecond")
}
{
val span = Span(100, Millis) scaledBy 5
val span = Span(100, Millis).scaledBy(5)
assert(span === Span(500, Millis))
assert(span.toString === "Span(500, Millis)")
assert(span.prettyString === "500 milliseconds")
}
{
val span = Span(3, Millis) scaledBy 0.5
val span = Span(3, Millis).scaledBy(0.5)
assert(span === Span(1.5, Millis))
assert(span.toString === "Span(1.5, Millis)")
assert(span.prettyString === "1.5 milliseconds")
}
{
val span = Span(1, Millisecond) scaledBy 999
val span = Span(1, Millisecond).scaledBy(999)
assert(span === Span(999, Millis))
assert(span.toString === "Span(999, Millis)")
assert(span.prettyString === "999 milliseconds")
}
}
it("should have second units if > 1 and < 60 seconds") {
{
val span = Span(1, Millisecond) scaledBy 1000
val span = Span(1, Millisecond).scaledBy(1000)
assert(span === Span(1, Second))
assert(span.toString === "Span(1, Second)")
assert(span.prettyString === "1 second")
}
{
val span = Span(100, Seconds) scaledBy 0.01
val span = Span(100, Seconds).scaledBy(0.01)
assert(span === Span(1, Second))
assert(span.toString === "Span(1, Second)")
assert(span.prettyString === "1 second")
}
{
val span = Span(10, Seconds) scaledBy 5
val span = Span(10, Seconds).scaledBy(5)
assert(span === Span(50, Seconds))
assert(span.toString === "Span(50, Seconds)")
assert(span.prettyString === "50 seconds")
}
{
val span = Span(3, Seconds) scaledBy 0.5
val span = Span(3, Seconds).scaledBy(0.5)
assert(span === Span(1.5, Seconds))
assert(span.toString === "Span(1.5, Seconds)")
assert(span.prettyString === "1.5 seconds")
}
{
val span = Span(1, Second) scaledBy 59
val span = Span(1, Second).scaledBy(59)
assert(span === Span(59, Seconds))
assert(span.toString === "Span(59, Seconds)")
assert(span.prettyString === "59 seconds")
}
}
it("should have minute units if > 1 and < 60 minutes") {
{
val span = Span(1, Second) scaledBy 60
val span = Span(1, Second).scaledBy(60)
assert(span === Span(1, Minute))
assert(span.toString === "Span(1, Minute)")
assert(span.prettyString === "1 minute")
}
{
val span = Span(100, Minutes) scaledBy 0.01
val span = Span(100, Minutes).scaledBy(0.01)
assert(span === Span(1, Minute))
assert(span.toString === "Span(1, Minute)")
assert(span.prettyString === "1 minute")
}
{
val span = Span(10, Minutes) scaledBy 5
val span = Span(10, Minutes).scaledBy(5)
assert(span === Span(50, Minutes))
assert(span.toString === "Span(50, Minutes)")
assert(span.prettyString === "50 minutes")
}
{
val span = Span(3, Minutes) scaledBy 0.5
val span = Span(3, Minutes).scaledBy(0.5)
assert(span === Span(1.5, Minutes))
assert(span.toString === "Span(1.5, Minutes)")
assert(span.prettyString === "1.5 minutes")
}
{
val span = Span(1, Minute) scaledBy 59
val span = Span(1, Minute).scaledBy(59)
assert(span === Span(59, Minutes))
assert(span.toString === "Span(59, Minutes)")
assert(span.prettyString === "59 minutes")
}
}
it("should have hour units if > 1 and < 24 hours") {
{
val span = Span(1, Minute) scaledBy 60
val span = Span(1, Minute).scaledBy(60)
assert(span === Span(1, Hour))
assert(span.toString === "Span(1, Hour)")
assert(span.prettyString === "1 hour")
}
{
val span = Span(100, Hours) scaledBy 0.01
val span = Span(100, Hours).scaledBy(0.01)
assert(span === Span(1, Hour))
assert(span.toString === "Span(1, Hour)")
assert(span.prettyString === "1 hour")
}
{
val span = Span(3, Hours) scaledBy 4
val span = Span(3, Hours).scaledBy(4)
assert(span === Span(12, Hours))
assert(span.toString === "Span(12, Hours)")
assert(span.prettyString === "12 hours")
}
{
val span = Span(3, Hours) scaledBy 0.5
val span = Span(3, Hours).scaledBy(0.5)
assert(span === Span(1.5, Hours))
assert(span.toString === "Span(1.5, Hours)")
assert(span.prettyString === "1.5 hours")
}
{
val span = Span(1, Hours) scaledBy 23
val span = Span(1, Hours).scaledBy(23)
assert(span === Span(23, Hours))
assert(span.toString === "Span(23, Hours)")
assert(span.prettyString === "23 hours")
}
}
it("should have day units if > 1 and < ? days") {
{
val span = Span(1, Hour) scaledBy 24
val span = Span(1, Hour).scaledBy(24)
assert(span === Span(1, Day))
assert(span.toString === "Span(1, Day)")
assert(span.prettyString === "1 day")
}
{
val span = Span(100, Days) scaledBy 0.01
val span = Span(100, Days).scaledBy(0.01)
assert(span === Span(1, Day))
assert(span.toString === "Span(1, Day)")
assert(span.prettyString === "1 day")
}
{
val span = Span(3, Days) scaledBy 4
val span = Span(3, Days).scaledBy(4)
assert(span === Span(12, Days))
assert(span.toString === "Span(12, Days)")
assert(span.prettyString === "12 days")
}
{
val span = Span(3, Days) scaledBy 0.5
val span = Span(3, Days).scaledBy(0.5)
assert(span === Span(1.5, Days))
assert(span.toString === "Span(1.5, Days)")
assert(span.prettyString === "1.5 days")
}
{
val span = Span(53376, Days) scaledBy 2
val span = Span(53376, Days).scaledBy(2)
assert(span === Span(106751.99116730063, Days))
assert(span.toString === "Span(106751.99116730063, Days)")
assert(span.prettyString === "106751.99116730063 days")
Expand Down

0 comments on commit 59d0774

Please sign in to comment.