-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsemaphorefactory_test.go
More file actions
37 lines (31 loc) · 929 Bytes
/
semaphorefactory_test.go
File metadata and controls
37 lines (31 loc) · 929 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
package cuirass_test
import (
"testing"
"github.com/arjantop/cuirass"
"github.com/stretchr/testify/assert"
)
func newTestringSemaphoreFactory() *cuirass.SemaphoreFactory {
return cuirass.NewSemaphoreFactory()
}
func TestSemaphoreFactoryGetSameInstance(t *testing.T) {
sf := newTestringSemaphoreFactory()
s1 := sf.Get("s1", 1)
assert.True(t, s1.TryAcquire())
s2 := sf.Get("s1", 1)
assert.False(t, s2.TryAcquire())
}
func TestSemaphoreFactoryGetSemaphoreUniqueKeys(t *testing.T) {
sf := newTestringSemaphoreFactory()
s1 := sf.Get("s1", 1)
assert.True(t, s1.TryAcquire())
s2 := sf.Get("s2", 1)
assert.True(t, s2.TryAcquire())
}
func TestSemaphoreFactoryGetChangedCapacity(t *testing.T) {
sf := newTestringSemaphoreFactory()
s1 := sf.Get("s1", 1)
assert.True(t, s1.TryAcquire())
s2 := sf.Get("s1", 2)
assert.True(t, s2.TryAcquire(), "Acquired resources are reset to zero")
assert.True(t, s2.TryAcquire())
}