MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / TestExpireStructure_PEXPIREBY

Function TestExpireStructure_PEXPIREBY

structure/expiring_key_test.go:196–230  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

194}
195
196func TestExpireStructure_PEXPIREBY(t *testing.T) {
197 expire, _ := initExpire()
198 defer expire.db.Close()
199
200 key := "test_key"
201 duration := int64(2000)
202
203 // Test PEXPIREBY function without tag
204 expireErr = expire.PEXPIREBY(key, duration)
205 assert.Nil(t, expireErr)
206
207 // Wait for the key to expire
208 time.Sleep(time.Millisecond * time.Duration(duration+100))
209
210 // Check if the key has expired
211 ttl, err := expire.TTL(key)
212 assert.Nil(t, err)
213 assert.Equal(t, int64(-2), ttl) // -2 indicates that the key does not exist
214
215 // Test PEXPIREBY function with tag "ex"
216 expireErr = expire.PEXPIREBY(key, duration, "ex")
217 assert.Nil(t, expireErr)
218
219 // Wait for the key to expire
220 time.Sleep(time.Millisecond * time.Duration(duration+100))
221
222 // Check if the key has expired
223 ttl, err = expire.TTL(key)
224 assert.Nil(t, err)
225 assert.Equal(t, int64(-2), ttl) // -2 indicates that the key does not exist
226
227 // Test PEXPIREBY function with an invalid tag
228 expireErr = expire.PEXPIREBY(key, duration, "invalid_tag")
229 assert.Equal(t, ErrInvalidArgs, expireErr)
230}
231
232func TestExpireStructure_EXPIREBYAT(t *testing.T) {
233 expire, _ := initExpire()

Callers

nothing calls this directly

Calls 4

initExpireFunction · 0.85
PEXPIREBYMethod · 0.80
CloseMethod · 0.65
TTLMethod · 0.65

Tested by

no test coverage detected