[MM-53269] Add configuration setting for integration requests timeout (#23805)

Co-authored-by: Michael Kochell <6913320+mickmister@users.noreply.github.com>
Этот коммит содержится в:
Ben Schumacher
2023-12-18 16:07:00 +01:00
коммит произвёл GitHub
родитель 7874daa6f7
Коммит 1fdddfe678
20 изменённых файлов: 343 добавлений и 136 удалений

Просмотреть файл

@@ -19,7 +19,6 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/v8/channels/testlib"
"github.com/mattermost/mattermost/server/v8/platform/services/httpservice"
)
func TestCreateIncomingWebhookForChannel(t *testing.T) {
@@ -787,7 +786,7 @@ func TestDoOutgoingWebhookRequest(t *testing.T) {
resp, err := th.App.doOutgoingWebhookRequest(server.URL, strings.NewReader(""), "application/json")
require.NoError(t, err)
assert.NotNil(t, resp)
require.NotNil(t, resp)
assert.NotNil(t, resp.Text)
assert.Equal(t, "Hello, World!", *resp.Text)
})
@@ -835,16 +834,34 @@ func TestDoOutgoingWebhookRequest(t *testing.T) {
defer server.Close()
defer close(releaseHandler)
th.App.HTTPService().(*httpservice.HTTPServiceImpl).RequestTimeout = 500 * time.Millisecond
defer func() {
th.App.HTTPService().(*httpservice.HTTPServiceImpl).RequestTimeout = httpservice.RequestTimeout
}()
th.App.UpdateConfig(func(cfg *model.Config) {
cfg.ServiceSettings.OutgoingIntegrationRequestsTimeout = model.NewInt64(1)
})
_, err := th.App.doOutgoingWebhookRequest(server.URL, strings.NewReader(""), "application/json")
require.Error(t, err)
require.IsType(t, &url.Error{}, err)
})
t.Run("with a slow response, long timeout configured", func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(1 * time.Second)
io.Copy(w, strings.NewReader(`{"text": "Hello, World!"}`))
}))
defer server.Close()
th.App.UpdateConfig(func(cfg *model.Config) {
cfg.ServiceSettings.OutgoingIntegrationRequestsTimeout = model.NewInt64(2)
})
resp, err := th.App.doOutgoingWebhookRequest(server.URL, strings.NewReader(""), "application/json")
require.NoError(t, err)
require.NotNil(t, resp)
assert.NotNil(t, resp.Text)
assert.Equal(t, "Hello, World!", *resp.Text)
})
t.Run("without response", func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
}))