@@ -0,0 +1,1757 @@
+#!/usr/bin/env python%0A%22%22%22Unittests for the :mod:%60bridgedb.Storage%60 module.%22%22%22%0A%0Afrom twisted.python import log%0Afrom twisted.trial import unittest%0Aimport bridgedb.Storage as Storage%0Afrom twisted.internet import reactor%0Afrom twisted.internet.threads import deferToThread%0Aimport os%0Aimport threading%0Afrom time import sleep%0A%0Aclass DatabaseTest(unittest.TestCase):%0A    def setUp(self):%0A        self.dbfname = 'test-bridgedb.sqlite'%0A        Storage.setDBFilename(self.dbfname)%0A%0A    def tearDown(self):%0A        if os.path.isfile(self.dbfname):%0A            os.unlink(self.dbfname)%0A        Storage.clearGlobalDB()%0A%0A    def _runAndDie(self, timeout, func):%0A        with func():%0A            sleep(timeout)%0A%0A    def _cb_assertTrue(self, result):%0A        self.assertTrue(result)%0A%0A    def _cb_assertFalse(self, result):%0A        self.assertFalse(result)%0A%0A    def _eb_Failure(self, failure):%0A        self.fail(failure)%0A%0A    def test_getDB_FalseWhenLocked(self):%0A        Storage._LOCK = threading.Lock()%0A        Storage._LOCK.acquire()%0A        self.assertFalse(Storage._LOCK.acquire(False))%0A%0A    def test_getDB_AcquireLock(self):%0A        Storage.initializeDBLock()%0A        with Storage.getDB() as db:%0A            self.assertIsInstance(db, Storage.Database)%0A            self.assertTrue(Storage.dbIsLocked())%0A            self.assertEqual(db, Storage._OPENED_DB)%0A%0A    def test_getDB_ConcurrencyLock(self):%0A        timeout = 1%0A        d1 = deferToThread(self._runAndDie, timeout, Storage.getDB)%0A        d1.addCallback(self._cb_assertFalse)%0A        d1.addErrback(self._eb_Failure)%0A        d2 = deferToThread(Storage.getDB, False)%0A        d2.addCallback(self._cb_assertFalse)%0A        d2.addErrback(self._eb_Failure)%0A        d2.addCallback(self._cb_assertTrue, Storage.getDB(False))%0A

Add unit tests for bridgedb.Storage