Skip to content

Commit

Permalink
chore: Fixes broker 'failed to allocate' test 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 2ad32cf commit d58816a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 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
18 changes: 15 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,20 @@ 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()
serviceOffering := "csb-google-mysql"
servicePlan := "default"
serviceName := random.Name(random.WithPrefix(serviceOffering, servicePlan))
// CreateInstance can fail and can leave a service record (albeit a failed one) lying around.
// We can't delete service brokers that have serviceInstances, so we need to ensure the service instance
// is cleaned up regardless as to whether it wa successful. This is important when we use our own service broker
// (which can only have 5 instances at any time) to prevent subsequent test failures.
defer services.Delete(serviceName)
serviceInstance := services.CreateInstance(
serviceOffering,
servicePlan,
services.WithBroker(serviceBroker),
services.WithName(serviceName),
)

By("pushing the unstarted app twice")
appOne := apps.Push(apps.WithApp(apps.MySQL))
Expand Down Expand Up @@ -54,7 +66,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(servicePlan, serviceOffering, serviceBroker.Name))

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

By("creating a service")
serviceOffering := "csb-google-postgres"
servicePlan := "small"
serviceName := random.Name(random.WithPrefix(serviceOffering, servicePlan))
// CreateInstance can fail and can leave a service record (albeit a failed one) lying around.
// We can't delete service brokers that have serviceInstances, so we need to ensure the service instance
// is cleaned up regardless as to whether it wa successful. This is important when we use our own service broker
// (which can only have 5 instances at any time) to prevent subsequent test failures.
defer services.Delete(serviceName)
serviceInstance := services.CreateInstance(
"csb-google-postgres",
"small",
serviceOffering,
servicePlan,
services.WithBroker(serviceBroker),
services.WithName(serviceName),
)
defer serviceInstance.Delete()

By("pushing the unstarted app twice")
appOne := apps.Push(apps.WithApp(apps.PostgreSQL))
Expand Down Expand Up @@ -59,7 +67,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(servicePlan, serviceOffering, serviceBroker.Name))

By("upgrading service instance")
serviceInstance.Upgrade()
Expand Down
16 changes: 12 additions & 4 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,20 @@ var _ = Describe("UpgradeStorageTest", Label("storage"), func() {
defer serviceBroker.Delete()

By("creating a service")
serviceOffering := "csb-google-storage-bucket"
servicePlan := "default"
serviceName := random.Name(random.WithPrefix(serviceOffering, servicePlan))
// CreateInstance can fail and can leave a service record (albeit a failed one) lying around.
// We can't delete service brokers that have serviceInstances, so we need to ensure the service instance
// is cleaned up regardless as to whether it wa successful. This is important when we use our own service broker
// (which can only have 5 instances at any time) to prevent subsequent test failures.
defer services.Delete(serviceName)
serviceInstance := services.CreateInstance(
"csb-google-storage-bucket",
"default",
serviceOffering,
servicePlan,
services.WithBroker(serviceBroker),
services.WithName(serviceName),
)
defer serviceInstance.Delete()

By("pushing the unstarted app twice")
appOne := apps.Push(apps.WithApp(apps.Storage))
Expand All @@ -53,7 +61,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(servicePlan, serviceOffering, serviceBroker.Name))

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

By("creating a service instance")
serviceOffering := "csb-google-storage-bucket"
servicePlan := "default"
serviceName := random.Name(random.WithPrefix(serviceOffering, servicePlan))
defer services.Delete(serviceName)
// CreateInstance can fail and can leave a service record (albeit a failed one) lying around.
// We can't delete service brokers that have serviceInstances, so we need to ensure the service instance
// is cleaned up regardless as to whether it wa successful. This is important when we use our own service broker
// (which can only have 5 instances at any time) to prevent subsequent test failures.
serviceInstance := services.CreateInstance(
"csb-google-storage-bucket",
"default",
serviceOffering,
servicePlan,
services.WithBroker(broker),
services.WithName(serviceName),
)

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 d58816a

Please sign in to comment.