Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 8babc3c

Browse files
authored
Fix creating sync subscription for the same method and path (#476) (#481)
1 parent 7944da3 commit 8babc3c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

libkv/subscription.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,13 @@ func isPathInConflict(existing, new string) bool {
265265
}
266266

267267
func newSubscriptionID(sub *subscription.Subscription) subscription.ID {
268-
raw := string(sub.Type) + "," + string(sub.EventType) + "," + string(sub.FunctionID) + "," + url.PathEscape(sub.Path) + "," + sub.Method
268+
var raw string
269+
if sub.Type == subscription.TypeAsync {
270+
raw = string(sub.Type) + "," + string(sub.EventType) + "," + string(sub.FunctionID) + "," + url.PathEscape(sub.Path) + "," + sub.Method
271+
} else {
272+
raw = string(sub.Type) + "," + string(sub.EventType) + "," + url.PathEscape(sub.Path) + "," + sub.Method
273+
}
274+
269275
return subscription.ID(base64.RawURLEncoding.EncodeToString([]byte(raw)))
270276
}
271277

libkv/subscription_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ func TestCreateSubscription(t *testing.T) {
2828
Type: subscription.TypeAsync, EventType: "user.created", FunctionID: "func", Path: "/", Method: "GET"}
2929
asyncEventPayload := []byte(`{"space":"default","name":"user.created"}`)
3030

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

0 commit comments

Comments
 (0)