Skip to content

Commit

Permalink
refactor test
Browse files Browse the repository at this point in the history
- reorder expectations for log output, we noticed that they we're
  somewhat badly organized

- fix CI flake:
  CI runs tests in parallel and they will flake when the dir that
  contains the lockfiles will be cleaned up prematurely.
  • Loading branch information
nouseforaname committed Sep 10, 2024
1 parent f7d4131 commit 51f1ac2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func startServer(registry pakBroker.BrokerRegistry, db *sql.DB, brokerapi http.H
logger.Info("received SIGTERM, server is shutting down gracefully allowing for in flight work to finish")
defer shutdownRelease()
for store.LockFilesExist() {
logger.Info("draining csb instance")
logger.Info("draining csb in progress")
time.Sleep(time.Second * 1)
}
logger.Info("draining complete")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ terraform {
}
resource "null_resource" "sleeper" {
provisioner "local-exec" {
command = "sleep 5"
command = "sleep 10"
}
}
resource "random_uuid" "random" {}
Expand Down
23 changes: 16 additions & 7 deletions integrationtest/termination_recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/pivotal-cf/brokerapi/v11/domain"
)

var _ = Describe("Recovery From Broker Termination", func() {
var _ = Describe("Recovery From Broker Termination", Ordered, func() {
const (
serviceOfferingGUID = "083f2884-eb7b-11ee-96c7-174e35671015"
servicePlanGUID = "0d953850-eb7b-11ee-bb2c-8ba95d780d82"
Expand All @@ -27,13 +27,15 @@ var _ = Describe("Recovery From Broker Termination", func() {
stdout *Buffer
stderr *Buffer
)
AfterAll(func() {
os.RemoveAll("/tmp/csb/")
})
Describe("running csb on a VM", func() {
BeforeEach(func() {
brokerpak = must(packer.BuildBrokerpak(csb, fixtures("termination-recovery")))

stdout = NewBuffer()
stderr = NewBuffer()
os.RemoveAll("/tmp/csb/")
broker = must(testdrive.StartBroker(csb, brokerpak, database, testdrive.WithOutputs(stdout, stderr)))

DeferCleanup(func() {
Expand All @@ -57,14 +59,22 @@ var _ = Describe("Recovery From Broker Termination", func() {

By("logging a message")
Eventually(stdout).Should(Say("received SIGTERM"))
Eventually(stdout).Should(Say("draining csb in progress"))
lockFile, err := os.Stat(fmt.Sprintf("/tmp/csb/tf_%s_", instanceGUID))
Expect(err).ToNot(HaveOccurred())
Expect(lockFile).ToNot(BeNil())

By("ensuring that the broker rejects requests")
Expect(broker.Client.LastOperation(instanceGUID, uuid.NewString()).Error).To(HaveOccurred())

Eventually(stdout, time.Minute).Should(Say("draining csb"))
Eventually(stdout, time.Minute).Should(Say(fmt.Sprintf("successfully applied tf:%s", instanceGUID)))
Eventually(stdout, time.Minute).Should(Say("draining complete"))
Eventually(stdout, time.Minute).ShouldNot(Say("shutdown error"))
// Fun stuff, do not optimize this with a SatisfyAll().. The relevant part of the docs is:
// When Say succeeds, it fast forwards the gbytes.Buffer's read cursor to just after the successful match.
// meaning if below lines, will be partially matched at first attempt, no further attempt can succeed because we
// forwarded past the location of the initial first match.

Eventually(stdout, time.Second*20).Should(Say(fmt.Sprintf("successfully stored state for tf:%s:", instanceGUID)))
Eventually(stdout, time.Second*20).Should(Say("draining complete"))
Consistently(stderr, time.Second*20).ShouldNot(Say("shutdown error"))

broker = must(testdrive.StartBroker(csb, brokerpak, database, testdrive.WithOutputs(stdout, stderr)))

Expand All @@ -85,7 +95,6 @@ var _ = Describe("Recovery From Broker Termination", func() {

stdout = NewBuffer()
stderr = NewBuffer()
os.RemoveAll("/tmp/csb/")
broker = must(testdrive.StartBroker(csb, brokerpak, database, testdrive.WithOutputs(stdout, stderr), testdrive.WithEnv("CF_INSTANCE_GUID=dcfa061e-c0e3-4237-a805-734578347393")))

DeferCleanup(func() {
Expand Down
3 changes: 2 additions & 1 deletion pkg/providers/tf/deployment_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ func (d *DeploymentManager) MarkOperationFinished(deployment *storage.TerraformD
"deploymentID": deployment.ID,
"message": deployment.LastOperationMessage,
})
} else {
d.logger.Info(fmt.Sprintf("successfully stored state for %s", deployment.ID))
}
d.logger.Info(fmt.Sprintf("successfully applied %s", deployment.ID))
return d.store.RemoveLockFile(deployment.ID)
}

Expand Down

0 comments on commit 51f1ac2

Please sign in to comment.