Skip to content

Commit

Permalink
fix: get tests green by brute force sleeps :/
Browse files Browse the repository at this point in the history
As recommended by @ChristopherDavenport
  • Loading branch information
Keith Pinson committed Jul 2, 2021
1 parent 1036248 commit bc0c6f5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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 {
Expand All @@ -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"))
Expand All @@ -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 {
Expand All @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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))
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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))
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit bc0c6f5

Please sign in to comment.