diff mbox

[Branch,~linaro-validation/lava-scheduler/trunk] Rev 36: add a test, fix a slightly ridiculous problem, slightly whingy comment about said problem

Message ID 20110720050050.8247.29231.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

Michael-Doyle Hudson July 20, 2011, 5 a.m. UTC
------------------------------------------------------------
revno: 36
committer: Michael-Doyle Hudson <michael.hudson@linaro.org>
branch nick: trunk
timestamp: Wed 2011-07-20 16:58:48 +1200
message:
  add a test, fix a slightly ridiculous problem, slightly whingy comment about said problem
modified:
  lava_scheduler_app/tests.py
  lava_scheduler_daemon/dbjobsource.py


--
lp:lava-scheduler
https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk

You are subscribed to branch lp:lava-scheduler.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'lava_scheduler_app/tests.py'
--- lava_scheduler_app/tests.py	2011-07-06 22:39:01 +0000
+++ lava_scheduler_app/tests.py	2011-07-20 04:58:48 +0000
@@ -3,6 +3,7 @@ 
 import json
 import xmlrpclib
 
+from django.db import transaction
 from django.contrib.auth.models import Permission, User
 from django.test.client import Client
 
@@ -195,13 +196,21 @@ 
         definition = {'foo': 'bar'}
         self.factory.make_testjob(
             target=device, definition=json.dumps(definition))
+        transaction.commit()
         self.assertEqual(
             definition, DatabaseJobSource().getJobForBoard_impl('panda01'))
 
+    def test_getJobForBoard_returns_None_if_no_job(self):
+        self.factory.make_device(hostname='panda01')
+        transaction.commit()
+        self.assertEqual(
+            None, DatabaseJobSource().getJobForBoard_impl('panda01'))
+
     def test_getJobForBoard_sets_start_time(self):
         device = self.factory.make_device(hostname='panda01')
         job = self.factory.make_testjob(target=device)
         before = datetime.datetime.now()
+        transaction.commit()
         DatabaseJobSource().getJobForBoard_impl('panda01')
         after = datetime.datetime.now()
         # reload from the database
@@ -211,6 +220,7 @@ 
     def test_getJobForBoard_set_statuses(self):
         device = self.factory.make_device(hostname='panda01')
         job = self.factory.make_testjob(target=device)
+        transaction.commit()
         DatabaseJobSource().getJobForBoard_impl('panda01')
         # reload from the database
         job = TestJob.objects.get(pk=job.pk)
@@ -222,6 +232,7 @@ 
     def test_getJobForBoard_sets_running_job(self):
         device = self.factory.make_device(hostname='panda01')
         job = self.factory.make_testjob(target=device)
+        transaction.commit()
         DatabaseJobSource().getJobForBoard_impl('panda01')
         # reload from the database
         job = TestJob.objects.get(pk=job.pk)
@@ -231,11 +242,13 @@ 
     def get_device_and_running_job(self):
         device = self.factory.make_device(hostname='panda01')
         job = self.factory.make_testjob(target=device)
+        transaction.commit()
         DatabaseJobSource().getJobForBoard_impl('panda01')
         return device, job
 
     def test_jobCompleted_set_statuses(self):
         device, job = self.get_device_and_running_job()
+        transaction.commit()
         DatabaseJobSource().jobCompleted_impl('panda01', None)
         job = TestJob.objects.get(pk=job.pk)
         device = Device.objects.get(pk=device.pk)
@@ -246,6 +259,7 @@ 
     def test_jobCompleted_sets_end_time(self):
         device, job = self.get_device_and_running_job()
         before = datetime.datetime.now()
+        transaction.commit()
         DatabaseJobSource().jobCompleted_impl('panda01', None)
         after = datetime.datetime.now()
         job = TestJob.objects.get(pk=job.pk)
@@ -253,6 +267,7 @@ 
 
     def test_jobCompleted_clears_current_job(self):
         device, job = self.get_device_and_running_job()
+        transaction.commit()
         DatabaseJobSource().jobCompleted_impl('panda01', None)
         device = Device.objects.get(pk=device.pk)
         self.assertEquals(None, device.current_job)

=== modified file 'lava_scheduler_daemon/dbjobsource.py'
--- lava_scheduler_daemon/dbjobsource.py	2011-07-06 21:59:57 +0000
+++ lava_scheduler_daemon/dbjobsource.py	2011-07-20 04:58:48 +0000
@@ -56,6 +56,11 @@ 
                     transaction.commit()
                     return json.loads(job.definition)
             else:
+                # We don't really need to rollback here, as no modifying
+                # operations have been made to the database.  But Django is
+                # stupi^Wconservative and assumes the queries that have been
+                # issued might have been modifications.
+                transaction.rollback()
                 return None
 
     def getJobForBoard(self, board_name):