tests: add test for race condition during VM creation (#906)

This commit is contained in:
Marek Marczykowski-Górecki 2014-10-22 02:15:32 +02:00
parent d5817eb6c5
commit 9324cdb175

View File

@ -19,10 +19,12 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
import multiprocessing
import os
import shutil
import unittest
import time
from qubes.qubes import QubesVmCollection, QubesException, system_path
VM_PREFIX = "test-"
@ -74,6 +76,27 @@ class BasicTests(unittest.TestCase):
except QubesException:
self.fail("verify_files() failed")
# Bug: #906
def test_db_locking(self):
def create_vm(name):
qc = QubesVmCollection()
qc.lock_db_for_writing()
qc.load()
time.sleep(1)
vmname = VM_PREFIX + name
qc.add_new_vm("QubesAppVm", name=vmname, template=qc.get_default_template())
qc.save()
qc.unlock_db()
t = multiprocessing.Process(target=create_vm, args=("test1",))
t.start()
create_vm("test2")
t.join()
self.qc.lock_db_for_reading()
self.qc.load()
self.qc.unlock_db()
self.assertIsNotNone(self.qc.get_vm_by_name(VM_PREFIX + "test1"))
self.assertIsNotNone(self.qc.get_vm_by_name(VM_PREFIX + "test2"))
class VmPropTests(unittest.TestCase):
def setUp(self):
self.qc = QubesVmCollection()