Changeset 65500de in trunk
- Timestamp:
- 2020-07-24T18:13:28Z (5 years ago)
- Branches:
- master
- Children:
- 7d0f773
- Parents:
- 8bcd6dd (diff), 383c564 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified misc/python3/ratchet-passing ¶
r8bcd6dd r65500de 53 53 allmydata.test.test_observer.Observer.test_oneshot 54 54 allmydata.test.test_observer.Observer.test_oneshot_fireagain 55 allmydata.test.test_pipeline.Pipeline.test_basic 56 allmydata.test.test_pipeline.Pipeline.test_errors 57 allmydata.test.test_pipeline.Pipeline.test_errors2 55 58 allmydata.test.test_python3.Python3PortingEffortTests.test_finished_porting 56 59 allmydata.test.test_python3.Python3PortingEffortTests.test_ported_modules_distinct -
TabularUnified src/allmydata/test/test_observer.py ¶
r8bcd6dd r65500de 1 """ 2 Tests for allmydata.util.observer. 3 4 Ported to Python 3. 5 """ 6 7 from __future__ import absolute_import 8 from __future__ import division 9 from __future__ import print_function 10 from __future__ import unicode_literals 11 12 from future.utils import PY2 13 if PY2: 14 from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, int, list, object, range, str, max, min # noqa: F401 1 15 2 16 from twisted.trial import unittest -
TabularUnified src/allmydata/test/test_util.py ¶
r8bcd6dd r65500de 6 6 import os, time, sys 7 7 import yaml 8 import gc # support PyPy9 8 10 9 from six.moves import StringIO … … 12 11 from twisted.internet import defer, reactor 13 12 from twisted.python.failure import Failure 14 from twisted.python import log15 13 16 14 from allmydata.util import idlib, mathutil 17 15 from allmydata.util import fileutil 18 16 from allmydata.util import limiter, pollmixin 19 from allmydata.util import statistics, dictutil, pipeline,yamlutil17 from allmydata.util import statistics, dictutil, yamlutil 20 18 from allmydata.util import log as tahoe_log 21 19 from allmydata.util.spans import Spans, overlap, DataSpans … … 752 750 self.failUnlessEqual(d.get_aux("one"), None) 753 751 754 class Pipeline(unittest.TestCase):755 def pause(self, *args, **kwargs):756 d = defer.Deferred()757 self.calls.append( (d, args, kwargs) )758 return d759 760 def failUnlessCallsAre(self, expected):761 #print self.calls762 #print expected763 self.failUnlessEqual(len(self.calls), len(expected), self.calls)764 for i,c in enumerate(self.calls):765 self.failUnlessEqual(c[1:], expected[i], str(i))766 767 def test_basic(self):768 self.calls = []769 finished = []770 p = pipeline.Pipeline(100)771 772 d = p.flush() # fires immediately773 d.addCallbacks(finished.append, log.err)774 self.failUnlessEqual(len(finished), 1)775 finished = []776 777 d = p.add(10, self.pause, "one")778 # the call should start right away, and our return Deferred should779 # fire right away780 d.addCallbacks(finished.append, log.err)781 self.failUnlessEqual(len(finished), 1)782 self.failUnlessEqual(finished[0], None)783 self.failUnlessCallsAre([ ( ("one",) , {} ) ])784 self.failUnlessEqual(p.gauge, 10)785 786 # pipeline: [one]787 788 finished = []789 d = p.add(20, self.pause, "two", kw=2)790 # pipeline: [one, two]791 792 # the call and the Deferred should fire right away793 d.addCallbacks(finished.append, log.err)794 self.failUnlessEqual(len(finished), 1)795 self.failUnlessEqual(finished[0], None)796 self.failUnlessCallsAre([ ( ("one",) , {} ),797 ( ("two",) , {"kw": 2} ),798 ])799 self.failUnlessEqual(p.gauge, 30)800 801 self.calls[0][0].callback("one-result")802 # pipeline: [two]803 self.failUnlessEqual(p.gauge, 20)804 805 finished = []806 d = p.add(90, self.pause, "three", "posarg1")807 # pipeline: [two, three]808 flushed = []809 fd = p.flush()810 fd.addCallbacks(flushed.append, log.err)811 self.failUnlessEqual(flushed, [])812 813 # the call will be made right away, but the return Deferred will not,814 # because the pipeline is now full.815 d.addCallbacks(finished.append, log.err)816 self.failUnlessEqual(len(finished), 0)817 self.failUnlessCallsAre([ ( ("one",) , {} ),818 ( ("two",) , {"kw": 2} ),819 ( ("three", "posarg1"), {} ),820 ])821 self.failUnlessEqual(p.gauge, 110)822 823 self.failUnlessRaises(pipeline.SingleFileError, p.add, 10, self.pause)824 825 # retiring either call will unblock the pipeline, causing the #3826 # Deferred to fire827 self.calls[2][0].callback("three-result")828 # pipeline: [two]829 830 self.failUnlessEqual(len(finished), 1)831 self.failUnlessEqual(finished[0], None)832 self.failUnlessEqual(flushed, [])833 834 # retiring call#2 will finally allow the flush() Deferred to fire835 self.calls[1][0].callback("two-result")836 self.failUnlessEqual(len(flushed), 1)837 838 def test_errors(self):839 self.calls = []840 p = pipeline.Pipeline(100)841 842 d1 = p.add(200, self.pause, "one")843 d2 = p.flush()844 845 finished = []846 d1.addBoth(finished.append)847 self.failUnlessEqual(finished, [])848 849 flushed = []850 d2.addBoth(flushed.append)851 self.failUnlessEqual(flushed, [])852 853 self.calls[0][0].errback(ValueError("oops"))854 855 self.failUnlessEqual(len(finished), 1)856 f = finished[0]857 self.failUnless(isinstance(f, Failure))858 self.failUnless(f.check(pipeline.PipelineError))859 self.failUnlessIn("PipelineError", str(f.value))860 self.failUnlessIn("ValueError", str(f.value))861 r = repr(f.value)862 self.failUnless("ValueError" in r, r)863 f2 = f.value.error864 self.failUnless(f2.check(ValueError))865 866 self.failUnlessEqual(len(flushed), 1)867 f = flushed[0]868 self.failUnless(isinstance(f, Failure))869 self.failUnless(f.check(pipeline.PipelineError))870 f2 = f.value.error871 self.failUnless(f2.check(ValueError))872 873 # now that the pipeline is in the failed state, any new calls will874 # fail immediately875 876 d3 = p.add(20, self.pause, "two")877 878 finished = []879 d3.addBoth(finished.append)880 self.failUnlessEqual(len(finished), 1)881 f = finished[0]882 self.failUnless(isinstance(f, Failure))883 self.failUnless(f.check(pipeline.PipelineError))884 r = repr(f.value)885 self.failUnless("ValueError" in r, r)886 f2 = f.value.error887 self.failUnless(f2.check(ValueError))888 889 d4 = p.flush()890 flushed = []891 d4.addBoth(flushed.append)892 self.failUnlessEqual(len(flushed), 1)893 f = flushed[0]894 self.failUnless(isinstance(f, Failure))895 self.failUnless(f.check(pipeline.PipelineError))896 f2 = f.value.error897 self.failUnless(f2.check(ValueError))898 899 def test_errors2(self):900 self.calls = []901 p = pipeline.Pipeline(100)902 903 d1 = p.add(10, self.pause, "one")904 d2 = p.add(20, self.pause, "two")905 d3 = p.add(30, self.pause, "three")906 d4 = p.flush()907 908 # one call fails, then the second one succeeds: make sure909 # ExpandableDeferredList tolerates the second one910 911 flushed = []912 d4.addBoth(flushed.append)913 self.failUnlessEqual(flushed, [])914 915 self.calls[0][0].errback(ValueError("oops"))916 self.failUnlessEqual(len(flushed), 1)917 f = flushed[0]918 self.failUnless(isinstance(f, Failure))919 self.failUnless(f.check(pipeline.PipelineError))920 f2 = f.value.error921 self.failUnless(f2.check(ValueError))922 923 self.calls[1][0].callback("two-result")924 self.calls[2][0].errback(ValueError("three-error"))925 926 del d1,d2,d3,d4927 gc.collect() # for PyPy928 752 929 753 class SampleError(Exception): -
TabularUnified src/allmydata/util/_python3.py ¶
r8bcd6dd r65500de 27 27 "allmydata.util.namespace", 28 28 "allmydata.util.netstring", 29 "allmydata.util.observer", 30 "allmydata.util.pipeline", 29 31 "allmydata.util.pollmixin", 30 32 "allmydata.util._python3", … … 42 44 "allmydata.test.test_humanreadable", 43 45 "allmydata.test.test_netstring", 46 "allmydata.test.test_observer", 47 "allmydata.test.test_pipeline", 44 48 "allmydata.test.test_python3", 45 49 "allmydata.test.test_time_format", -
TabularUnified src/allmydata/util/observer.py ¶
r8bcd6dd r65500de 1 # -*- test-case-name: allmydata.test.test_observer -*- 1 """ 2 Observer for Twisted code. 3 4 Ported to Python 3. 5 """ 6 7 from __future__ import absolute_import 8 from __future__ import division 9 from __future__ import print_function 10 from __future__ import unicode_literals 11 12 from future.utils import PY2 13 if PY2: 14 from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, int, list, object, range, str, max, min # noqa: F401 2 15 3 16 import weakref -
TabularUnified src/allmydata/util/pipeline.py ¶
r8bcd6dd r65500de 1 """ 2 A pipeline of Deferreds. 3 4 Ported to Python 3. 5 """ 6 7 from __future__ import absolute_import 8 from __future__ import division 9 from __future__ import print_function 10 from __future__ import unicode_literals 11 12 from future.utils import PY2 13 if PY2: 14 from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, int, list, object, range, str, max, min # noqa: F401 1 15 2 16 from twisted.internet import defer … … 4 18 from twisted.python import log 5 19 from allmydata.util.assertutil import precondition 20 6 21 7 22 class PipelineError(Exception):
Note: See TracChangeset
for help on using the changeset viewer.