mirror of
https://github.com/mattermost/mattermost.git
synced 2026-04-15 22:12:19 -04:00
Previously, we relied on the plugin to close the DB connections on shutdown. While this keeps the code simple, there is no guarantee that the plugin author will remember to close the DB. In that case, it's better to track the connections from the server side and close them in case they weren't closed already. This complicates the API slightly, but it's a price we need to pay. https://mattermost.atlassian.net/browse/MM-56402 ```release-note We close any remaining unclosed DB RPC connections after a plugin shuts down. ``` Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com> Co-authored-by: Mattermost Build <build@mattermost.com>
40 lines
876 B
Go
40 lines
876 B
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package app
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestConnCreateTimeout(t *testing.T) {
|
|
th := Setup(t)
|
|
defer th.TearDown()
|
|
|
|
*th.App.Config().SqlSettings.QueryTimeout = 0
|
|
|
|
d := NewDriverImpl(th.Server)
|
|
_, err := d.Conn(true)
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestShutdownPluginConns(t *testing.T) {
|
|
th := Setup(t)
|
|
defer th.TearDown()
|
|
|
|
d := NewDriverImpl(th.Server)
|
|
_, err := d.ConnWithPluginID(true, "plugin1")
|
|
require.NoError(t, err)
|
|
_, err = d.ConnWithPluginID(true, "plugin2")
|
|
require.NoError(t, err)
|
|
_, err = d.ConnWithPluginID(true, "plugin1")
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, d.connMap, 3)
|
|
d.ShutdownConns("plugin1")
|
|
require.Len(t, d.connMap, 1)
|
|
d.ShutdownConns("plugin2")
|
|
require.Len(t, d.connMap, 0)
|
|
}
|