From bc0c6f5612a2438d2600f85074e7663ec3d56cd6 Mon Sep 17 00:00:00 2001 From: Keith Pinson Date: Thu, 1 Jul 2021 20:43:15 -0400 Subject: [PATCH] fix: get tests green by brute force sleeps :/ As recommended by @christopherdavenport --- .../mules/AutoMemoryCacheSpec.scala | 22 ++++++++--------- .../mules/MemoryCacheSpec.scala | 24 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/modules/core/src/test/scala/io/chrisdavenport/mules/AutoMemoryCacheSpec.scala b/modules/core/src/test/scala/io/chrisdavenport/mules/AutoMemoryCacheSpec.scala index cfec76a..cea53e2 100644 --- a/modules/core/src/test/scala/io/chrisdavenport/mules/AutoMemoryCacheSpec.scala +++ b/modules/core/src/test/scala/io/chrisdavenport/mules/AutoMemoryCacheSpec.scala @@ -7,7 +7,7 @@ import munit._ import scala.concurrent.duration._ class AutoMemoryCacheSpec extends CatsEffectSuite { - val cacheKeyExpiration = TimeSpec.unsafeFromDuration(12.hours) + val cacheKeyExpiration = TimeSpec.unsafeFromDuration(1200.millis) val checkExpirationsEvery = TimeSpec.unsafeFromDuration(10.millis) test("Auto MemoryCache.ofSingleImmutableMap should expire keys") { @@ -16,11 +16,11 @@ class AutoMemoryCacheSpec extends CatsEffectSuite { .use(cache => for { _ <- cache.insert(1, "foo") - //_ <- IO(ctx.tick(5.hours)) + _ <- IO.sleep(500.millis) _ <- cache.insert(2, "bar") a1 <- cache.lookupNoUpdate(1) b1 <- cache.lookupNoUpdate(2) - //_ <- IO(ctx.tick(7.hours + 1.second)) // expiration time reached + _ <- IO.sleep(700.millis + 100.millis) // expiration time reached a2 <- cache.lookupNoUpdate(1) b2 <- cache.lookupNoUpdate(2) } yield { @@ -38,12 +38,12 @@ class AutoMemoryCacheSpec extends CatsEffectSuite { .use(cache => for { _ <- cache.insert(1, "foo") - //_ <- IO(ctx.tick(5.hours)) + _ <- IO.sleep(500.millis) a1 <- cache.lookupNoUpdate(1) _ <- cache.insert(1, "bar") - //_ <- IO(ctx.tick(7.hours + 1.second)) // expiration time reached for first timestamp + _ <- IO.sleep(700.millis + 100.millis) // expiration time reached for first timestamp a2 <- cache.lookupNoUpdate(1) - //_ <- IO(ctx.tick(5.hours)) // expiration time reached for last timestamp + _ <- IO.sleep(500.millis) // expiration time reached for last timestamp a3 <- cache.lookupNoUpdate(1) } yield { assert(a1.contains("foo")) @@ -58,11 +58,11 @@ class AutoMemoryCacheSpec extends CatsEffectSuite { .use(cache => for { _ <- cache.insert(1, "foo") - //_ <- IO(ctx.tick(5.hours)) + _ <- IO.sleep(500.millis) _ <- cache.insert(2, "bar") a1 <- cache.lookupNoUpdate(1) b1 <- cache.lookupNoUpdate(2) - //_ <- IO(ctx.tick(7.hours + 1.second)) // expiration time reached + _ <- IO.sleep(700.millis + 100.millis) // expiration time reached a2 <- cache.lookupNoUpdate(1) b2 <- cache.lookupNoUpdate(2) } yield { @@ -80,12 +80,12 @@ class AutoMemoryCacheSpec extends CatsEffectSuite { .use(cache => for { _ <- cache.insert(1, "foo") - //_ <- IO(ctx.tick(5.hours)) + _ <- IO.sleep(500.millis) a1 <- cache.lookupNoUpdate(1) _ <- cache.insert(1, "bar") - //_ <- IO(ctx.tick(7.hours + 1.second)) // expiration time reached for first timestamp + _ <- IO.sleep(700.millis + 100.millis) // expiration time reached for first timestamp a2 <- cache.lookupNoUpdate(1) - //_ <- IO(ctx.tick(5.hours)) // expiration time reached for last timestamp + _ <- IO.sleep(500.millis) // expiration time reached for last timestamp a3 <- cache.lookupNoUpdate(1) } yield { assert(a1.contains("foo")) diff --git a/modules/core/src/test/scala/io/chrisdavenport/mules/MemoryCacheSpec.scala b/modules/core/src/test/scala/io/chrisdavenport/mules/MemoryCacheSpec.scala index 7b71bb5..9bb32f4 100644 --- a/modules/core/src/test/scala/io/chrisdavenport/mules/MemoryCacheSpec.scala +++ b/modules/core/src/test/scala/io/chrisdavenport/mules/MemoryCacheSpec.scala @@ -9,7 +9,7 @@ class MemoryCacheSpec extends CatsEffectSuite { for { cache <- MemoryCache.ofSingleImmutableMap[IO, String, Int](Some(TimeSpec.unsafeFromDuration(1.second)))(Async[IO]) _ <- cache.insert("Foo", 1) - //_ = ctx.tick(1.nano) + _ <- IO.sleep(1.nano) value <- cache.lookup("Foo") } yield { assertEquals(value, Some(1)) @@ -31,7 +31,7 @@ class MemoryCacheSpec extends CatsEffectSuite { for { cache <- MemoryCache.ofSingleImmutableMap[IO, String, Int](Some(TimeSpec.unsafeFromDuration(1.second)))(Async[IO]) _ <- cache.insert("Foo", 1) - //_ <- Sync[IO].delay(ctx.tick(2.seconds)) + _ <- IO.sleep(2.seconds) _ <- cache.purgeExpired value <- cache.lookupNoUpdate("Foo") } yield { @@ -43,7 +43,7 @@ class MemoryCacheSpec extends CatsEffectSuite { for { cache <- MemoryCache.ofSingleImmutableMap[IO, String, Int](Some(TimeSpec.unsafeFromDuration(1.second)))(Async[IO]) _ <- cache.insert("Foo", 1) - //_ <- Sync[IO].delay(ctx.tick(2.seconds)) + _ <- IO.sleep(2.seconds) value <- cache.lookup("Foo") } yield { assertEquals(value, None) @@ -56,7 +56,7 @@ class MemoryCacheSpec extends CatsEffectSuite { iCache <- MemoryCache.ofSingleImmutableMap[IO, String, Int](Some(TimeSpec.unsafeFromDuration(1.second)))(Async[IO]) cache = iCache.setOnDelete(_ => checkWasTouched.set(true)) _ <- cache.insert("Foo", 1) - //_ <- Sync[IO].delay(ctx.tick(2.seconds)) + _ <- IO.sleep(2.seconds) value <- cache.lookupNoUpdate("Foo") wasTouched <- checkWasTouched.get } yield { @@ -69,7 +69,7 @@ class MemoryCacheSpec extends CatsEffectSuite { for { cache <- MemoryCache.ofShardedImmutableMap[IO, String, Int](10, Some(TimeSpec.unsafeFromDuration(1.second)))(Async[IO]) _ <- cache.insert("Foo", 1) - //_ = ctx.tick(1.nano) + _ <- IO.sleep(1.nano) value <- cache.lookup("Foo") } yield { assertEquals(value, Some(1)) @@ -91,7 +91,7 @@ class MemoryCacheSpec extends CatsEffectSuite { for { cache <- MemoryCache.ofShardedImmutableMap[IO, String, Int](10, Some(TimeSpec.unsafeFromDuration(1.second)))(Async[IO]) _ <- cache.insert("Foo", 1) - //_ <- Sync[IO].delay(ctx.tick(2.seconds)) + _ <- IO.sleep(2.seconds) _ <- cache.purgeExpired value <- cache.lookupNoUpdate("Foo") } yield { @@ -103,7 +103,7 @@ class MemoryCacheSpec extends CatsEffectSuite { for { cache <- MemoryCache.ofShardedImmutableMap[IO, String, Int](10, Some(TimeSpec.unsafeFromDuration(1.second)))(Async[IO]) _ <- cache.insert("Foo", 1) - //_ <- Sync[IO].delay(ctx.tick(2.seconds)) + _ <- IO.sleep(2.seconds) value <- cache.lookup("Foo") } yield { assertEquals(value, None) @@ -116,7 +116,7 @@ class MemoryCacheSpec extends CatsEffectSuite { iCache <- MemoryCache.ofShardedImmutableMap[IO, String, Int](10, Some(TimeSpec.unsafeFromDuration(1.second)))(Async[IO]) cache = iCache.setOnDelete(_ => checkWasTouched.set(true)) _ <- cache.insert("Foo", 1) - //_ <- Sync[IO].delay(ctx.tick(2.seconds)) + _ <- IO.sleep(2.seconds) value <- cache.lookupNoUpdate("Foo") wasTouched <- checkWasTouched.get } yield { @@ -129,7 +129,7 @@ class MemoryCacheSpec extends CatsEffectSuite { for { cache <- MemoryCache.ofConcurrentHashMap[IO, String, Int](Some(TimeSpec.unsafeFromDuration(1.second)))(Async[IO]) _ <- cache.insert("Foo", 1) - //_ = ctx.tick(1.nano) + _ <- IO.sleep(1.nano) value <- cache.lookup("Foo") } yield { assertEquals(value, Some(1)) @@ -151,7 +151,7 @@ class MemoryCacheSpec extends CatsEffectSuite { for { cache <- MemoryCache.ofConcurrentHashMap[IO, String, Int](Some(TimeSpec.unsafeFromDuration(1.second)))(Async[IO]) _ <- cache.insert("Foo", 1) - //_ <- Sync[IO].delay(ctx.tick(2.seconds)) + _ <- IO.sleep(2.seconds) _ <- cache.purgeExpired value <- cache.lookupNoUpdate("Foo") } yield { @@ -163,7 +163,7 @@ class MemoryCacheSpec extends CatsEffectSuite { for { cache <- MemoryCache.ofConcurrentHashMap[IO, String, Int](Some(TimeSpec.unsafeFromDuration(1.second)))(Async[IO]) _ <- cache.insert("Foo", 1) - //_ <- Sync[IO].delay(ctx.tick(2.seconds)) + _ <- IO.sleep(2.seconds) value <- cache.lookup("Foo") } yield { assertEquals(value, None) @@ -176,7 +176,7 @@ class MemoryCacheSpec extends CatsEffectSuite { iCache <- MemoryCache.ofConcurrentHashMap[IO, String, Int](Some(TimeSpec.unsafeFromDuration(1.second)))(Async[IO]) cache = iCache.setOnDelete(_ => checkWasTouched.set(true)) _ <- cache.insert("Foo", 1) - //_ <- Sync[IO].delay(ctx.tick(2.seconds)) + _ <- IO.sleep(2.seconds) value <- cache.lookupNoUpdate("Foo") wasTouched <- checkWasTouched.get } yield {