Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Optimizations to project deletion and TestRun deletion. Fix for CUANT…

…O-82. Remove DataService.deleteTestCasesForProject() and tests.
  • Loading branch information...
commit 6bc4185559e73a37d25234643b7b83270f15c524 1 parent 5ed9b7b
Todd Wells authored October 08, 2011
7  grails/grails-app/jobs/ProjectDeletionJob.groovy
@@ -33,10 +33,11 @@ class ProjectDeletionJob {
33 33
 		def toDelete = Project.findAllByDeleted(true)
34 34
 		toDelete.each {
35 35
 			def pg = it.projectGroup?.name
36  
-			log.info("Deleting ${it.name} from ProjectGroup ${pg}")
  36
+			def startTime = new Date().time
  37
+			log.info("Deleting project ${it.name}")
37 38
 			projectService.deleteProject(it)
38  
-			log.info("${it.name} from ProjectGroup ${pg} deleted")
  39
+			def elapsed = new Date().time - startTime
  40
+			log.info("Project ${it.name} deleted, ${elapsed} ms elapsed.")
39 41
 		}
40 42
 	}
41  
-
42 43
 }
12  grails/grails-app/services/cuanto/DataService.groovy
@@ -560,18 +560,6 @@ class DataService {
560 560
 	}
561 561
 
562 562
 
563  
-	def deleteTestCasesForProject(project) {
564  
-		def cases = getTestCases(project)
565  
-		cases.each { TestCase tc ->
566  
-			def outcomes = TestOutcome.findAllByTestCase(tc)
567  
-			outcomes.each { outcome ->
568  
-				outcome.delete(flush:true)
569  
-			}
570  
-		}
571  
-		TestCase.executeUpdate("delete cuanto.TestCase tc where tc.project = ?", [project])
572  
-	}
573  
-
574  
-
575 563
 	def getBugSummary(testRun) {
576 564
 		def bugStats = TestOutcome.executeQuery("""select distinct outc.bug, (select count(outb) from
577 565
 				cuanto.TestOutcome outb	where outb.testRun = ? and outb.bug = outc.bug) from cuanto.TestOutcome
7  grails/grails-app/services/cuanto/ProjectService.groovy
@@ -60,10 +60,12 @@ class ProjectService {
60 60
 		if (project) {
61 61
 			def origGroup = project.projectGroup
62 62
 			def testRuns = dataService.getTestRunsByProject(project)
63  
-			dataService.deleteTestCasesForProject(project)
64 63
 			testRuns.each { testRun ->
65  
-				testRunService.deleteTestRun(testRun)
  64
+				testRunService.deleteTestRun(testRun, false)
66 65
 			}
  66
+
  67
+			TestCase.executeUpdate("delete cuanto.TestCase tc where tc.project = ?", [project])
  68
+
67 69
 			project.delete(flush: true)
68 70
 			deleteProjectGroupIfUnused(origGroup)
69 71
 		}
@@ -219,6 +221,7 @@ class ProjectService {
219 221
 
220 222
 	void queueForDeletion(Project project) {
221 223
 		def groupId = project?.projectGroup?.id
  224
+		log.info "Queuing ${project.name} for deletion"
222 225
 		project.deleted = true
223 226
 		project.projectGroup = null
224 227
 		project.projectKey = String.valueOf(System.currentTimeMillis()).reverse()
24  grails/grails-app/services/cuanto/TestRunService.groovy
@@ -648,11 +648,15 @@ class TestRunService {
648 648
 	 * after which FailureStatusUpdateTasks are queued for re-initialization of the isFailureStatusChanged field
649 649
 	 * for all TestOutcomes in the next TestRun.
650 650
 	 */
651  
-	def deleteTestRun(TestRun run) {
652  
-		TestRun.withTransaction {
  651
+	def deleteTestRun(TestRun run, recalc = true) {
653 652
 			try {
654  
-				TestRun testRun = TestRun.lock(run.id)
655  
-				TestRun nextRun = dataService.getNextTestRun(run)
  653
+				TestRun testRun = TestRun.get(run.id)
  654
+				TestRun nextRun = null
  655
+
  656
+				 if (recalc) {
  657
+					 nextRun = dataService.getNextTestRun(run)
  658
+				 }
  659
+
656 660
 				statisticService.dequeueTestRunStats(run.id)
657 661
 				statisticService.deleteStatsForTestRun(run)
658 662
 
@@ -684,7 +688,8 @@ class TestRunService {
684 688
 
685 689
 				testRun.save()
686 690
 				testRun.delete()
687  
-				if (nextRun) {
  691
+
  692
+				if (recalc && nextRun) {
688 693
 					failureStatusService.queueFailureStatusUpdateForRun(nextRun)
689 694
 					nextRun?.discard()
690 695
 				}
@@ -695,15 +700,12 @@ class TestRunService {
695 700
 			} catch (StaleObjectStateException e) {
696 701
 				log.error "StaleObjectStateException for test run ${run.id}"
697 702
 			}
698  
-		}
699 703
 	}
700 704
 
701 705
 
702  
-	Integer deleteTestRuns(testRunIds) {
703  
-		TestRun.withTransaction {
704  
-			testRunIds.each { runId ->
705  
-				deleteTestRun TestRun.get(runId)
706  
-			}
  706
+	Integer deleteTestRuns(testRunIds, recalc = true) {
  707
+		testRunIds.each { runId ->
  708
+			deleteTestRun(TestRun.get(runId), recalc)
707 709
 		}
708 710
 		return testRunIds.size()
709 711
 	}
16  grails/test/integration/cuanto/TestCaseTests.groovy
@@ -154,20 +154,4 @@ class TestCaseTests extends GroovyTestCase {
154 154
 		assertEquals "Wrong number of test cases", 1, dataService.getTestCases(fetchedProj).size()
155 155
 	}
156 156
 
157  
-
158  
-	void testDeleteTestCasesForProject() {
159  
-		def project = to.project
160  
-		dataService.saveDomainObject project
161  
-
162  
-		def testCases = 10
163  
-		1.upto(testCases) {
164  
-			def testCase = to.getTestCase(project)
165  
-			dataService.saveDomainObject testCase
166  
-		}
167  
-
168  
-		assertEquals "Wrong number of test cases", testCases, TestCase.list().size()
169  
-		dataService.deleteTestCasesForProject(project)
170  
-		assertEquals "Wrong number of test cases", 0, TestCase.list().size()
171  
-		assertEquals "Wrong number of test outcomes", 0, TestOutcome.list().size()
172  
-	}
173 157
 }

0 notes on commit 6bc4185

Please sign in to comment.
Something went wrong with that request. Please try again.