diff --git a/server/backend/sync/pubsub.go b/server/backend/sync/pubsub.go index 23d3c6b6a..7f6b24402 100644 --- a/server/backend/sync/pubsub.go +++ b/server/backend/sync/pubsub.go @@ -22,20 +22,23 @@ import ( "github.com/yorkie-team/yorkie/pkg/document/time" ) -type eventTypes map[string]struct{} +// EventTypes stores the subscribed event types. +type EventTypes map[string]struct{} -func (s eventTypes) add(t string) { +// Add adds the given type to EventTypes. +func (s EventTypes) Add(t string) { s[t] = struct{}{} } -func (s eventTypes) remove(t string) { +// Remove removes the given type from EventTypes. +func (s EventTypes) Remove(t string) { delete(s, t) } // Subscription represents a subscription of a subscriber to documents. type Subscription struct { id string - types eventTypes + types EventTypes subscriber *time.ActorID closed bool events chan Event @@ -45,7 +48,7 @@ type Subscription struct { func NewSubscription(subscriber *time.ActorID) *Subscription { return &Subscription{ id: xid.New().String(), - types: make(eventTypes), + types: make(EventTypes), subscriber: subscriber, events: make(chan Event, 1), } @@ -57,18 +60,18 @@ func (s *Subscription) ID() string { } // Types returns the subscribed event type list. -func (s *Subscription) Types() eventTypes { +func (s *Subscription) Types() EventTypes { return s.types } // AddType adds the event type to the subscribed event type list. func (s *Subscription) AddType(t string) { - s.types.add(t) + s.types.Add(t) } // RemoveType removes the event type from the subscribed event type list. func (s *Subscription) RemoveType(t string) { - s.types.remove(t) + s.types.Remove(t) } // Events returns the Event channel of this subscription. diff --git a/test/integration/document_test.go b/test/integration/document_test.go index 2cdd4f73c..4c1691f65 100644 --- a/test/integration/document_test.go +++ b/test/integration/document_test.go @@ -557,7 +557,6 @@ func TestDocument(t *testing.T) { }) t.Run("no duplicate broadcasts for duplicate subscriptions", func(t *testing.T) { - // t.Skip() bch := make(chan string) ctx := context.Background() handler := func(eventType, publisher string, payload []byte) error { @@ -576,14 +575,10 @@ func TestDocument(t *testing.T) { err = d1.SubscribeBroadcastEvent("mention", handler) assert.NoError(t, err) - println("second sub start") - // d1 subscribes to the broadcast event twice. err = d1.SubscribeBroadcastEvent("mention", handler) assert.NoError(t, err) - println("second sub end") - d2 := document.New(helper.TestDocKey(t)) assert.NoError(t, c2.Attach(ctx, d2)) rch2, err := c2.Watch(ctx, d2)