Merge pull request #8839 from r266-tech/codex/precontent-keepalive-clock-fixture

test(antigravity): stabilize repeated pre-content keepalives
This commit is contained in:
Wesley Liddick authored and GitHub committed 2026-11-27 17:06:11 +08:00
commit a2df5a86e9
1 file changed
+26 -21
@@ -10,6 +10,7 @@ import (
"net/http/httptest"
"strings"
"testing"
"testing/synctest"
"time"
"github.com/Wei-Shaw/sub2api/internal/config"
@@ -1232,27 +1233,31 @@ func TestAntigravityCompatHandlerPreContentKeepalive(t *testing.T) {
}
func TestAntigravityCompatHandlerRepeatsPreContentKeepalive(t *testing.T) {
svc := newAntigravityCompatService(config.GatewayConfig{
MaxLineSize: defaultMaxLineSize, StreamDataIntervalTimeout: 30, StreamKeepaliveInterval: 0,
}, nil)
c, recorder := newAntigravityCompatContext(http.MethodPost, "/", nil)
reader, pipeWriter := io.Pipe()
defer func() { _ = reader.Close() }()
resp := &http.Response{StatusCode: http.StatusOK, Body: reader}
done := make(chan error, 1)
go func() {
_, err := svc.handleAntigravityCompatStreamWithKeepaliveInterval(
c, resp, time.Now().Add(-15*time.Millisecond), "gemini-3.1-pro",
newAntigravityResponsesStreamAdapter("gemini-3.1-pro"), "test", 15*time.Millisecond, time.Second,
)
done <- err
}()
time.Sleep(55 * time.Millisecond)
require.NoError(t, pipeWriter.Close())
require.Error(t, <-done)
require.GreaterOrEqual(t, strings.Count(recorder.Body.String(), ": ping\n\n"), 3)
require.Contains(t, recorder.Body.String(), "event: error")
require.True(t, IsResponseCommitted(c))
synctest.Test(t, func(t *testing.T) {
svc := newAntigravityCompatService(config.GatewayConfig{
MaxLineSize: defaultMaxLineSize, StreamDataIntervalTimeout: 30, StreamKeepaliveInterval: 0,
}, nil)
c, recorder := newAntigravityCompatContext(http.MethodPost, "/", nil)
reader, pipeWriter := io.Pipe()
defer func() { _ = reader.Close() }()
resp := &http.Response{StatusCode: http.StatusOK, Body: reader}
done := make(chan error, 1)
go func() {
_, err := svc.handleAntigravityCompatStreamWithKeepaliveInterval(
c, resp, time.Now().Add(-15*time.Millisecond), "gemini-3.1-pro",
newAntigravityResponsesStreamAdapter("gemini-3.1-pro"), "test", 15*time.Millisecond, time.Second,
)
done <- err
}()
// Start the handler and scanner before advancing the virtual clock.
synctest.Wait()
time.Sleep(55 * time.Millisecond)
require.NoError(t, pipeWriter.Close())
require.Error(t, <-done)
require.GreaterOrEqual(t, strings.Count(recorder.Body.String(), ": ping\n\n"), 3)
require.Contains(t, recorder.Body.String(), "event: error")
require.True(t, IsResponseCommitted(c))
})
}
func TestAntigravityCompatHandlerPreContentDeadlineWithCommentOnlyStream(t *testing.T) {