Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Implement re-sent provision requests correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
pmorie committed Mar 13, 2017
1 parent ce716b8 commit b7978d5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
19 changes: 13 additions & 6 deletions pkg/brokerapi/fakeserver/fake_broker_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ func NewFakeBrokerServer() *FakeBrokerServer {

}

// ProvisionReaction represents a reaction that the fake server should make to
// a provision request.
type ProvisionReaction struct {
Status int
Response *brokerapi.CreateServiceInstanceResponse
Expand Down Expand Up @@ -209,12 +211,11 @@ func (f *FakeBrokerServer) lastOperationHandler(w http.ResponseWriter, r *http.R
State: brokerapi.StateInProgress,
})
} else {
// TODO: add instance to list of active instances
// if activeProvision.AsyncResult == brokerapi.StateSucceeded
// f.ActiveInstances =
f.ActiveInstances[id] = f.OriginatingProvisionRequests[id]
delete(f.ActiveProvisions, req.Operation)
delete(f.OriginatingProvisionRequests, id)

glog.Infof("(provision) Returning response status %v to last_operation request %v", activeProvision.AsyncResult, req.Operation)
glog.Infof("Returning response status %v to last_operation request %v", activeProvision.AsyncResult, req.Operation)

util.WriteResponse(w, http.StatusOK, brokerapi.LastOperationResponse{
State: activeProvision.AsyncResult,
Expand Down Expand Up @@ -318,8 +319,14 @@ func (f *FakeBrokerServer) provisionHandler(w http.ResponseWriter, r *http.Reque
return
}

// record the state of the async reaction
f.ActiveProvisions[reaction.Operation] = reaction
// record the state of the async reaction, if it is destined to succeed
if reaction.Status == http.StatusAccepted {
f.ActiveProvisions[reaction.Operation] = reaction
}

if reaction.AsyncResult == brokerapi.StateSucceeded {
f.OriginatingProvisionRequests[id] = *req
}

util.WriteResponse(w, reaction.Status, &brokerapi.CreateServiceInstanceResponse{
Operation: reaction.Operation,
Expand Down
23 changes: 15 additions & 8 deletions pkg/brokerapi/openservicebroker/open_service_broker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,12 @@ func TestDeprovisionInstanceAcceptedSuccessAsynchronous(t *testing.T) {
defer fbs.Stop()

fbs.ProvisionReactions[testServiceInstanceID] = fakeserver.ProvisionReaction{
Status: http.StatusCreated,
}

c := NewClient(testBrokerName, url, "", "")
if _, err := c.CreateServiceInstance(testServiceInstanceID, &brokerapi.CreateServiceInstanceRequest{}); err != nil {
t.Fatal(err.Error())
Status: http.StatusAccepted,
Async: true,
Operation: "12345",
Polls: 2,
AsyncResult: brokerapi.StateSucceeded,
}

fbs.DeprovisionReactions[testServiceInstanceID] = fakeserver.DeprovisionReaction{
Status: http.StatusAccepted,
Async: true,
Expand All @@ -248,12 +246,21 @@ func TestDeprovisionInstanceAcceptedSuccessAsynchronous(t *testing.T) {
AsyncResult: brokerapi.StateSucceeded,
}

deleteReq := brokerapi.DeleteServiceInstanceRequest{
req := brokerapi.CreateServiceInstanceRequest{
AcceptsIncomplete: true,
ServiceID: "014-01840",
PlanID: "54331",
}
c := NewClient(testBrokerName, url, "", "")
if _, err := c.CreateServiceInstance(testServiceInstanceID, &req); err != nil {
t.Fatal(err.Error())
}

deleteReq := brokerapi.DeleteServiceInstanceRequest{
AcceptsIncomplete: true,
ServiceID: "014-01840",
PlanID: "54331",
}
if err := c.DeleteServiceInstance(testServiceInstanceID, &deleteReq); err != nil {
t.Fatal(err.Error())
}
Expand Down

0 comments on commit b7978d5

Please sign in to comment.