Ϫf dZddlZddlZddlmZ ddlZdZddlm Z ddl m Z m Z Gdd Z e je Gd d e ZGd d e Zy#e$rdZYJwxYw)z) Tests for L{twisted.python.threadable}. N)skipIfFT) threadable)FailTestSynchronousTestCasec eZdZdgZdZdZdZy) TestObjectaMethodctdD]g}|j|jc|_|_|j|jz|_|jdk(rTJd|jfzy)N rzz == %d, not 0 as expected)rangeyxz)selfis >/usr/lib/python3/dist-packages/twisted/test/test_threadable.pyr zTestObject.aMethodsbr IA!VVTVVNDFDFVVdff_DF66Q; H <y H H; IN)__name__ __module__ __qualname__ synchronizedrrr rrrrs;L A AIrrcZeZdZdZdZeeddZeeddZdZ y)SynchronizationTestsc|jtjtjtjdy)z Reduce the CPython check interval so that thread switches happen much more often, hopefully exercising more possible race conditions. Also, delay actual test startup until the reactor has been started. gHz>N) addCleanupsyssetswitchintervalgetswitchintervalrs rsetUpzSynchronizationTests.setUp)s/ --s/D/D/FG i(rcX|jdtjjy)zk The name of a synchronized method is inaffected by the synchronization decorator. r N) assertEqualrr rr"s rtest_synchronizedNamez*SynchronizationTests.test_synchronizedName2s J$6$6$?$?@r!Platform does not support threadsctjgtjfd}|j |j |j dd|jtjdy)z L{threadable.isInIOThread} returns C{True} if and only if it is called in the same thread as L{threadable.registerAsIOThread}. cJjtjSN)appendr isInIOThread) foreignResultsrz8SynchronizationTests.test_isInIOThread..Bs=// 0G0G0IJrtargetrz#Non-IO thread reported as IO threadz#IO thread reported as not IO threadN) rregisterAsIOThread threadingThreadstartjoin assertFalse assertTruer,)rtr-s @rtest_isInIOThreadz&SynchronizationTests.test_isInIOThread9sn %%'   J     q)+PQ   # # %'L rctgfd}g}tdD]9}tj|}|j ||j ;|D]}|j r ty)Nc tdD]}jy#t$r$}jt |Yd}~yd}~wwxYwNi)rr AssertionErrorr+str)reerrorsos rcallMethodLotszHSynchronizationTests.testThreadedSynchronization..callMethodLotsQsG &t AIIK ! & c!f%% &s $ AA  Ar/)rrr2r3r+r4r5r)rrBthreadsrr8r@rAs @@rtestThreadedSynchronizationz0SynchronizationTests.testThreadedSynchronizationKs L &q A  7A NN1  GGI   A FFH  6" " rcXt}tdD]}|jyr<)rrr )rrArs rtestUnthreadedSynchronizationz2SynchronizationTests.testUnthreadedSynchronizationds% Lt A IIK rN) rrrr#r&r threadingSkipr9rErGrrrrr(sL)A M>? @ " M>?#@#0rrc0eZdZeeddZdZy)SerializationTestsr'ctj}t|}tj|}tj |}|j ||yr*)rXLocktypepickledumpsloadsassertIsInstance)rlocklockType lockPicklenewLocks r testPicklingzSerializationTests.testPicklingksE!:\\$' ,,z* gx0rcd}tj|}tj|d}tj|y)Ns6ctwisted.python.threadable unpickle_lock p0 (tp1 Rp2 .)rNrPrO)rrTrR newPickles rtestUnpicklingz!SerializationTests.testUnpicklingss1S ||J'LLq)  YrN)rrrrrHrVrZrrrrJrJjs" M>?1@1 rrJ)__doc__rNrunittestrr2rH ImportErrortwisted.pythonrtwisted.trial.unittestrrr synchronizerrJrrrrasz  M%@ I I z"?.?D  ,  wMsAA#"A#