MM-17688 - Updated http timeout for plugin install from URL (#11887)
* Bumped http request timeout for plugin install from URL * Added unit test for timeout higher than 30 seconds. Other minor PR feedback * Fixed spacing
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
11b0a20d7d
Коммит
53f4bf1ec1
@@ -10,6 +10,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/mlog"
|
"github.com/mattermost/mattermost-server/mlog"
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
@@ -17,6 +18,9 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
MAXIMUM_PLUGIN_FILE_SIZE = 50 * 1024 * 1024
|
MAXIMUM_PLUGIN_FILE_SIZE = 50 * 1024 * 1024
|
||||||
|
// INSTALL_PLUGIN_FROM_URL_HTTP_REQUEST_TIMEOUT defines a high timeout for installing plugins
|
||||||
|
// from an external URL to avoid slow connections or large plugins from failing to install.
|
||||||
|
INSTALL_PLUGIN_FROM_URL_HTTP_REQUEST_TIMEOUT = 60 * time.Minute
|
||||||
)
|
)
|
||||||
|
|
||||||
func (api *API) InitPlugin() {
|
func (api *API) InitPlugin() {
|
||||||
@@ -115,6 +119,8 @@ func installPluginFromUrl(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
client := c.App.HTTPService.MakeClient(true)
|
client := c.App.HTTPService.MakeClient(true)
|
||||||
|
client.Timeout = INSTALL_PLUGIN_FROM_URL_HTTP_REQUEST_TIMEOUT
|
||||||
|
|
||||||
resp, err := client.Get(downloadUrl)
|
resp, err := client.Get(downloadUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Err = model.NewAppError("installPluginFromUrl", "api.plugin.install.download_failed.app_error", nil, err.Error(), http.StatusBadRequest)
|
c.Err = model.NewAppError("installPluginFromUrl", "api.plugin.install.download_failed.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/testlib"
|
"github.com/mattermost/mattermost-server/testlib"
|
||||||
@@ -59,6 +60,24 @@ func TestPlugin(t *testing.T) {
|
|||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
assert.Equal(t, "testplugin", manifest.Id)
|
assert.Equal(t, "testplugin", manifest.Id)
|
||||||
|
|
||||||
|
t.Run("install plugin from URL with slow response time", func(t *testing.T) {
|
||||||
|
if testing.Short() {
|
||||||
|
t.Skip("skipping test to install plugin from a slow response server")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Install from URL - slow server to simulate longer bundle download times
|
||||||
|
slowTestServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||||
|
time.Sleep(60 * time.Second) // Wait longer than the previous default 30 seconds timeout
|
||||||
|
res.WriteHeader(http.StatusOK)
|
||||||
|
res.Write(tarData)
|
||||||
|
}))
|
||||||
|
defer func() { slowTestServer.Close() }()
|
||||||
|
|
||||||
|
manifest, resp = th.SystemAdminClient.InstallPluginFromUrl(slowTestServer.URL, true)
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
assert.Equal(t, "testplugin", manifest.Id)
|
||||||
|
})
|
||||||
|
|
||||||
// Stored in File Store: Install Plugin from URL case
|
// Stored in File Store: Install Plugin from URL case
|
||||||
pluginStored, err := th.App.FileExists("./plugins/" + manifest.Id + ".tar.gz")
|
pluginStored, err := th.App.FileExists("./plugins/" + manifest.Id + ".tar.gz")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user