github.com/mattermosttest/mattermost-server/v5@v5.0.0-20200917143240-9dfa12e121f9/app/plugin_shutdown_test.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package app 5 6 import ( 7 "testing" 8 "time" 9 10 "github.com/stretchr/testify/require" 11 ) 12 13 func TestPluginShutdownTest(t *testing.T) { 14 if testing.Short() { 15 t.Skip("skipping test to verify forced shutdown of slow plugin") 16 } 17 18 th := Setup(t) 19 defer th.TearDown() 20 21 tearDown, _, _ := SetAppEnvironmentWithPlugins(t, 22 []string{ 23 ` 24 package main 25 26 import ( 27 "github.com/mattermost/mattermost-server/v5/plugin" 28 ) 29 30 type MyPlugin struct { 31 plugin.MattermostPlugin 32 } 33 34 func main() { 35 plugin.ClientMain(&MyPlugin{}) 36 } 37 `, 38 ` 39 package main 40 41 import ( 42 "github.com/mattermost/mattermost-server/v5/plugin" 43 ) 44 45 type MyPlugin struct { 46 plugin.MattermostPlugin 47 } 48 49 func (p *MyPlugin) OnDeactivate() error { 50 c := make(chan bool) 51 <-c 52 53 return nil 54 } 55 56 func main() { 57 plugin.ClientMain(&MyPlugin{}) 58 } 59 `, 60 }, th.App, th.App.NewPluginAPI) 61 defer tearDown() 62 63 done := make(chan bool) 64 go func() { 65 defer close(done) 66 th.App.Srv().ShutDownPlugins() 67 }() 68 69 select { 70 case <-done: 71 case <-time.After(15 * time.Second): 72 require.Fail(t, "failed to force plugin shutdown after 10 seconds") 73 } 74 }