Skip to content

Commit

Permalink
Fix creating sync subscription for the same method and path (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthenw authored and Maciej Winnicki committed Jul 11, 2018
1 parent 5f94b72 commit 9c6a87d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion libkv/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,13 @@ func isPathInConflict(existing, new string) bool {
}

func newSubscriptionID(sub *subscription.Subscription) subscription.ID {
raw := string(sub.Type) + "," + string(sub.EventType) + "," + string(sub.FunctionID) + "," + url.PathEscape(sub.Path) + "," + sub.Method
var raw string
if sub.Type == subscription.TypeAsync {
raw = string(sub.Type) + "," + string(sub.EventType) + "," + string(sub.FunctionID) + "," + url.PathEscape(sub.Path) + "," + sub.Method
} else {
raw = string(sub.Type) + "," + string(sub.EventType) + "," + url.PathEscape(sub.Path) + "," + sub.Method
}

return subscription.ID(base64.RawURLEncoding.EncodeToString([]byte(raw)))
}

Expand Down
4 changes: 2 additions & 2 deletions libkv/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func TestCreateSubscription(t *testing.T) {
Type: subscription.TypeAsync, EventType: "user.created", FunctionID: "func", Path: "/", Method: "GET"}
asyncEventPayload := []byte(`{"space":"default","name":"user.created"}`)

syncKey := "default/c3luYyxodHRwLnJlcXVlc3QsZnVuYywlMkYsUE9TVA"
syncKey := "default/c3luYyxodHRwLnJlcXVlc3QsJTJGLFBPU1Q"
syncValue := []byte(
`{"space":"default","subscriptionId":"c3luYyxodHRwLnJlcXVlc3QsZnVuYywlMkYsUE9TVA",` +
`{"space":"default","subscriptionId":"c3luYyxodHRwLnJlcXVlc3QsJTJGLFBPU1Q",` +
`"type":"sync","eventType":"http.request","functionId":"func","path":"/","method":"POST"}`)
syncSub := &subscription.Subscription{
Type: subscription.TypeSync, EventType: "http.request", FunctionID: "func", Path: "/", Method: "POST"}
Expand Down

0 comments on commit 9c6a87d

Please sign in to comment.