-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathstreamer_test.go
More file actions
36 lines (27 loc) · 836 Bytes
/
Copy pathstreamer_test.go
File metadata and controls
36 lines (27 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package signalr
import (
"sync/atomic"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Streamer", func() {
Context("Stop with maxCancels set", func() {
It("should not add entries beyond maxCancels", func() {
s := &streamer{maxCancels: 2}
s.Stop("id1")
s.Stop("id2")
s.Stop("id3") // should be silently dropped
Expect(atomic.LoadInt64(&s.cancelCount)).To(Equal(int64(2)))
present := 0
s.cancels.Range(func(_, _ interface{}) bool { present++; return true })
Expect(present).To(Equal(2))
})
It("should accept duplicate IDs without double-counting", func() {
s := &streamer{maxCancels: 2}
s.Stop("id1")
s.Stop("id1") // duplicate — LoadOrStore skips the increment
s.Stop("id2")
Expect(atomic.LoadInt64(&s.cancelCount)).To(Equal(int64(2)))
})
})
})