He-Pin commented on code in PR #3668:
URL: https://github.com/apache/pekko/pull/3668#discussion_r4357192242
##########
actor-tests/src/test/scala/org/apache/pekko/dispatch/MailboxTaskSubmissionSpec.scala:
##########
@@ -75,6 +75,51 @@ class MailboxTaskSubmissionSpec extends PekkoSpec {
}
}
+ "PekkoForkJoinTask" must {
+
+ "preserve the Runnable hash code across fresh wrappers" in {
+ for (hash <- Seq(Int.MinValue, -1, 0, 1, Int.MaxValue)) {
+ val runnable = new Runnable {
+ final override def run(): Unit = ()
+ final override def hashCode(): Int = hash
+ }
+ val first = new PekkoForkJoinTask(runnable)
+ val second = new PekkoForkJoinTask(runnable)
+
+ withClue(s"Runnable hash code $hash: ") {
+ first.hashCode() shouldBe hash
+ second.hashCode() shouldBe hash
+ (first should not).equal(second)
+ }
+ }
+ }
+
+ "retain independent completion and cancellation for wrappers with the same
hash code" in {
+ val runs = new AtomicInteger(0)
+ val runnable = new Runnable {
+ final override def run(): Unit = { runs.incrementAndGet() }
+ final override def hashCode(): Int = 42
+ }
+ val cancelled = new PekkoForkJoinTask(runnable)
+ val completed = new PekkoForkJoinTask(runnable)
+ val pending = new PekkoForkJoinTask(runnable)
+
+ cancelled.cancel(false) shouldBe true
+ completed.invoke()
+
+ cancelled.isCancelled shouldBe true
+ completed.isCompletedNormally shouldBe true
+ pending.isDone shouldBe false
+ runs.get() shouldBe 1
+ Set(cancelled, completed, pending).size shouldBe 3
Review Comment:
Optional test improvement: this three-element `Set(...)` is represented by
Scala's specialized `Set3`, whose membership checks compare equality without
using hash buckets. An explicit `immutable.HashSet.empty[PekkoForkJoinTask] ++
Seq(cancelled, completed, pending)` (or `java.util.HashSet`) would also verify
that distinct wrappers remain distinct when all three deliberately collide on
hash code 42. The implementation passes that check in an isolated probe; this
is coverage strengthening, not a blocker.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]