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

Function TestExpireStructure_EXPIREBYAT

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

Source from the content-addressed store, hash-verified

230}
231
232func TestExpireStructure_EXPIREBYAT(t *testing.T) {
233 expire, _ := initExpire()
234 defer expire.db.Close()
235
236 key := "test_key"
237 timestamp := time.Now().Add(time.Second * 2).Unix()
238
239 // Test EXPIREBYAT function without tag
240 expireErr = expire.EXPIREBYAT(key, timestamp)
241 assert.Nil(t, expireErr)
242
243 // Wait for the key to expire
244 time.Sleep(time.Second * 3)
245
246 // Check if the key has expired
247 ttl, err := expire.TTL(key)
248 assert.Nil(t, err)
249 assert.Equal(t, int64(-2), ttl) // -2 indicates that the key does not exist
250
251 // Test EXPIREBYAT function with tag "ex"
252 expireErr = expire.EXPIREBYAT(key, timestamp, "ex")
253 assert.Nil(t, expireErr)
254
255 // Check if the key has expired
256 ttl, err = expire.TTL(key)
257 assert.Nil(t, err)
258 assert.Equal(t, int64(timestamp), ttl)
259
260 // Test EXPIREBYAT function with an invalid tag
261 expireErr = expire.EXPIREBYAT(key, timestamp, "invalid_tag")
262 assert.Equal(t, ErrInvalidArgs, expireErr)
263}
264
265func TestExpireStructure_PEXPIREBYAT(t *testing.T) {
266 expire, _ := initExpire()

Callers

nothing calls this directly

Calls 5

initExpireFunction · 0.85
AddMethod · 0.80
EXPIREBYATMethod · 0.80
CloseMethod · 0.65
TTLMethod · 0.65

Tested by

no test coverage detected