-
Notifications
You must be signed in to change notification settings - Fork 0
/
slot_test.go
54 lines (40 loc) · 1.05 KB
/
slot_test.go
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
44
45
46
47
48
49
50
51
52
53
54
package kredis
func (s *KredisTestSuite) TestSlot() {
slot, err := NewSlot("slot", 3)
s.NoError(err)
s.True(slot.IsAvailable())
s.True(slot.Reserve())
s.True(slot.Reserve())
s.True(slot.Reserve())
s.Equal(int64(3), slot.Taken())
s.False(slot.IsAvailable())
s.True(slot.Release())
s.Equal(int64(2), slot.Taken())
s.True(slot.IsAvailable())
s.NoError(slot.Reset())
s.Equal(int64(0), slot.Taken())
s.True(slot.IsAvailable())
s.False(slot.Release())
}
func (s KredisTestSuite) TestSlotExpiry() {
slot, err := NewSlot("slot", 1, WithConfigName("capture"), WithExpiry("5s"))
s.NoError(err)
slot.Reserve()
s.False(slot.IsAvailable())
s.Equal("EXPIRE ns:slot 5", s.captureHook.Captures[2].String())
}
func (s *KredisTestSuite) TestSlotWithReserveCallback() {
var called int
callback := func() {
called += 1
}
slot, err := NewSlot("slot", 1)
s.NoError(err)
s.True(slot.Reserve(callback))
s.Equal(1, called)
s.Equal(int64(0), slot.Taken())
slot.Reserve()
s.False(slot.Reserve(callback))
s.Equal(1, called)
s.Equal(int64(0), slot.Taken())
}