Skip to content

Commit

Permalink
Add test cases and apply lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sejongk committed Sep 6, 2023
1 parent 9be6fe1 commit 6dc5b7b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
19 changes: 11 additions & 8 deletions server/backend/sync/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
}
Expand All @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions test/integration/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

1 comment on commit 6dc5b7b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go Benchmark

Benchmark suite Current: 6dc5b7b Previous: 8b2a9a7 Ratio
BenchmarkDocument/constructor_test - ns/op 1860 ns/op 1645 ns/op 1.13
BenchmarkDocument/constructor_test - B/op 1144 B/op 1144 B/op 1
BenchmarkDocument/constructor_test - allocs/op 18 allocs/op 18 allocs/op 1
BenchmarkDocument/status_test - ns/op 1173 ns/op 1036 ns/op 1.13
BenchmarkDocument/status_test - B/op 1112 B/op 1112 B/op 1
BenchmarkDocument/status_test - allocs/op 16 allocs/op 16 allocs/op 1
BenchmarkDocument/equals_test - ns/op 10537 ns/op 9056 ns/op 1.16
BenchmarkDocument/equals_test - B/op 6721 B/op 6720 B/op 1.00
BenchmarkDocument/equals_test - allocs/op 113 allocs/op 113 allocs/op 1
BenchmarkDocument/nested_update_test - ns/op 27787 ns/op 23725 ns/op 1.17
BenchmarkDocument/nested_update_test - B/op 11897 B/op 11897 B/op 1
BenchmarkDocument/nested_update_test - allocs/op 251 allocs/op 251 allocs/op 1
BenchmarkDocument/delete_test - ns/op 33736 ns/op 29089 ns/op 1.16
BenchmarkDocument/delete_test - B/op 15122 B/op 15122 B/op 1
BenchmarkDocument/delete_test - allocs/op 330 allocs/op 330 allocs/op 1
BenchmarkDocument/object_test - ns/op 11915 ns/op 10382 ns/op 1.15
BenchmarkDocument/object_test - B/op 6656 B/op 6657 B/op 1.00
BenchmarkDocument/object_test - allocs/op 113 allocs/op 113 allocs/op 1
BenchmarkDocument/array_test - ns/op 38903 ns/op 34925 ns/op 1.11
BenchmarkDocument/array_test - B/op 11753 B/op 11754 B/op 1.00
BenchmarkDocument/array_test - allocs/op 267 allocs/op 267 allocs/op 1
BenchmarkDocument/text_test - ns/op 44252 ns/op 38657 ns/op 1.14
BenchmarkDocument/text_test - B/op 14826 B/op 14826 B/op 1
BenchmarkDocument/text_test - allocs/op 473 allocs/op 473 allocs/op 1
BenchmarkDocument/text_composition_test - ns/op 44134 ns/op 38208 ns/op 1.16
BenchmarkDocument/text_composition_test - B/op 18210 B/op 18210 B/op 1
BenchmarkDocument/text_composition_test - allocs/op 474 allocs/op 474 allocs/op 1
BenchmarkDocument/rich_text_test - ns/op 116454 ns/op 102400 ns/op 1.14
BenchmarkDocument/rich_text_test - B/op 37023 B/op 37016 B/op 1.00
BenchmarkDocument/rich_text_test - allocs/op 1134 allocs/op 1134 allocs/op 1
BenchmarkDocument/counter_test - ns/op 24982 ns/op 21823 ns/op 1.14
BenchmarkDocument/counter_test - B/op 10177 B/op 10178 B/op 1.00
BenchmarkDocument/counter_test - allocs/op 238 allocs/op 238 allocs/op 1
BenchmarkDocument/text_edit_gc_100 - ns/op 4546263 ns/op 3919058 ns/op 1.16
BenchmarkDocument/text_edit_gc_100 - B/op 1553490 B/op 1553500 B/op 1.00
BenchmarkDocument/text_edit_gc_100 - allocs/op 17165 allocs/op 17166 allocs/op 1.00
BenchmarkDocument/text_edit_gc_1000 - ns/op 354118836 ns/op 305822693 ns/op 1.16
BenchmarkDocument/text_edit_gc_1000 - B/op 136639794 B/op 136666284 B/op 1.00
BenchmarkDocument/text_edit_gc_1000 - allocs/op 210740 allocs/op 210879 allocs/op 1.00
BenchmarkDocument/text_split_gc_100 - ns/op 5119297 ns/op 4461948 ns/op 1.15
BenchmarkDocument/text_split_gc_100 - B/op 2217895 B/op 2218207 B/op 1.00
BenchmarkDocument/text_split_gc_100 - allocs/op 16592 allocs/op 16595 allocs/op 1.00
BenchmarkDocument/text_split_gc_1000 - ns/op 426845316 ns/op 357452373 ns/op 1.19
BenchmarkDocument/text_split_gc_1000 - B/op 214880930 B/op 214840861 B/op 1.00
BenchmarkDocument/text_split_gc_1000 - allocs/op 211544 allocs/op 211342 allocs/op 1.00
BenchmarkDocument/text_delete_all_10000 - ns/op 20259147 ns/op 17519738 ns/op 1.16
BenchmarkDocument/text_delete_all_10000 - B/op 5904082 B/op 5905240 B/op 1.00
BenchmarkDocument/text_delete_all_10000 - allocs/op 41125 allocs/op 41131 allocs/op 1.00
BenchmarkDocument/text_delete_all_100000 - ns/op 270692799 ns/op 239749099 ns/op 1.13
BenchmarkDocument/text_delete_all_100000 - B/op 53844249 B/op 53858656 B/op 1.00
BenchmarkDocument/text_delete_all_100000 - allocs/op 415998 allocs/op 416083 allocs/op 1.00
BenchmarkDocument/text_100 - ns/op 361335 ns/op 313643 ns/op 1.15
BenchmarkDocument/text_100 - B/op 118421 B/op 118421 B/op 1
BenchmarkDocument/text_100 - allocs/op 5077 allocs/op 5077 allocs/op 1
BenchmarkDocument/text_1000 - ns/op 3894842 ns/op 3457317 ns/op 1.13
BenchmarkDocument/text_1000 - B/op 1153005 B/op 1153025 B/op 1.00
BenchmarkDocument/text_1000 - allocs/op 50081 allocs/op 50081 allocs/op 1
BenchmarkDocument/array_1000 - ns/op 1988100 ns/op 1713545 ns/op 1.16
BenchmarkDocument/array_1000 - B/op 1102838 B/op 1103084 B/op 1.00
BenchmarkDocument/array_1000 - allocs/op 11870 allocs/op 11871 allocs/op 1.00
BenchmarkDocument/array_10000 - ns/op 21772776 ns/op 19152387 ns/op 1.14
BenchmarkDocument/array_10000 - B/op 9906278 B/op 9906093 B/op 1.00
BenchmarkDocument/array_10000 - allocs/op 120719 allocs/op 120718 allocs/op 1.00
BenchmarkDocument/array_gc_100 - ns/op 203562 ns/op 176825 ns/op 1.15
BenchmarkDocument/array_gc_100 - B/op 98376 B/op 98364 B/op 1.00
BenchmarkDocument/array_gc_100 - allocs/op 1246 allocs/op 1246 allocs/op 1
BenchmarkDocument/array_gc_1000 - ns/op 2199757 ns/op 1937102 ns/op 1.14
BenchmarkDocument/array_gc_1000 - B/op 1170507 B/op 1170600 B/op 1.00
BenchmarkDocument/array_gc_1000 - allocs/op 12909 allocs/op 12909 allocs/op 1
BenchmarkDocument/counter_1000 - ns/op 324912 ns/op 289151 ns/op 1.12
BenchmarkDocument/counter_1000 - B/op 198743 B/op 198740 B/op 1.00
BenchmarkDocument/counter_1000 - allocs/op 6506 allocs/op 6506 allocs/op 1
BenchmarkDocument/counter_10000 - ns/op 3489413 ns/op 3069618 ns/op 1.14
BenchmarkDocument/counter_10000 - B/op 2165666 B/op 2165685 B/op 1.00
BenchmarkDocument/counter_10000 - allocs/op 69513 allocs/op 69513 allocs/op 1
BenchmarkDocument/object_1000 - ns/op 1998991 ns/op 1774782 ns/op 1.13
BenchmarkDocument/object_1000 - B/op 1451546 B/op 1451444 B/op 1.00
BenchmarkDocument/object_1000 - allocs/op 9918 allocs/op 9918 allocs/op 1
BenchmarkDocument/object_10000 - ns/op 24799328 ns/op 22137040 ns/op 1.12
BenchmarkDocument/object_10000 - B/op 12367629 B/op 12370116 B/op 1.00
BenchmarkDocument/object_10000 - allocs/op 101215 allocs/op 101224 allocs/op 1.00
BenchmarkDocument/tree_100 - ns/op 1143332 ns/op
BenchmarkDocument/tree_100 - B/op 442833 B/op
BenchmarkDocument/tree_100 - allocs/op 4503 allocs/op
BenchmarkDocument/tree_1000 - ns/op 82149715 ns/op
BenchmarkDocument/tree_1000 - B/op 35222792 B/op
BenchmarkDocument/tree_1000 - allocs/op 44115 allocs/op
BenchmarkDocument/tree_10000 - ns/op 10649651708 ns/op
BenchmarkDocument/tree_10000 - B/op 3438903856 B/op
BenchmarkDocument/tree_10000 - allocs/op 440193 allocs/op
BenchmarkDocument/tree_delete_all_1000 - ns/op 75873320 ns/op
BenchmarkDocument/tree_delete_all_1000 - B/op 35693382 B/op
BenchmarkDocument/tree_delete_all_1000 - allocs/op 51771 allocs/op
BenchmarkDocument/tree_edit_gc_100 - ns/op 3903104 ns/op
BenchmarkDocument/tree_edit_gc_100 - B/op 2077419 B/op
BenchmarkDocument/tree_edit_gc_100 - allocs/op 11162 allocs/op
BenchmarkDocument/tree_edit_gc_1000 - ns/op 294855238 ns/op
BenchmarkDocument/tree_edit_gc_1000 - B/op 180372974 B/op
BenchmarkDocument/tree_edit_gc_1000 - allocs/op 113375 allocs/op
BenchmarkDocument/tree_split_gc_100 - ns/op 2806116 ns/op
BenchmarkDocument/tree_split_gc_100 - B/op 1347769 B/op
BenchmarkDocument/tree_split_gc_100 - allocs/op 9058 allocs/op
BenchmarkDocument/tree_split_gc_1000 - ns/op 188431806 ns/op
BenchmarkDocument/tree_split_gc_1000 - B/op 113955434 B/op
BenchmarkDocument/tree_split_gc_1000 - allocs/op 93865 allocs/op
BenchmarkRPC/client_to_server - ns/op 454461810 ns/op 403586987 ns/op 1.13
BenchmarkRPC/client_to_server - B/op 12339565 B/op 12224802 B/op 1.01
BenchmarkRPC/client_to_server - allocs/op 177431 allocs/op 176918 allocs/op 1.00
BenchmarkRPC/client_to_client_via_server - ns/op 768956376 ns/op 703134840 ns/op 1.09
BenchmarkRPC/client_to_client_via_server - B/op 22814080 B/op 22618076 B/op 1.01
BenchmarkRPC/client_to_client_via_server - allocs/op 331820 allocs/op 331134 allocs/op 1.00
BenchmarkRPC/attach_large_document - ns/op 1651109748 ns/op 1359748878 ns/op 1.21
BenchmarkRPC/attach_large_document - B/op 1799487456 B/op 1799405880 B/op 1.00
BenchmarkRPC/attach_large_document - allocs/op 9693 allocs/op 9590 allocs/op 1.01
BenchmarkRPC/adminCli_to_server - ns/op 646657428 ns/op 598842152 ns/op 1.08
BenchmarkRPC/adminCli_to_server - B/op 21107480 B/op 21103788 B/op 1.00
BenchmarkRPC/adminCli_to_server - allocs/op 333618 allocs/op 333606 allocs/op 1.00
BenchmarkLocker - ns/op 151.5 ns/op 122.4 ns/op 1.24
BenchmarkLocker - B/op 16 B/op 16 B/op 1
BenchmarkLocker - allocs/op 1 allocs/op 1 allocs/op 1
BenchmarkLockerParallel - ns/op 171 ns/op 128.7 ns/op 1.33
BenchmarkLockerParallel - B/op 0 B/op 0 B/op NaN
BenchmarkLockerParallel - allocs/op 0 allocs/op 0 allocs/op NaN
BenchmarkLockerMoreKeys - ns/op 357.1 ns/op 483.6 ns/op 0.74
BenchmarkLockerMoreKeys - B/op 14 B/op 13 B/op 1.08
BenchmarkLockerMoreKeys - allocs/op 0 allocs/op 0 allocs/op NaN
BenchmarkSync/memory_sync_10_test - ns/op 8793 ns/op 7322 ns/op 1.20
BenchmarkSync/memory_sync_10_test - B/op 1281 B/op 1283 B/op 1.00
BenchmarkSync/memory_sync_10_test - allocs/op 38 allocs/op 38 allocs/op 1
BenchmarkSync/memory_sync_100_test - ns/op 82318 ns/op 69765 ns/op 1.18
BenchmarkSync/memory_sync_100_test - B/op 8701 B/op 8737 B/op 1.00
BenchmarkSync/memory_sync_100_test - allocs/op 277 allocs/op 279 allocs/op 0.99
BenchmarkSync/memory_sync_1000_test - ns/op 790076 ns/op 686582 ns/op 1.15
BenchmarkSync/memory_sync_1000_test - B/op 81461 B/op 81819 B/op 1.00
BenchmarkSync/memory_sync_1000_test - allocs/op 2563 allocs/op 2582 allocs/op 0.99
BenchmarkSync/memory_sync_10000_test - ns/op 8513341 ns/op 7139141 ns/op 1.19
BenchmarkSync/memory_sync_10000_test - B/op 861142 B/op 858288 B/op 1.00
BenchmarkSync/memory_sync_10000_test - allocs/op 26994 allocs/op 26871 allocs/op 1.00
BenchmarkTextEditing - ns/op 30752489721 ns/op 27047402085 ns/op 1.14
BenchmarkTextEditing - B/op 8456368288 B/op 8456806024 B/op 1.00
BenchmarkTextEditing - allocs/op 20613112 allocs/op 20613838 allocs/op 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.