Skip to content

Commit b79d7a5

Browse files
authored
Merge pull request #15242 from apache/fix-recording-test
Fix flaky `PerTestRecordingSpec`
2 parents 4472d5d + 57d468e commit b79d7a5

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

grails-test-examples/geb/src/integration-test/groovy/org/demo/spock/PerTestRecordingSpec.groovy

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package org.demo.spock
2121

22+
import java.nio.file.Files
23+
2224
import spock.lang.Stepwise
2325

2426
import grails.plugin.geb.ContainerGebSpec
@@ -43,9 +45,6 @@ class PerTestRecordingSpec extends ContainerGebSpec {
4345
when: 'visiting another page than the previous test'
4446
to(UploadPage)
4547

46-
and: 'pausing to ensure the recorded file size is different'
47-
Thread.sleep(1000)
48-
4948
then: 'the page loads correctly'
5049
title == 'Upload Test'
5150
}
@@ -86,15 +85,12 @@ class PerTestRecordingSpec extends ContainerGebSpec {
8685
recordingFiles != null
8786
recordingFiles.length >= 2 // At least 2 files for the first two test methods
8887

89-
and: 'the recording files should have different content (different sizes)'
88+
and: 'the recording files should have different content'
9089
// Sort by last modified time to get the most recent files
9190
def sortedFiles = recordingFiles.sort { it.lastModified() }
9291
def secondLastFile = sortedFiles[sortedFiles.length - 2]
9392
def lastFile = sortedFiles[sortedFiles.length - 1]
94-
95-
// Files should have different sizes (allowing for small variations due to timing)
96-
long sizeDifference = Math.abs(lastFile.length() - secondLastFile.length())
97-
sizeDifference > 1000 // Expect at least 1KB difference
93+
Files.mismatch(lastFile.toPath(), secondLastFile.toPath()) != -1
9894
}
9995

10096
private static boolean isVideoFile(File file) {

0 commit comments

Comments
 (0)