mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
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
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/mlog"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
@@ -17,6 +18,9 @@ import (
|
||||
|
||||
const (
|
||||
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() {
|
||||
@@ -115,6 +119,8 @@ func installPluginFromUrl(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
client := c.App.HTTPService.MakeClient(true)
|
||||
client.Timeout = INSTALL_PLUGIN_FROM_URL_HTTP_REQUEST_TIMEOUT
|
||||
|
||||
resp, err := client.Get(downloadUrl)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("installPluginFromUrl", "api.plugin.install.download_failed.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/testlib"
|
||||
@@ -59,6 +60,24 @@ func TestPlugin(t *testing.T) {
|
||||
CheckNoError(t, resp)
|
||||
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
|
||||
pluginStored, err := th.App.FileExists("./plugins/" + manifest.Id + ".tar.gz")
|
||||
assert.Nil(t, err)
|
||||
|
||||
Reference in New Issue
Block a user