Skip to content

Commit

Permalink
Add test to make sure clearIfFull works
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed Dec 1, 2023
1 parent 7694799 commit d743d32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions app/src/main/scala/Executor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ trait Executor:

object Executor:

// val maxSize = 300
type State = Map[WorkId, Work.Move]

case class Config(maxSize: Int)
Expand Down Expand Up @@ -98,7 +97,7 @@ object Executor:
.flatMap(monitor.updateSize)

def clearIfFull(coll: State): (State, IO[Unit]) =
if coll.size > confg.maxSize then
if coll.size >= confg.maxSize then
Map.empty -> Logger[IO].warn(
s"MoveDB collection is full! maxSize=${confg.maxSize}. Dropping all now!"
)
Expand Down
11 changes: 11 additions & 0 deletions app/src/test/scala/ExecutorTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ object ExecutorTest extends SimpleIOSuite:
acquired <- executor.acquire(key)
yield assert(acquired.isEmpty)

test("if moves reach max size it should clear all moves"):
for
executor <- createExecutor(Executor.Config(3))
_ <- executor.add(request)
_ <- executor.add(request.copy(id = GameId("2")))
_ <- executor.add(request.copy(id = GameId("3")))
_ <- executor.add(request.copy(id = GameId("4")))
acquired <- executor.acquire(key)
empty <- executor.acquire(ClientKey("key2"))
yield assert(acquired.isDefined && empty.isEmpty)

def createExecutor(config: Executor.Config = Executor.Config(300)): IO[Executor] =
createLilaClient.flatMap(Executor.instance(_, noopMonitor, config))

Expand Down

0 comments on commit d743d32

Please sign in to comment.