From 24357b9a0cc8c7a7ddc70b0833c59f0e67cce824 Mon Sep 17 00:00:00 2001 From: NiniOak Date: Mon, 14 Aug 2023 23:11:43 +0000 Subject: [PATCH] backport of commit 59bfc81d49a905480329a38c0d8d0109ea100d3e --- .../consul-container/libs/service/connect.go | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/test/integration/consul-container/libs/service/connect.go b/test/integration/consul-container/libs/service/connect.go index 70060f19e1fd..cf8b897162ad 100644 --- a/test/integration/consul-container/libs/service/connect.go +++ b/test/integration/consul-container/libs/service/connect.go @@ -64,14 +64,17 @@ func (g ConnectContainer) GetPort(port int) (int, error) { } func (g ConnectContainer) Restart() error { - _, err := g.GetStatus() - if err != nil { - return fmt.Errorf("error fetching sidecar container state %s", err) + var deferClean utils.ResettableDefer + defer deferClean.Execute() + + if utils.FollowLog { + if err := g.container.StopLogProducer(); err != nil { + return fmt.Errorf("stopping log producer: %w", err) + } } fmt.Printf("Stopping container: %s\n", g.GetName()) - err = g.container.Stop(g.ctx, nil) - + err := g.container.Stop(g.ctx, nil) if err != nil { return fmt.Errorf("error stopping sidecar container %s", err) } @@ -81,6 +84,17 @@ func (g ConnectContainer) Restart() error { if err != nil { return fmt.Errorf("error starting sidecar container %s", err) } + + if utils.FollowLog { + if err := g.container.StartLogProducer(g.ctx); err != nil { + return fmt.Errorf("starting log producer: %w", err) + } + g.container.FollowOutput(&LogConsumer{}) + deferClean.Add(func() { + _ = g.container.StopLogProducer() + }) + } + return nil }