Skip to content

Commit

Permalink
chore: Fixes broker 'failed to allocate errors'
Browse files Browse the repository at this point in the history
We can only have 5 instances of our test broker running. Tests that use the test broker can see 'failed to allocate' errors.
This is because in the case of a failed creation of a service in our tests will fail to clean up the test broker, causing other test runs to fail.
  • Loading branch information
ifindlay-cci committed Jan 3, 2025
1 parent 1aa9ed1 commit 74ea8aa
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
8 changes: 6 additions & 2 deletions acceptance-tests/helpers/services/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import (
)

func (s *ServiceInstance) Delete() {
Delete(s.Name)
}

func Delete(name string) {
switch cf.Version() {
case cf.VersionV8:
deleteWithWait(s.Name)
deleteWithWait(name)
default:
deleteWithPoll(s.Name)
deleteWithPoll(name)
}
}

Expand Down
11 changes: 8 additions & 3 deletions acceptance-tests/upgrade/update_and_upgrade_mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ var _ = Describe("UpgradeMYSQLTest", Label("mysql"), func() {
defer serviceBroker.Delete()

By("creating a service instance")
serviceInstance := services.CreateInstance("csb-google-mysql", "default", services.WithBroker(serviceBroker))
defer serviceInstance.Delete()
// We have to create the defered delete *before* creating the service.
// If there is an error in a creating the service then services.CreateInstance won't return
// and we may have a failed creation in the database attached to the broker we just created,
// preventing deleting the broker. Calling `cf delete-service` still needs to be done.
serviceName := "csb-google-mysql"
services.Delete(serviceName)
serviceInstance := services.CreateInstance(serviceName, "default", services.WithBroker(serviceBroker))

By("pushing the unstarted app twice")
appOne := apps.Push(apps.WithApp(apps.MySQL))
Expand Down Expand Up @@ -54,7 +59,7 @@ var _ = Describe("UpgradeMYSQLTest", Label("mysql"), func() {
serviceBroker.UpdateBroker(developmentBuildDir)

By("validating that the instance plan is still active")
Expect(plans.ExistsAndAvailable("default", "csb-google-mysql", serviceBroker.Name))
Expect(plans.ExistsAndAvailable("default", serviceName, serviceBroker.Name))

By("upgrading service instance")
serviceInstance.Upgrade()
Expand Down
11 changes: 8 additions & 3 deletions acceptance-tests/upgrade/update_and_upgrade_postgresql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ var _ = Describe("UpgradePostgreSQLTest", Label("postgresql"), func() {
)
defer serviceBroker.Delete()

// We have to start the defered delete *before* creating the service.
// If there is an error in a creating the service then services.CreateInstance won't return
// and we may have a failed creation in the database attached to the broker we just created,
// preventing deleting the broker. Calling `cf delete-service` still needs to be done.
serviceName := "csb-google-postgres"
defer services.Delete(serviceName)
By("creating a service")
serviceInstance := services.CreateInstance(
"csb-google-postgres",
serviceName,
"small",
services.WithBroker(serviceBroker),
)
defer serviceInstance.Delete()

By("pushing the unstarted app twice")
appOne := apps.Push(apps.WithApp(apps.PostgreSQL))
Expand Down Expand Up @@ -59,7 +64,7 @@ var _ = Describe("UpgradePostgreSQLTest", Label("postgresql"), func() {
serviceBroker.UpdateBroker(developmentBuildDir)

By("validating that the instance plan is still active")
Expect(plans.ExistsAndAvailable("small", "csb-google-postgres", serviceBroker.Name))
Expect(plans.ExistsAndAvailable("small", serviceName, serviceBroker.Name))

By("upgrading service instance")
serviceInstance.Upgrade()
Expand Down
9 changes: 7 additions & 2 deletions acceptance-tests/upgrade/update_and_upgrade_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ var _ = Describe("UpgradeStorageTest", Label("storage"), func() {
defer serviceBroker.Delete()

By("creating a service")
// We have to create the defered delete *before* creating the service.
// If there is an error in a creating the service then services.CreateInstance won't return
// and we may have a failed creation in the database attached to the broker we just created,
// preventing deleting the broker. Calling `cf delete-service` still needs to be done.
serviceName := "csb-google-storage-bucket"
defer services.Delete(serviceName)
serviceInstance := services.CreateInstance(
"csb-google-storage-bucket",
"default",
services.WithBroker(serviceBroker),
)
defer serviceInstance.Delete()

By("pushing the unstarted app twice")
appOne := apps.Push(apps.WithApp(apps.Storage))
Expand All @@ -53,7 +58,7 @@ var _ = Describe("UpgradeStorageTest", Label("storage"), func() {
serviceBroker.UpdateBroker(developmentBuildDir)

By("validating that the instance plan is still active")
Expect(plans.ExistsAndAvailable("default", "csb-google-storage-bucket", serviceBroker.Name))
Expect(plans.ExistsAndAvailable("default", serviceName, serviceBroker.Name))

By("upgrading service instance")
serviceInstance.Upgrade()
Expand Down
10 changes: 7 additions & 3 deletions acceptance-tests/withoutcredhub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ var _ = Describe("Without CredHub", Label("withoutcredhub"), func() {
defer broker.Delete()

By("creating a service instance")
// We have to create the defered delete *before* creating the service.
// If there is an error in a creating the service then services.CreateInstance won't return
// and we may have a failed creation in the database attached to the broker we just created,
// preventing deleting the broker. Calling `cf delete-service` still needs to be done.
serviceName := "csb-google-storage-bucket"
defer services.Delete(serviceName)
serviceInstance := services.CreateInstance(
"csb-google-storage-bucket",
serviceName,
"default",
services.WithBroker(broker),
)

defer serviceInstance.Delete()

By("pushing the unstarted app")
app := apps.Push(apps.WithApp(apps.Storage))
defer apps.Delete(app)
Expand Down

0 comments on commit 74ea8aa

Please sign in to comment.