Skip to content

Commit f71f9de

Browse files
markpollackspring-builds
authored andcommitted
Fix intermittent streaming response aggregation test failure (#4135)
Fix OpenAiChatClientIT.beanStreamOutputConverterRecords test that was failing intermittently when run as part of a test suite due to empty streaming chunks causing malformed JSON during aggregation. Changes: - Filter out empty/null text chunks before aggregation to prevent malformed JSON - Replace silent return with explicit test failure when streaming aggregation produces empty results - Add debugging logs to aid troubleshooting of streaming response issues The test now properly detects and reports streaming aggregation problems instead of silently skipping, improving CI reliability and error detection. Fixes #4134 Signed-off-by: Mark Pollack <[email protected]> (cherry picked from commit 85c194c)
1 parent 90a88ec commit f71f9de

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/client/OpenAiChatClientIT.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.springframework.util.MimeTypeUtils;
5757

5858
import static org.assertj.core.api.Assertions.assertThat;
59+
import static org.junit.jupiter.api.Assertions.fail;
5960

6061
@SpringBootTest(classes = OpenAiTestConfiguration.class)
6162
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+")
@@ -235,9 +236,18 @@ void beanStreamOutputConverterRecords() {
235236
.stream()
236237
.filter(cr -> cr.getResult() != null)
237238
.map(cr -> cr.getResult().getOutput().getText())
239+
.filter(text -> text != null && !text.trim().isEmpty()) // Filter out empty/null text
238240
.collect(Collectors.joining());
239241
// @formatter:on
240242

243+
// Add debugging to understand what text we're trying to parse
244+
logger.debug("Aggregated streaming text: {}", generationTextFromStream);
245+
246+
// Ensure we have valid JSON before attempting conversion
247+
if (generationTextFromStream.trim().isEmpty()) {
248+
fail("Empty aggregated text from streaming response - this indicates a problem with streaming aggregation");
249+
}
250+
241251
ActorsFilms actorsFilms = outputConverter.convert(generationTextFromStream);
242252

243253
logger.info("" + actorsFilms);

0 commit comments

Comments
 (0)