This is an automated email from the ASF dual-hosted git repository.
matrei pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/grails-core.git
The following commit(s) were added to refs/heads/7.0.x by this push:
new 1cde2d4518 test: fix more flakiness in `PerTestRecordingSpec` (#15248)
1cde2d4518 is described below
commit 1cde2d45182b90162c21e11b6054cbce3057b682
Author: Mattias Reichel <[email protected]>
AuthorDate: Fri Nov 21 14:01:57 2025 +0100
test: fix more flakiness in `PerTestRecordingSpec` (#15248)
---
.../org/demo/spock/PerTestRecordingSpec.groovy | 38 ++++++++++++++++++----
1 file changed, 32 insertions(+), 6 deletions(-)
diff --git
a/grails-test-examples/geb/src/integration-test/groovy/org/demo/spock/PerTestRecordingSpec.groovy
b/grails-test-examples/geb/src/integration-test/groovy/org/demo/spock/PerTestRecordingSpec.groovy
index 67213bb497..16a51b27bf 100644
---
a/grails-test-examples/geb/src/integration-test/groovy/org/demo/spock/PerTestRecordingSpec.groovy
+++
b/grails-test-examples/geb/src/integration-test/groovy/org/demo/spock/PerTestRecordingSpec.groovy
@@ -44,7 +44,10 @@ class PerTestRecordingSpec extends ContainerGebSpec {
void '(setup) running a second test to create another recording'() {
when: 'visiting another page than the previous test'
to(UploadPage)
-
+
+ and: 'pausing so we can see the page change in the video'
+ Thread.sleep(500)
+
then: 'the page loads correctly'
title == 'Upload Test'
}
@@ -77,13 +80,14 @@ class PerTestRecordingSpec extends ContainerGebSpec {
recordingDir != null
when: 'getting all video recording files (mp4 or flv) from the
recording directory'
- def recordingFiles = recordingDir?.listFiles({ File file ->
- isVideoFile(file) && file.name.contains(this.class.simpleName)
- } as FileFilter)
+ def minFileCount = 2 // At least 2 files for the first two test methods
+ def recordingFiles = waitForRecordingFiles(recordingDir,
this.class.simpleName, minFileCount)
+ def names = recordingFiles*.name.join('\n')
then: 'recording files should exist for each test method'
- recordingFiles != null
- recordingFiles.length >= 2 // At least 2 files for the first two test
methods
+ recordingFiles.length >= minFileCount
+ names.contains('setup_running_a_test_to_create_a_recording')
+ names.contains('setup_running_a_second_test_to_create_another')
and: 'the recording files should have different content'
// Sort by last modified time to get the most recent files
@@ -96,4 +100,26 @@ class PerTestRecordingSpec extends ContainerGebSpec {
private static boolean isVideoFile(File file) {
file.isFile() && (file.name.endsWith('.mp4') ||
file.name.endsWith('.flv'))
}
+
+ private static File[] waitForRecordingFiles(
+ File recordingDir,
+ String testClassName,
+ int minFileCount = 2,
+ long timeoutMillis = 10_000L,
+ long pollIntervalMillis = 500L
+ ) {
+ long deadline = System.currentTimeMillis() + timeoutMillis
+ File[] recordingFiles = []
+ while (System.currentTimeMillis() < deadline) {
+ recordingFiles = recordingDir.listFiles({ file ->
+ isVideoFile(file) && file.name.contains(testClassName)
+ } as FileFilter) ?: [] as File[]
+
+ if (recordingFiles.length >= minFileCount) {
+ break
+ }
+ sleep(pollIntervalMillis)
+ }
+ return recordingFiles
+ }
}