MCPcopy
hub / github.com/docker/docker-agent / TestSupervisor_StopConcurrent

Function TestSupervisor_StopConcurrent

pkg/tools/lifecycle/supervisor_test.go:802–830  ·  view source on GitHub ↗

TestSupervisor_StopConcurrent exercises the s.stopping guard: several goroutines call Stop concurrently while the watcher is live in sess.Wait(). All calls must return without error and observe a fully-shut-down supervisor.

(t *testing.T)

Source from the content-addressed store, hash-verified

800// sess.Wait(). All calls must return without error and observe a
801// fully-shut-down supervisor.
802func TestSupervisor_StopConcurrent(t *testing.T) {
803 t.Parallel()
804
805 sess := newFakeSession()
806 c := newScriptedConnector(scriptStep{session: sess})
807 s := lifecycle.New("test", c, lifecycle.Policy{})
808
809 assert.NilError(t, s.Start(t.Context()))
810 sess.waitParked(t)
811
812 const n = 4
813 errs := make(chan error, n)
814 var wg sync.WaitGroup
815 wg.Add(n)
816 for range n {
817 go func() {
818 defer wg.Done()
819 errs <- s.Stop(t.Context())
820 }()
821 }
822 wg.Wait()
823 close(errs)
824
825 for err := range errs {
826 assert.NilError(t, err)
827 }
828 assert.Check(t, is.Equal(s.State().State, lifecycle.StateStopped))
829 assert.Check(t, sess.waitDone.Load(), "a Stop returned before watcher's Wait() completed")
830}

Callers

nothing calls this directly

Calls 12

NewFunction · 0.92
newFakeSessionFunction · 0.85
newScriptedConnectorFunction · 0.85
ContextMethod · 0.80
waitParkedMethod · 0.80
CheckMethod · 0.80
LoadMethod · 0.80
StartMethod · 0.65
AddMethod · 0.65
StopMethod · 0.65
WaitMethod · 0.65
StateMethod · 0.65

Tested by

no test coverage detected