Example #1
0
def t1(pretty, factory):
    class Defiant(Control):
        def handle_SIGTERM(self, signum, frame):
            pass  # go on living

        @Control.rpc
        def ping(self):
            return 'pong', self.pid

        @Control.rpc
        def stop(self):
            Control.stop(self)

    class Spawner(Control):
        children = None

        @Control.rpc
        def spawn(self):
            if not self.children:
                self.children = []
            sock, port = find_free_port()
            d = Defiant(port, None, sock)
            d.start()
            self.children.append(d)
            return [d.pid, port]

        @Control.rpc
        def orphanize(self):
            if not self.children:
                return None
            child, self.children = self.children[0], self.children[1:]
            child.terminate()
            self.join_later(child)

        @Control.rpc
        def list_orphans(self):
            return [p.pid for p in self.deferred_joins]

    sock, port = find_free_port()
    spawner = Spawner(port, None, sock)
    spawner.start()
    factory.processes.append(spawner)
    master = RemoteControl(('', port), None, 1)

    defiers = []
    for i in range(5):
        pid, port = master.spawn()
        remote = RemoteControl(('', port), None, 5)
        defiers.append(remote)

    orphans = master.list_orphans()
    if orphans:
        print('FAIL %s: there are orphans: %s' % (pretty, orphans))
        return False

    for i in range(5):
        master.orphanize()

    orphans = master.list_orphans()
    if len(orphans) != 5:
        print('FAIL %s: there are not 5 orphans: %s' % (pretty, orphans))
        return False

    for remote in defiers:
        try:
            remote.ping()
        except Exception, e:
            print('FAIL %s: orphan died too soon: %s' % (pretty, remote))
            return False
        remote.stop(__async__=True)
Example #2
0
        remote.stop_listening()
    except Exception, e:
        print('FAIL %s: could not stop listening: %s' % (pretty, str(e)))
        return False

    # existing connection is still alive?
    try:
        pong = remote.sync_ping()
    except Exception, e:
        print('FAIL %s: ping failed: %s' % (pretty, str(e)))
        return False

    # new connections cannot be made?
    try:
        r = RemoteControl(('',remote.address[1]), 'password', 1, False)
        pong = r.ping()
        print('FAIL %s: can talk to the deaf: %s' % (pretty, pong))
        return False
    except ConnectionRefused, e:
        pass # good
    except Exception, e:
        print('FAIL %s: wrong error: %s' % (pretty, str(e)))
        return False

    return True

# check that non-ASCII characters in implicitly typed AveException messages
# do not hang the control
@smoke
@setup(MockControl)
def t30(control, remote, pipe):