From bd7ac67eeb8d2be8171742d298d792d7c683f77e Mon Sep 17 00:00:00 2001 From: Ales Stimec Date: Wed, 18 Dec 2024 17:16:11 +0100 Subject: [PATCH] fix - remove force destroy of application offers. --- internal/juju/offers.go | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/internal/juju/offers.go b/internal/juju/offers.go index b8428417..d31de998 100644 --- a/internal/juju/offers.go +++ b/internal/juju/offers.go @@ -195,26 +195,30 @@ func (c offersClient) DestroyOffer(input *DestroyOfferInput) error { return err } - forceDestroy := false - //This code loops until it detects 0 connections in the offer or 3 minutes elapses - if len(offer.Connections) > 0 { - end := time.Now().Add(5 * time.Minute) - for ok := true; ok; ok = len(offer.Connections) > 0 { - //if we have been failing to destroy offer for 5 minutes then force destroy - //TODO: investigate cleaner solution (acceptance tests fail even if timeout set to 20m) - if time.Now().After(end) { - forceDestroy = true - break - } - time.Sleep(10 * time.Second) - offer, err = client.ApplicationOffer(input.OfferURL) - if err != nil { - return err + checkConnections := func() error { + //This code loops until it detects 0 connections in the offer or 3 minutes elapses + if len(offer.Connections) > 0 { + end := time.Now().Add(5 * time.Minute) + for ok := true; ok; ok = len(offer.Connections) > 0 { + //if we have been failing to destroy offer for 5 minutes then fail on destroy + if time.Now().After(end) { + return fmt.Errorf("offer %q has remaining connections", input.OfferURL) + } + time.Sleep(10 * time.Second) + offer, err = client.ApplicationOffer(input.OfferURL) + if err != nil { + return err + } } } + return nil + } + + if err = checkConnections(); err != nil { + return err } - err = client.DestroyOffers(forceDestroy, input.OfferURL) + err = client.DestroyOffers(false, input.OfferURL) if err != nil { return err }