forked from go-stomp/stomp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathid_test.go
More file actions
43 lines (34 loc) · 708 Bytes
/
id_test.go
File metadata and controls
43 lines (34 loc) · 708 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
37
38
39
40
41
42
43
package stomp
import (
. "gopkg.in/check.v1"
"runtime"
)
// only used during testing, does not need to be thread-safe
func resetId() {
_lastId = 0
}
func (s *StompSuite) SetUpSuite(c *C) {
resetId()
runtime.GOMAXPROCS(runtime.NumCPU())
}
func (s *StompSuite) TearDownSuite(c *C) {
runtime.GOMAXPROCS(1)
}
func (s *StompSuite) TestAllocateId(c *C) {
c.Assert(allocateId(), Equals, "1")
c.Assert(allocateId(), Equals, "2")
ch := make(chan bool, 50)
for i := 0; i < 50; i++ {
go doAllocate(100, ch)
}
for i := 0; i < 50; i++ {
<-ch
}
c.Assert(allocateId(), Equals, "5003")
}
func doAllocate(count int, ch chan bool) {
for i := 0; i < count; i++ {
_ = allocateId()
}
ch <- true
}