-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
890e3ed
commit 63a3823
Showing
5 changed files
with
65 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package lila.fishnet | ||
|
||
import cats.effect.IO | ||
import cats.effect.kernel.{ Ref, Resource } | ||
import cats.effect.testkit.TestControl | ||
import java.time.Instant | ||
import org.typelevel.log4cats.Logger | ||
import org.typelevel.log4cats.noop.NoOpLogger | ||
import weaver.* | ||
|
||
import scala.concurrent.duration.* | ||
|
||
object CleaningJobTest extends SimpleIOSuite: | ||
|
||
given Logger[IO] = NoOpLogger[IO] | ||
|
||
val times = (60 - 5) / 3 + 1 | ||
test(s"cleaning run $times times in 1 minute"): | ||
val res = for | ||
ref <- Resource.eval(Ref.of[IO, Int](0)) | ||
executor = createExcutor(ref) | ||
_ <- WorkCleaningJob(executor).run().background | ||
_ <- Resource.eval(IO.sleep(1.minute)) | ||
count <- Resource.eval(ref.get) | ||
yield count | ||
val program = res.use(count => IO(expect.same(count, times))) | ||
TestControl.executeEmbed(program) | ||
|
||
def createExcutor(ref: Ref[IO, Int]): Executor = | ||
new Executor: | ||
def acquire(accquire: ClientKey) = IO.none | ||
def move(workId: WorkId, fishnetKey: ClientKey, move: BestMove) = IO.unit | ||
def add(work: Lila.Request) = IO.unit | ||
def clean(before: Instant) = ref.update(_ + 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package lila.fishnet | ||
|
||
import cats.effect.IO | ||
|
||
object Helper: | ||
|
||
val noopMonitor: Monitor = | ||
new Monitor: | ||
def success(work: Work.Move): IO[Unit] = IO.unit | ||
def failure(work: Work.Move, clientKey: ClientKey, e: Exception): IO[Unit] = IO.unit | ||
def notFound(id: WorkId, clientKey: ClientKey): IO[Unit] = IO.unit | ||
def notAcquired(work: Work.Move, clientKey: ClientKey): IO[Unit] = IO.unit | ||
def updateSize(map: Map[WorkId, Work.Move]): IO[Unit] = IO.unit | ||
|
||
val noopLilaClient: LilaClient = | ||
new LilaClient: | ||
def send(move: Lila.Move): IO[Unit] = IO.unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters