Module: Synctest::Patches
- Defined in:
- lib/synctest/patches.rb
Overview
Process-wide shims which dispatch to a thread-local bubble. Outside a bubble, every method immediately delegates to Ruby's original behavior.
Defined Under Namespace
Modules: ConditionVariablePatch, FiberSingletonPatch, KernelPatch, KernelSingletonPatch, MonitorPatch, MutexPatch, ProcessSingletonPatch, QueuePatch, SizedQueuePatch, ThreadPatch, ThreadSingletonPatch, TimeSingletonPatch, TimeoutPatch
Class Method Summary collapse
Class Method Details
.install! ⇒ Object
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
# File 'lib/synctest/patches.rb', line 572 def install! return if @installed Kernel.prepend(KernelPatch) Kernel.singleton_class.prepend(KernelSingletonPatch) Time.singleton_class.prepend(TimeSingletonPatch) Process.singleton_class.prepend(ProcessSingletonPatch) Thread.singleton_class.prepend(ThreadSingletonPatch) Thread.prepend(ThreadPatch) Mutex.prepend(MutexPatch) ConditionVariable.prepend(ConditionVariablePatch) Monitor.prepend(MonitorPatch) Queue.prepend(QueuePatch) SizedQueue.prepend(SizedQueuePatch) Fiber.singleton_class.prepend(FiberSingletonPatch) Timeout.singleton_class.prepend(TimeoutPatch) Timeout.prepend(TimeoutPatch) @installed = true end |
.run_timeout_timer(seconds, exception, message) ⇒ Object
593 594 595 596 597 598 599 600 601 602 603 604 605 |
# File 'lib/synctest/patches.rb', line 593 def run_timeout_timer(seconds, exception, ) target = Thread.current timer = Thread.new do sleep(seconds) target.raise(exception, ) end yield(seconds) ensure if timer timer.kill if timer.alive? timer.join end end |