Exemple #1
0
    def setUp(self):
        self.config = testing.setUp()
        # creating a test application
        settings = {}
        load_into_settings(self.ini, settings)
        self.config.add_settings(settings)
        self.config.include("appsync")

        # do we have memcached support, if not
        # and if we use the SQL backend we need to
        # adapt its options
        if not memcache_up():
            backend = self.config.registry.settings['storage.backend']
            storage = self.config.registry.getUtility(IAppSyncDatabase)
            if backend == 'appsync.storage.sql.SQLDatabase':
                storage.cache = FakeCache()
            elif backend == 'appsync.storage.mirrored.MirroredDatabase':
                rw = storage._readwrite
                if rw.__class__.__name__ == 'SQLDatabase':
                    rw.cache = FakeCache()

        wsgiapp = self.config.make_wsgi_app()
        retry_after = self.config.registry.settings.get('global.retry_after',
                '120')
        app = CatchErrors(CatchAuthError(wsgiapp, retry_after))
        self.app = TestApp(app)
Exemple #2
0
    def setUp(self):
        self.config = testing.setUp()
        # creating a test application
        settings = {}
        load_into_settings(self.ini, settings)
        self.config.add_settings(settings)
        self.config.include("appsync")

        # do we have memcached support, if not
        # and if we use the SQL backend we need to
        # adapt its options
        if not memcache_up():
            backend = self.config.registry.settings['storage.backend']
            storage = self.config.registry.getUtility(IAppSyncDatabase)
            if backend == 'appsync.storage.sql.SQLDatabase':
                storage.cache = FakeCache()
            elif backend == 'appsync.storage.mirrored.MirroredDatabase':
                rw = storage._readwrite
                if rw.__class__.__name__ == 'SQLDatabase':
                    rw.cache = FakeCache()

        wsgiapp = self.config.make_wsgi_app()
        retry_after = self.config.registry.settings.get(
            'global.retry_after', '120')
        app = CatchErrors(CatchAuthError(wsgiapp, retry_after))
        self.app = TestApp(app)
Exemple #3
0
    def test_hits(self):
        # do we have memcached running ?
        if not memcache_up():
            return

        # running with memcached
        current = FakeSauropod.hits
        self.test_protocol()
        hits_with_cache = FakeSauropod.hits - current

        # reset the data
        FakeSauropod.clear()

        # let's deactivate the cache
        storage = self.config.registry.getUtility(IAppSyncDatabase)
        current = FakeSauropod.hits
        old = storage.cache
        storage.cache = None
        try:
            self.test_protocol()
        finally:
            storage.cache = old

        hits_no_cache = FakeSauropod.hits - current

        # when cache is enabled, we hits more than two times the DB
        self.assertTrue(hits_with_cache * 2 < hits_no_cache)