Chore: Avoid stopping plugin (#74654)

This commit is contained in:
Andres Martinez Gotor
2023-09-12 10:34:12 +02:00
committed by GitHub
parent 8cb93bf3e7
commit 1a8a19a9ed
3 changed files with 60 additions and 31 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"sync"
"testing"
"time"
"github.com/stretchr/testify/require"
@ -71,6 +72,31 @@ func TestProcessManager_Start(t *testing.T) {
})
}
})
t.Run("Won't stop the plugin if the context is cancelled", func(t *testing.T) {
bp := fakes.NewFakeBackendPlugin(true)
p := createPlugin(t, bp, func(plugin *plugins.Plugin) {
plugin.Backend = true
})
tickerDuration := keepPluginAliveTickerDuration
keepPluginAliveTickerDuration = 1 * time.Millisecond
defer func() {
keepPluginAliveTickerDuration = tickerDuration
}()
m := &Service{}
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
err := m.Start(ctx, p)
require.NoError(t, err)
require.Equal(t, 1, bp.StartCount)
cancel()
<-bp.ExitedCheckDoneOrStopped
require.False(t, p.Exited())
require.Equal(t, 0, bp.StopCount)
})
}
func TestProcessManager_Stop(t *testing.T) {