diff --git a/core/native/src/main/scala/cats/effect/unsafe/EpollSystem.scala b/core/native/src/main/scala/cats/effect/unsafe/EpollSystem.scala index 9874edb58e..1f1e62cf06 100644 --- a/core/native/src/main/scala/cats/effect/unsafe/EpollSystem.scala +++ b/core/native/src/main/scala/cats/effect/unsafe/EpollSystem.scala @@ -62,6 +62,9 @@ object EpollSystem extends PollingSystem { def poll(poller: Poller, nanos: Long, reportFailure: Throwable => Unit): Boolean = poller.poll(nanos) + def steal(poller: Poller, reportFailure: Throwable => Unit): Boolean = + poller.steal() + def needsPoll(poller: Poller): Boolean = poller.needsPoll() def interrupt(targetThread: Thread, targetPoller: Poller): Unit = () @@ -219,6 +222,8 @@ object EpollSystem extends PollingSystem { polled } + private[EpollSystem] def steal(): Boolean = poll(0) + private[EpollSystem] def needsPoll(): Boolean = !handles.isEmpty() private[EpollSystem] def register( diff --git a/tests/jvm-native/src/test/scala/cats/effect/unsafe/PollingSystemSpec.scala b/tests/jvm-native/src/test/scala/cats/effect/unsafe/PollingSystemSpec.scala new file mode 100644 index 0000000000..c515b1a5e4 --- /dev/null +++ b/tests/jvm-native/src/test/scala/cats/effect/unsafe/PollingSystemSpec.scala @@ -0,0 +1,36 @@ +/* + * Copyright 2020-2024 Typelevel + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cats.effect +package unsafe + +trait PollingSystemSpec extends BaseSpec { + + def system: IO[PollingSystem] + + "Polling System" should { + "not blocker stealer when owner is polling" in real { + system.flatMap { s => + IO(s.makePoller()).flatMap { p => + IO.interruptible(s.poll(p, -1, _ => ())).background.surround { + IO(s.steal(p, _ => ()) should beFalse) + } + } + } + } + } + +} diff --git a/tests/jvm/src/test/scala/cats/effect/unsafe/SelectorSystemSpec.scala b/tests/jvm/src/test/scala/cats/effect/unsafe/SelectorSystemSpec.scala index 70c0906a14..5e8f8d43d0 100644 --- a/tests/jvm/src/test/scala/cats/effect/unsafe/SelectorSystemSpec.scala +++ b/tests/jvm/src/test/scala/cats/effect/unsafe/SelectorSystemSpec.scala @@ -17,18 +17,8 @@ package cats.effect package unsafe -class SelectorSystemSpec extends BaseSpec { +class SelectorSystemSpec extends PollingSystemSpec { - "SelectorSystem" should { - "not blocker stealer when owner is polling" in real { - IO(SelectorSystem()).flatMap { s => - IO(s.makePoller()).flatMap { p => - IO.interruptible(s.poll(p, -1, _ => ())).background.surround { - IO(s.steal(p, _ => ()) should beFalse) - } - } - } - } - } + def system = IO(SelectorSystem()) } diff --git a/tests/native/src/test/scala/cats/effect/unsafe/SelectorSystemSpec.scala b/tests/native/src/test/scala/cats/effect/unsafe/SelectorSystemSpec.scala new file mode 100644 index 0000000000..de7e1c6861 --- /dev/null +++ b/tests/native/src/test/scala/cats/effect/unsafe/SelectorSystemSpec.scala @@ -0,0 +1,24 @@ +/* + * Copyright 2020-2024 Typelevel + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cats.effect +package unsafe + +class SelectorSystemSpec extends PollingSystemSpec { + + def system = IO(FileDescriptorPoller) + +}