Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 187 lines (151 sloc) 6.598 kb
b73ee542 » graemerocher
2012-03-16 added build listener, however this currently breaks the built, only t…
1 import org.gradle.api.execution.TaskExecutionListener
2 import org.gradle.api.tasks.testing.Test
3 import org.gradle.api.tasks.*
4
77bafbc8 » graemerocher
2012-01-18 first cut of new geb/spock based functional test suite
5 apply plugin: 'groovy'
6 apply plugin: 'idea'
68e0540a » graemerocher
2012-01-18 running single tests and fixed cleanup of tmp project directories
7 apply plugin: 'eclipse'
77bafbc8 » graemerocher
2012-01-18 first cut of new geb/spock based functional test suite
8
9 repositories {
941bad30 » jeffbrown
2012-09-04 revert to groovy 1.8 for now
10 mavenCentral()
11 mavenRepo url:"https://nexus.codehaus.org/content/repositories/snapshots"
77bafbc8 » graemerocher
2012-01-18 first cut of new geb/spock based functional test suite
12 }
13
14
15 test {
16 if (project.hasProperty('maxParallelForks'))
17 maxParallelForks = project.maxParallelForks as int
18 if (project.hasProperty('forkEvery'))
19 forkEvery = project.forkEvery as int
45cfcd76 » graemerocher
2013-01-11 update test suite for latest changes to grails-core
20
21
22 testLogging.showStandardStreams = true
77bafbc8 » graemerocher
2012-01-18 first cut of new geb/spock based functional test suite
23 }
24
25 // The drivers we want to use
45cfcd76 » graemerocher
2013-01-11 update test suite for latest changes to grails-core
26 ext {
27 drivers = ["htmlunit"]
28 }
29
77bafbc8 » graemerocher
2012-01-18 first cut of new geb/spock based functional test suite
30
31 dependencies {
cb081210 » graemerocher
2013-04-10 fix PluginViews functional test
32 groovy "org.codehaus.groovy:groovy-all:2.1.2"
77bafbc8 » graemerocher
2012-01-18 first cut of new geb/spock based functional test suite
33
cb081210 » graemerocher
2013-04-10 fix PluginViews functional test
34 def gebVersion = "0.9.0"
35 def seleniumVersion = "2.31.0"
77bafbc8 » graemerocher
2012-01-18 first cut of new geb/spock based functional test suite
36
37 // If using Spock, need to depend on geb-spock
cb081210 » graemerocher
2013-04-10 fix PluginViews functional test
38 testCompile "org.gebish:geb-spock:$gebVersion"
39
40 testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
77bafbc8 » graemerocher
2012-01-18 first cut of new geb/spock based functional test suite
41
42 // If using JUnit, need to depend on geb-junit (3 or 4)
cb081210 » graemerocher
2013-04-10 fix PluginViews functional test
43 testCompile "org.gebish:geb-junit4:$gebVersion"
77bafbc8 » graemerocher
2012-01-18 first cut of new geb/spock based functional test suite
44 testCompile "junit:junit-dep:4.8.2"
45
46 // Drivers
cb081210 » graemerocher
2013-04-10 fix PluginViews functional test
47 testCompile "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
48 // testCompile "com.github.detro.ghostdriver:phantomjsdriver:1.0.1"
77bafbc8 » graemerocher
2012-01-18 first cut of new geb/spock based functional test suite
49 drivers.each { driver ->
50 testCompile "org.seleniumhq.selenium:selenium-$driver-driver:$seleniumVersion"
51 }
52 }
53
f07757b2 » graemerocher
2012-03-16 Some fixes that ensure the autostart processes are terminated when th…
54
77bafbc8 » graemerocher
2012-01-18 first cut of new geb/spock based functional test suite
55 drivers.each { driver ->
636779cc » graemerocher
2012-03-27 fixed failing test, improved handling of auto startup apps and remove…
56 def testSingle = System.getProperty("test.single")
57 if(testSingle)
58 System.setProperty("${driver}Test.single", testSingle)
77bafbc8 » graemerocher
2012-01-18 first cut of new geb/spock based functional test suite
59 task "${driver}Test"(type: Test) {
60 def grailsWorkDir = new File(buildDir, 'grails-work')
61 def projectWorkDir = new File(buildDir, 'project-work')
62 def outputDir = new File(buildDir, 'output')
c9ac511b » graemerocher
2012-01-20 formatting fix
63
f7d79969 » graemerocher
2012-03-16 allow definition of applications that autostart when the test suite s…
64 def appToPort = [:]
65 def grailsHome = System.properties['grails.home'] ?: new File('../grails-master').exists() ? new File('../grails-master').absolutePath : new File('../grails-core').absolutePath
66 def processes = []
636779cc » graemerocher
2012-03-27 fixed failing test, improved handling of auto startup apps and remove…
67 boolean backgroundComplete = false
f7d79969 » graemerocher
2012-03-16 allow definition of applications that autostart when the test suite s…
68 def appsToStart = new File("autostart").listFiles().findAll() { File f -> f.isDirectory() && !f.isHidden()}
69 int port = 8890
70 for(File appDir in appsToStart) {
71 println "Autostarting application $appDir.name"
72 if(new File(appDir, "grails-app").exists()) {
73 appToPort.put(appDir, port++)
74 }
75 }
76
c9ac511b » graemerocher
2012-01-20 formatting fix
77 doFirst {
77bafbc8 » graemerocher
2012-01-18 first cut of new geb/spock based functional test suite
78 [grailsWorkDir, projectWorkDir, outputDir].each {
79 it.deleteDir()
80 assert it.mkdirs()
f7d79969 » graemerocher
2012-03-16 allow definition of applications that autostart when the test suite s…
81 }
636779cc » graemerocher
2012-03-27 fixed failing test, improved handling of auto startup apps and remove…
82 boolean appsStarted = false
f7d79969 » graemerocher
2012-03-16 allow definition of applications that autostart when the test suite s…
83 for(entry in appToPort) {
84 File appDir = entry.key
85 port = entry.value
86 println "Autostarting application $appDir.name"
636779cc » graemerocher
2012-03-27 fixed failing test, improved handling of auto startup apps and remove…
87
f7d79969 » graemerocher
2012-03-16 allow definition of applications that autostart when the test suite s…
88 if(new File(appDir, "grails-app").exists()) {
89 // start app
636779cc » graemerocher
2012-03-27 fixed failing test, improved handling of auto startup apps and remove…
90
91 appsStarted = true
f07757b2 » graemerocher
2012-03-16 Some fixes that ensure the autostart processes are terminated when th…
92 Thread.start {
636779cc » graemerocher
2012-03-27 fixed failing test, improved handling of auto startup apps and remove…
93 try {
94 def toExecute = buildCommand("upgrade", grailsHome, grailsWorkDir, projectWorkDir, appDir,port)
95 def upgrade = createProcess(toExecute, grailsHome, appDir)
96 executeProcess(upgrade)
97
98 toExecute = buildCommand("run-app", grailsHome, grailsWorkDir, projectWorkDir, appDir,port)
45cfcd76 » graemerocher
2013-01-11 update test suite for latest changes to grails-core
99 def process = createProcess(toExecute, grailsHome, appDir)
636779cc » graemerocher
2012-03-27 fixed failing test, improved handling of auto startup apps and remove…
100 processes << process
101 backgroundComplete = true
102 executeProcess(process)
103 }
104 finally {
105 backgroundComplete = true
106 }
f7d79969 » graemerocher
2012-03-16 allow definition of applications that autostart when the test suite s…
107 }
108
109 }
110 }
636779cc » graemerocher
2012-03-27 fixed failing test, improved handling of auto startup apps and remove…
111 if(!appsStarted) {
112 backgroundComplete = true
113 }
114
f7d79969 » graemerocher
2012-03-16 allow definition of applications that autostart when the test suite s…
115 }
116
b73ee542 » graemerocher
2012-03-16 added build listener, however this currently breaks the built, only t…
117 gradle.addListener(
118 [beforeExecute: { org.gradle.api.Task t ->},
119 afterExecute: {Task task, TaskState state ->
636779cc » graemerocher
2012-03-27 fixed failing test, improved handling of auto startup apps and remove…
120 if (task instanceof Test) {
121 while(!backgroundComplete) {
122 sleep 1000
123 }
124
b73ee542 » graemerocher
2012-03-16 added build listener, however this currently breaks the built, only t…
125 for(Process p in processes) {
126 p.destroy()
127 }
636779cc » graemerocher
2012-03-27 fixed failing test, improved handling of auto startup apps and remove…
128
b73ee542 » graemerocher
2012-03-16 added build listener, however this currently breaks the built, only t…
129 processes.clear()
130 [grailsWorkDir, projectWorkDir, outputDir].each {
131 it.deleteDir()
132 assert it.mkdirs()
133 }
134 }
135 }] as TaskExecutionListener
136 )
d15e1a8a » graemerocher
2012-01-20 removed duplicate get reports sys property
137 testReportDir = file("$reportsDir/$name/tests")
138 testResultsDir = file("$buildDir/test-results/$name")
139
f7d79969 » graemerocher
2012-03-16 allow definition of applications that autostart when the test suite s…
140 for (entry in appToPort) {
141
142 systemProperty "grails.app.port.$entry.key.name", entry.value
143 }
d15e1a8a » graemerocher
2012-01-20 removed duplicate get reports sys property
144 systemProperty "geb.build.reportsDir", "$reportsDir/$name/geb"
145 systemProperty "geb.env", driver
f7d79969 » graemerocher
2012-03-16 allow definition of applications that autostart when the test suite s…
146
147 systemProperty 'grailsHome', grailsHome
77bafbc8 » graemerocher
2012-01-18 first cut of new geb/spock based functional test suite
148 systemProperty 'grailsWorkDir', grailsWorkDir.canonicalPath
75033d8b » graemerocher
2012-01-18 cleanup handling of project work dir
149 systemProperty 'projectWorkDir', projectWorkDir.canonicalPath
77bafbc8 » graemerocher
2012-01-18 first cut of new geb/spock based functional test suite
150 systemProperty 'outputDir', outputDir.canonicalPath
cb081210 » graemerocher
2013-04-10 fix PluginViews functional test
151 // jvmArgs '-Xdebug',
152 // '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005'
f07757b2 » graemerocher
2012-03-16 Some fixes that ensure the autostart processes are terminated when th…
153
cb081210 » graemerocher
2013-04-10 fix PluginViews functional test
154 // maxParallelForks = 2
155 // forkEvery = 2
77bafbc8 » graemerocher
2012-01-18 first cut of new geb/spock based functional test suite
156 // If you wanted to set the baseUrl in your build…
157 // systemProperty "geb.build.baseUrl", "http://myapp.com"
158 }
159 }
160
f07757b2 » graemerocher
2012-03-16 Some fixes that ensure the autostart processes are terminated when th…
161 def executeProcess(Process process) {
162 def buffer = new StringBuffer()
163 process.consumeProcessOutput(buffer, buffer)
164 process.waitForOrKill(1000 * 60 * 5)
45cfcd76 » graemerocher
2013-01-11 update test suite for latest changes to grails-core
165 def exitStatus = process.exitValue()
f07757b2 » graemerocher
2012-03-16 Some fixes that ensure the autostart processes are terminated when th…
166 println buffer
167 }
168
169 Process createProcess(ArrayList<String> toExecute, grailsHome, appDir) {
46031fc6 » graemerocher
2012-03-16 various fixes to improve the reliability of test execution
170 println "Running command: ${toExecute.join(' ')}"
f7d79969 » graemerocher
2012-03-16 allow definition of applications that autostart when the test suite s…
171 println "Base directory: $appDir"
172
173 def process = (Process) new ProcessBuilder(toExecute).with {
174 redirectErrorStream(true)
175 directory(appDir.canonicalFile)
176 environment()["GRAILS_HOME"] = grailsHome
177 start()
178 }
179 return process
180 }
181
182 def buildCommand(String cmd, grailsHome, grailsWorkDir, projectWorkDir, appDir,int port) {
37f7c237 » graemerocher
2012-03-27 add --stacktrace to attempt to debug the problem in the build server
183 [new File("${grailsHome}/bin/grails").canonicalPath, "-Dgrails.work.dir=${grailsWorkDir} -Dgrails.project.work.dir=${projectWorkDir}/${appDir.name}".toString(), "--non-interactive".toString(), "--stacktrace", "-Dgrails.server.port.http=${port}".toString(), cmd.toString()]
184
f7d79969 » graemerocher
2012-03-16 allow definition of applications that autostart when the test suite s…
185 }
186
68e0540a » graemerocher
2012-01-18 running single tests and fixed cleanup of tmp project directories
187 task test(overwrite: true, dependsOn: drivers.collect { tasks["${it}Test"] })
188
189
Something went wrong with that request. Please try again.