@@ -135,24 +135,41 @@ func TestMemoryCache_GetAndRefresh(t *testing.T) {
135
135
}
136
136
137
137
func TestMemoryCache_Delete (t * testing.T ) {
138
- var count = 10000
139
- var mc = New (WithInterval (100 * time .Millisecond , 100 * time .Millisecond ))
140
- for i := 0 ; i < count ; i ++ {
141
- key := string (utils .AlphabetNumeric .Generate (8 ))
142
- exp := rand .Intn (1000 ) + 200
143
- mc .Set (key , 1 , time .Duration (exp )* time .Millisecond )
144
- }
138
+ t .Run ("1" , func (t * testing.T ) {
139
+ var count = 10000
140
+ var mc = New (WithInterval (100 * time .Millisecond , 100 * time .Millisecond ))
141
+ for i := 0 ; i < count ; i ++ {
142
+ key := string (utils .AlphabetNumeric .Generate (8 ))
143
+ exp := rand .Intn (1000 ) + 200
144
+ mc .Set (key , 1 , time .Duration (exp )* time .Millisecond )
145
+ }
145
146
146
- var keys = mc .Keys ("" )
147
- for i := 0 ; i < 100 ; i ++ {
148
- deleted := mc .Delete (keys [i ])
149
- assert .True (t , deleted )
147
+ var keys = mc .Keys ("" )
148
+ for i := 0 ; i < 100 ; i ++ {
149
+ deleted := mc .Delete (keys [i ])
150
+ assert .True (t , deleted )
150
151
151
- key := string (utils .AlphabetNumeric .Generate (8 ))
152
- deleted = mc .Delete (key )
153
- assert .False (t , deleted )
154
- }
155
- assert .Equal (t , mc .Len (), count - 100 )
152
+ key := string (utils .AlphabetNumeric .Generate (8 ))
153
+ deleted = mc .Delete (key )
154
+ assert .False (t , deleted )
155
+ }
156
+ assert .Equal (t , mc .Len (), count - 100 )
157
+ })
158
+
159
+ t .Run ("2" , func (t * testing.T ) {
160
+ var mc = New ()
161
+ var wg = & sync.WaitGroup {}
162
+ wg .Add (1 )
163
+ mc .SetWithCallback ("ming" , 1 , - 1 , func (ele * Element , reason Reason ) {
164
+ assert .Equal (t , reason , ReasonDeleted )
165
+ wg .Done ()
166
+ })
167
+ mc .SetWithCallback ("ting" , 2 , - 1 , func (ele * Element , reason Reason ) {
168
+ wg .Done ()
169
+ })
170
+ go mc .Delete ("ming" )
171
+ wg .Wait ()
172
+ })
156
173
}
157
174
158
175
func TestMaxCap (t * testing.T ) {
0 commit comments