Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,36 @@ class PerTestRecordingSpec extends ContainerGebSpec {
long pollIntervalMillis = 500L
) {
long deadline = System.currentTimeMillis() + timeoutMillis
List<File> recordingFiles = []
Map<String, Long> previousSizes = [:]
Comment thread
borinquenkid marked this conversation as resolved.
Outdated
List<File> readyFiles = []
while (System.currentTimeMillis() < deadline) {
// Re-scan on every poll: the directory and the files both appear
// asynchronously while the recording container flushes videos.
recordingFiles = currentRunRecordingDirs(baseRecordingDir).collectMany { File dir ->
List<File> candidateFiles = currentRunRecordingDirs(baseRecordingDir).collectMany { File dir ->
(dir.listFiles({ File file ->
isVideoFile(file) && file.name.contains(testClassName)
} as FileFilter) ?: new File[0]) as List<File>
}
Map<String, Long> currentSizes = candidateFiles.collectEntries { File file ->
[(file.absolutePath): file.length()]
}

// Testcontainers copies each recording with a plain, non-atomic
// stream copy, so a file can appear in the directory scan above
// while still 0 bytes or only partially written. Only treat a
// recording as ready once its size is non-zero and unchanged
// since the previous poll, which means the copy has finished.
readyFiles = candidateFiles.findAll { File file ->
long size = currentSizes[file.absolutePath]
size > 0 && previousSizes[file.absolutePath] == size
}
Comment thread
borinquenkid marked this conversation as resolved.
Outdated

if (recordingFiles.size() >= minFileCount) {
if (readyFiles.size() >= minFileCount) {
break
}
previousSizes = currentSizes
sleep(pollIntervalMillis)
}
return recordingFiles
return readyFiles
Comment thread
borinquenkid marked this conversation as resolved.
Outdated
}
}
Loading