Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send original update request back in response #1480

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions internal/internal_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type (
updateProtocol struct {
protoInstanceID string
clientIdentity string
initialRequest *updatepb.Request
requestMsgID string
requestSeqID int64
scheduleUpdate func(name string, id string, args *commonpb.Payloads, header *commonpb.Header, callbacks UpdateCallbacks)
Expand Down Expand Up @@ -134,15 +135,16 @@ func (up *updateProtocol) requireState(action string, valid ...updateState) {
}

func (up *updateProtocol) HandleMessage(msg *protocolpb.Message) error {
var req updatepb.Request
if err := msg.Body.UnmarshalTo(&req); err != nil {
var request updatepb.Request
if err := msg.Body.UnmarshalTo(&request); err != nil {
return err
}
up.initialRequest = &request
up.requireState("update request", updateStateNew)
up.requestMsgID = msg.GetId()
up.requestSeqID = msg.GetEventId()
input := req.GetInput()
up.scheduleUpdate(input.GetName(), req.GetMeta().GetUpdateId(), input.GetArgs(), input.GetHeader(), up)
input := up.initialRequest.GetInput()
up.scheduleUpdate(input.GetName(), up.initialRequest.GetMeta().GetUpdateId(), input.GetArgs(), input.GetHeader(), up)
up.state = updateStateRequestInitiated
return nil
}
Expand All @@ -157,8 +159,11 @@ func (up *updateProtocol) Accept() {
Body: protocol.MustMarshalAny(&updatepb.Acceptance{
AcceptedRequestMessageId: up.requestMsgID,
AcceptedRequestSequencingEventId: up.requestSeqID,
AcceptedRequest: up.initialRequest,
}),
}, withExpectedEventPredicate(up.checkAcceptedEvent))
// Stop holding a reference to the initial request to allow it to be GCed
up.initialRequest = nil
up.state = updateStateAccepted
}

Expand All @@ -171,8 +176,8 @@ func (up *updateProtocol) Reject(err error) {
Body: protocol.MustMarshalAny(&updatepb.Rejection{
RejectedRequestMessageId: up.requestMsgID,
RejectedRequestSequencingEventId: up.requestSeqID,
RejectedRequest: up.initialRequest,
Failure: up.env.GetFailureConverter().ErrorToFailure(err),
// RejectedRequest field no longer read by server - will be removed from API soon
}),
})
up.state = updateStateCompleted
Expand Down
4 changes: 2 additions & 2 deletions internal/internal_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ func TestAcceptedEventPredicate(t *testing.T) {

var acptmsg updatepb.Acceptance
require.NoError(t, env.outbox[0].msg.Body.UnmarshalTo(&acptmsg))
require.Nil(t, acptmsg.AcceptedRequest,
"do not send the original request back - this field will be removed soon")
require.EqualExportedValues(t, &request, acptmsg.AcceptedRequest,
"Sent the original request back in the accepted message")

pred := env.outbox[0].eventPredicate
for _, tc := range [...]struct {
Expand Down
Loading