Beispiel #1
0
    def test_pinning(self):
        # Check to make sure the 'other' database shows in in reads first
        success = False
        for i in range(100):
            db = self.router.db_for_read(self.obj1)
            if db == 'other':
                success = True
                break
        self.assertTrue(success, "The 'other' database was not offered.")

        # Simulate a write
        self.router.db_for_write(self.obj1)

        # Check to make sure that only the master database shows up in reads,
        # since the thread should now be pinned
        success = True
        for i in range(100):
            db = self.router.db_for_read(self.obj1)
            if db == 'other':
                success = False
                break
        self.assertTrue(success, "The 'other' database was offered in error.")

        pinning.unpin_thread()
        pinning.clear_db_write()
Beispiel #2
0
 def test_pinning(self):
     # Check to make sure the 'other' database shows in in reads first
     success = False
     for i in range(100):
         db = self.router.db_for_read(self.obj1)
         if db == 'other':
             success = True
             break
     self.assertTrue(success, "The 'other' database was not offered.")
     
     # Simulate a write
     self.router.db_for_write(self.obj1)
     
     # Check to make sure that only the master database shows up in reads,
     # since the thread should now be pinned
     success = True
     for i in range(100):
         db = self.router.db_for_read(self.obj1)
         if db == 'other':
             success = False
             break
     self.assertTrue(success, "The 'other' database was offered in error.")
     
     pinning.unpin_thread()
     pinning.clear_db_write()
Beispiel #3
0
 def process_response(self, request, response):
     """
     If there was a write to the db, set the session variable to enable
     pinning.  If the variable already exists, the time will be reset.
     """
     if pinning.db_was_written():
         pinned_until = datetime.now() + timedelta(seconds=PINNING_SECONDS)
         request.session[PINNING_KEY] = pinned_until
         pinning.clear_db_write()
     pinning.unpin_thread()
     return response
Beispiel #4
0
 def process_response(self, request, response):
     """
     If there was a write to the db, set the session variable to enable
     pinning.  If the variable already exists, the time will be reset.
     """
     if pinning.db_was_written():
         pinned_until = datetime.now() + timedelta(seconds=PINNING_SECONDS)
         request.session[PINNING_KEY] = pinned_until
         pinning.clear_db_write()
     pinning.unpin_thread()
     return response
Beispiel #5
0
 def process_response(self, request, response):
     """
     If this is a POST request and there was a write to the db, set the
     cookie to enable pinning.  If the cookie already exists, the time will
     be reset.
     """
     if request.method == 'POST' and pinning.db_was_written():
         response.set_cookie(PINNING_KEY,
                             value='y',
                             max_age=PINNING_SECONDS)
         pinning.clear_db_write()
     pinning.unpin_thread()
     return response
Beispiel #6
0
 def process_response(self, request, response):
     """
     If this is a POST request and there was a write to the db, set the
     cookie to enable pinning.  If the cookie already exists, the time will
     be reset.
     """
     if request.method == 'POST' and pinning.db_was_written():
         response.set_cookie(PINNING_KEY,
                             value='y',
                             max_age=PINNING_SECONDS)
         pinning.clear_db_write()
     pinning.unpin_thread()
     return response