viff

changeset 1202:90e278d7a950

Unit tests can be run without ViffReactor again.
author Marcel Keller <mkeller@cs.au.dk>
date Mon, 20 Jul 2009 12:04:46 +0200
parents 0fb5d4da2f1e
children 7fde9811e3bf
files viff/test/util.py
diffstat 1 files changed, 18 insertions(+), 13 deletions(-) [+]
line diff
     1.1 --- a/viff/test/util.py	Fri Jul 17 16:24:03 2009 +0200
     1.2 +++ b/viff/test/util.py	Mon Jul 20 12:04:46 2009 +0200
     1.3 @@ -27,6 +27,7 @@
     1.4  from viff.config import generate_configs, load_config
     1.5  from viff.util import rand
     1.6  from viff.test.loopback import loopbackAsync
     1.7 +from viff.reactor import ViffReactor
     1.8  
     1.9  from random import Random
    1.10  
    1.11 @@ -135,11 +136,27 @@
    1.12          self.close_sentinels = []
    1.13  
    1.14          self.runtimes = []
    1.15 -        self.real_runtimes = []
    1.16          for id in reversed(range(1, self.num_players+1)):
    1.17              _, players = load_config(configs[id])
    1.18              self.create_loopback_runtime(id, players)
    1.19  
    1.20 +        if isinstance(reactor, ViffReactor):
    1.21 +            def set_loop_call(runtimes):
    1.22 +                self.i = 0
    1.23 +
    1.24 +                # This loop call should ensure the queues of the parties are
    1.25 +                # processed in a more or less fair manner. This is necessary
    1.26 +                # because we have only one reactor for all parties here.
    1.27 +                def loop_call():
    1.28 +                    i = self.i
    1.29 +                    for j in range(len(runtimes)):
    1.30 +                        self.i = (self.i + 1) % len(runtimes)
    1.31 +                        runtimes[(i + j) % len(runtimes)].process_deferred_queue()
    1.32 +
    1.33 +                reactor.setLoopCall(loop_call)
    1.34 +
    1.35 +            gatherResults(self.runtimes).addCallback(set_loop_call)
    1.36 +
    1.37      def tearDown(self):
    1.38          """Ensure that all protocol transports are closed.
    1.39  
    1.40 @@ -179,18 +196,6 @@
    1.41          # the Runtime, since we want everybody to wait until all
    1.42          # runtimes are ready.
    1.43          self.runtimes.append(result)
    1.44 -        self.real_runtimes.append(runtime)
    1.45 -        self.i = 0
    1.46 -
    1.47 -        # This loop call should ensure the queues of the parties are
    1.48 -        # processed in a more or less fair manner. This is necessary
    1.49 -        # because we have only one reactor for all parties here.
    1.50 -        def loop_call():
    1.51 -            for runtime in self.real_runtimes[self.i:] + self.real_runtimes[:self.i]:
    1.52 -                runtime.process_deferred_queue()
    1.53 -                self.i = (self.i + 1) % len(self.real_runtimes)
    1.54 -
    1.55 -        reactor.setLoopCall(loop_call)
    1.56  
    1.57          for peer_id in players:
    1.58              if peer_id != id: