Skip to content

Commit 99d1c4e

Browse files
committedApr 1, 2025·
probe server until connection can be ok in test
1 parent ac6c36b commit 99d1c4e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed
 

‎pkg/streamable_http/streamable_http_transport_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"sync"
1010
"testing"
11+
"time"
1112

1213
"github.com/stretchr/testify/assert"
1314
"github.com/stretchr/testify/require"
@@ -40,6 +41,13 @@ func TestStreamableHttpTransport(t *testing.T) {
4041
waitGroup.Wait()
4142
}()
4243

44+
// addresses race condition between server start and test start
45+
assert.EventuallyWithT(t, func(c *assert.CollectT) {
46+
resp, err := http.Get("http://localhost:8080/mcp")
47+
assert.NoError(c, err)
48+
defer func() { assert.NoError(c, resp.Body.Close()) }()
49+
}, 5*time.Second, 200*time.Millisecond)
50+
4351
// testing https://spec.modelcontextprotocol.io/specification/2025-03-26/basic/transports/#listening-for-messages-from-the-server
4452
// for now we only check that the server is responding with 405 as spec says it should when "long-running" SSE is not supported
4553
t.Run("GET is not yet supported", func(t *testing.T) {
@@ -188,7 +196,6 @@ func TestStreamableHttpTransport(t *testing.T) {
188196
require.Equal(t, "", resp.Header.Get("Content-Type"))
189197
require.Equal(t, ``, string(respBody))
190198
})
191-
192199
}
193200

194201
func TestMarshalServerError(t *testing.T) {

0 commit comments

Comments
 (0)
Please sign in to comment.