Skip to content

Commit

Permalink
test: fix mssql_db_failover_existing test
Browse files Browse the repository at this point in the history
- As well as testing the "existing" plan, it used another plan too,
  and therefore needed changes because of #922
- Also explicitly frees backing database on broker delete, which will
  hopefully reduce leaking of resources
  • Loading branch information
blgm committed Jan 30, 2025
1 parent 4919a9a commit d30059a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
7 changes: 6 additions & 1 deletion acceptance-tests/helpers/brokers/delete.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package brokers

import "csbbrokerpakazure/acceptance-tests/helpers/cf"
import (
"csbbrokerpakazure/acceptance-tests/helpers/cf"
)

func (b *Broker) Delete() {
// This is implicit when deleting the app, but sometimes that fails, so this ensures the resource is freed
cf.Run("unbind-service", b.Name, "csb-sql")

cf.Run("delete-service-broker", b.Name, "-f")
b.app.Delete()
}
4 changes: 2 additions & 2 deletions acceptance-tests/helpers/brokers/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/onsi/ginkgo/v2"
)

func (b Broker) env() []apps.EnvVar {
func (b *Broker) env() []apps.EnvVar {
var result []apps.EnvVar

for name, required := range map[string]bool{
Expand Down Expand Up @@ -51,6 +51,6 @@ func (b Broker) env() []apps.EnvVar {
return append(result, b.envExtras...)
}

func (b Broker) latestEnv() []apps.EnvVar {
func (b *Broker) latestEnv() []apps.EnvVar {
return readEnvrcServices(testpath.BrokerpakFile(".envrc"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

var _ = Describe("Upgrade and Update csb-azure-mssql-db-failover-group 'existing' plan", Label("mssql-db-failover-group-existing"), func() {
When("upgrading broker version", func() {

It("should continue to work", func() {
ctx := context.Background()

Expand All @@ -25,15 +24,11 @@ var _ = Describe("Upgrade and Update csb-azure-mssql-db-failover-group 'existing
Expect(err).NotTo(HaveOccurred())

DeferCleanup(func() {
GinkgoHelper()

By("deleting the created resource group and DB servers")
err := mssqlserver.Cleanup(ctx, serversConfig, subscriptionID)
Expect(err).NotTo(HaveOccurred())
Expect(mssqlserver.Cleanup(ctx, serversConfig, subscriptionID)).To(Succeed())
})

By("pushing latest released broker version")

serviceBroker := brokers.Create(
brokers.WithPrefix("csb-db-fo"),
brokers.WithSourceDir(releasedBuildDir),
Expand Down Expand Up @@ -109,8 +104,16 @@ var _ = Describe("Upgrade and Update csb-azure-mssql-db-failover-group 'existing
Expect(plans.ExistsAndAvailable(servicePlan, serviceOffering, serviceBroker.Name))
Expect(plans.ExistsAndAvailable(servicePlanExisting, serviceOffering, serviceBroker.Name))

By("upgrading previous services")
By("upgrading previous service, failing first time and then repeating")
// Because the "azurerm_sql_database" resource is deleted at the same time as the "azurerm_mssql_database"
// is created, the upgrade will fail due to using the same name in Azure
initialFogInstance.UpgradeExpectFailure()
// The deletion operation of the "azurerm_sql_database" resource should now have completed, so the
// "azurerm_mssql_database" can be created without a name conflict in Azure
initialFogInstance.Upgrade()

By("upgrading previous 'existing' service")
// Because the "existing" plan does not actually create a failover group, it should not fail to upgrade
existingFogInstance.Upgrade()

By("getting the previously set value using the second app")
Expand Down

0 comments on commit d30059a

Please sign in to comment.