Example #1
0
    def _makeServer(self):
        # import only now to prevent the testrunner from importing it too early
        # Otherwise dualmodechannel.the_trigger is closed by the ZEO tests
        from zope.server.ftp.server import FTPServer

        root_dir = demofs.Directory()
        root_dir['test'] = demofs.Directory()
        root_dir['test'].access['foo'] = 7
        root_dir['private'] = demofs.Directory()
        root_dir['private'].access['foo'] = 7
        root_dir['private'].access['anonymous'] = 0

        fs = demofs.DemoFileSystem(root_dir, 'foo')
        fs.writefile('/test/existing', BytesIO(b'test initial data'))
        fs.writefile('/private/existing', BytesIO(b'private initial data'))

        self.__fs = fs = demofs.DemoFileSystem(root_dir, 'root')
        fs.writefile('/existing', BytesIO(b'root initial data'))

        fs_access = demofs.DemoFileSystemAccess(root_dir, {'foo': 'bar'})

        return FTPServer(self.LOCALHOST,
                         self.SERVER_PORT,
                         fs_access,
                         task_dispatcher=self.td,
                         adj=my_adj)
Example #2
0
    def setUp(self):
        # import only now to prevent the testrunner from importing it too early
        # Otherwise dualmodechannel.the_trigger is closed by the ZEO tests
        from zope.server.ftp.server import FTPServer
        td.setThreadCount(1)
        if len(asyncore.socket_map) != 1:
            # Let sockets die off.
            # TODO tests should be more careful to clear the socket map.
            asyncore.poll(0.1)
        self.orig_map_size = len(asyncore.socket_map)
        self.hook_asyncore_error()

        root_dir = demofs.Directory()
        root_dir['test'] = demofs.Directory()
        root_dir['test'].access['foo'] = 7
        root_dir['private'] = demofs.Directory()
        root_dir['private'].access['foo'] = 7
        root_dir['private'].access['anonymous'] = 0

        fs = demofs.DemoFileSystem(root_dir, 'foo')
        fs.writefile('/test/existing', StringIO('test initial data'))
        fs.writefile('/private/existing', StringIO('private initial data'))

        self.__fs = fs = demofs.DemoFileSystem(root_dir, 'root')
        fs.writefile('/existing', StringIO('root initial data'))

        fs_access = demofs.DemoFileSystemAccess(root_dir, {'foo': 'bar'})

        self.server = FTPServer(LOCALHOST, SERVER_PORT, fs_access,
                                task_dispatcher=td, adj=my_adj)
        if CONNECT_TO_PORT == 0:
            self.port = self.server.socket.getsockname()[1]
        else:
            self.port = CONNECT_TO_PORT
        self.run_loop = 1
        self.counter = 0
        self.thread_started = Event()
        self.thread = Thread(target=self.loop)
        self.thread.setDaemon(True)
        self.thread.start()
        self.thread_started.wait(10.0)
        self.assert_(self.thread_started.isSet())
Example #3
0
    def setUp(self):
        td.setThreadCount(1)
        if len(asyncore.socket_map) != 1:
            # Let sockets die off.
            # TODO tests should be more careful to clear the socket map.
            asyncore.poll(0.1)
        self.orig_map_size = len(asyncore.socket_map)
        self.hook_asyncore_error()

        root_dir = demofs.Directory()
        root_dir["test"] = demofs.Directory()
        root_dir["test"].access["foo"] = 7
        root_dir["private"] = demofs.Directory()
        root_dir["private"].access["foo"] = 7
        root_dir["private"].access["anonymous"] = 0

        fs = demofs.DemoFileSystem(root_dir, "foo")
        fs.writefile("/test/existing", StringIO("test initial data"))
        fs.writefile("/private/existing", StringIO("private initial data"))

        self.__fs = fs = demofs.DemoFileSystem(root_dir, "root")
        fs.writefile("/existing", StringIO("root initial data"))

        fs_access = demofs.DemoFileSystemAccess(root_dir, {"foo": "bar"})

        self.server = FTPServer(LOCALHOST, SERVER_PORT, fs_access, task_dispatcher=td, adj=my_adj)
        if CONNECT_TO_PORT == 0:
            self.port = self.server.socket.getsockname()[1]
        else:
            self.port = CONNECT_TO_PORT
        self.run_loop = 1
        self.counter = 0
        self.thread_started = Event()
        self.thread = Thread(target=self.loop)
        self.thread.setDaemon(True)
        self.thread.start()
        self.thread_started.wait(10.0)
        self.assert_(self.thread_started.isSet())
Example #4
0
class Tests(unittest.TestCase, AsyncoreErrorHook):
    def setUp(self):
        td.setThreadCount(1)
        if len(asyncore.socket_map) != 1:
            # Let sockets die off.
            # TODO tests should be more careful to clear the socket map.
            asyncore.poll(0.1)
        self.orig_map_size = len(asyncore.socket_map)
        self.hook_asyncore_error()

        root_dir = demofs.Directory()
        root_dir["test"] = demofs.Directory()
        root_dir["test"].access["foo"] = 7
        root_dir["private"] = demofs.Directory()
        root_dir["private"].access["foo"] = 7
        root_dir["private"].access["anonymous"] = 0

        fs = demofs.DemoFileSystem(root_dir, "foo")
        fs.writefile("/test/existing", StringIO("test initial data"))
        fs.writefile("/private/existing", StringIO("private initial data"))

        self.__fs = fs = demofs.DemoFileSystem(root_dir, "root")
        fs.writefile("/existing", StringIO("root initial data"))

        fs_access = demofs.DemoFileSystemAccess(root_dir, {"foo": "bar"})

        self.server = FTPServer(LOCALHOST, SERVER_PORT, fs_access, task_dispatcher=td, adj=my_adj)
        if CONNECT_TO_PORT == 0:
            self.port = self.server.socket.getsockname()[1]
        else:
            self.port = CONNECT_TO_PORT
        self.run_loop = 1
        self.counter = 0
        self.thread_started = Event()
        self.thread = Thread(target=self.loop)
        self.thread.setDaemon(True)
        self.thread.start()
        self.thread_started.wait(10.0)
        self.assert_(self.thread_started.isSet())

    def tearDown(self):
        self.run_loop = 0
        self.thread.join()
        td.shutdown()
        self.server.close()
        # Make sure all sockets get closed by asyncore normally.
        timeout = time.time() + 2
        while 1:
            if len(asyncore.socket_map) == self.orig_map_size:
                # Clean!
                break
            if time.time() >= timeout:
                self.fail("Leaked a socket: %s" % ` asyncore.socket_map `)
                break
            asyncore.poll(0.1)

        self.unhook_asyncore_error()

    def loop(self):
        self.thread_started.set()
        import select
        from errno import EBADF

        while self.run_loop:
            self.counter = self.counter + 1
            # Note that it isn't acceptable to fail out of
            # this loop. That will likely make the tests hang.
            try:
                asyncore.poll(0.1)
                continue
            except select.error, data:
                print "EXCEPTION POLLING IN LOOP(): ", data
                if data[0] == EBADF:
                    for key in asyncore.socket_map.keys():
                        print
                        try:
                            select.select([], [], [key], 0.0)
                        except select.error, v:
                            print "Bad entry in socket map", key, v
                            print asyncore.socket_map[key]
                            print asyncore.socket_map[key].__class__
                            del asyncore.socket_map[key]
                        else:
                            print "OK entry in socket map", key
                            print asyncore.socket_map[key]
                            print asyncore.socket_map[key].__class__
                        print
            except: