ktorio / ktorio/ktor

Flaky test: TestApplicationTest.testStreamingResponse race condition on mingwX64

Open
#5,476 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
14.5k
Forks
1.3k
Avg merge
2d 13h
Merged PRs (30d)
49

Description

## Root cause

The test assumes strict alternating message ordering between server-side writes and client-side reads via a Channel. This ordering is not guaranteed because the server coroutine and client coroutine may be scheduled differently on different platforms.

Error on mingwX64:
```
kotlin.AssertionError: Expected , actual <[Client] Test 1>.
```

Also seen on JVM on the `release/3.x` base branch (build 412674).

## Suggested fix

The test design relies on timing-dependent interleaving. Consider using explicit synchronization (e.g., a second channel or barrier) to enforce the expected ordering, or restructure the test to not depend on strict interleaving.

File: `ktor-server/ktor-server-test-host/common/test/TestApplicationTest.kt`

Observed in PR #5465 and on `release/3.x` base branch.

Contributor guide

Open the contributing guide

Research direction

Start with ktor-server/ktor-server-test-host/common/test/TestApplicationTest.kt and inspect TestApplicationTest.testStreamingResponse, focusing on the Channel-based server writes and client reads. Reproduce or run the test on mingwX64 or JVM, then verify it no longer depends on timing-specific message interleaving and passes consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.