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

Function TestExpireStructure_EXPIREBY

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

Source from the content-addressed store, hash-verified

158}
159
160func TestExpireStructure_EXPIREBY(t *testing.T) {
161 expire, _ := initExpire()
162 defer expire.db.Close()
163
164 key := "test_key"
165 duration := int64(2)
166
167 // Test EXPIREBY function without tag
168 expireErr = expire.EXPIREBY(key, duration)
169 assert.Nil(t, expireErr)
170
171 // Wait for the key to expire
172 time.Sleep(time.Second * time.Duration(duration+1))
173
174 // Check if the key has expired
175 ttl, err := expire.TTL(key)
176 assert.Nil(t, err)
177 assert.Equal(t, int64(-2), ttl) // -2 indicates that the key does not exist
178
179 // Test EXPIREBY function with tag "ex"
180 expireErr = expire.EXPIREBY(key, duration, "ex")
181 assert.Nil(t, expireErr)
182
183 // Wait for the key to expire
184 time.Sleep(time.Second * time.Duration(duration+1))
185
186 // Check if the key has expired
187 ttl, err = expire.TTL(key)
188 assert.Nil(t, err)
189 assert.Equal(t, int64(-2), ttl) // -2 indicates that the key does not exist
190
191 // Test EXPIREBY function with an invalid tag
192 expireErr = expire.EXPIREBY(key, duration, "invalid_tag")
193 assert.Equal(t, ErrInvalidArgs, expireErr)
194}
195
196func TestExpireStructure_PEXPIREBY(t *testing.T) {
197 expire, _ := initExpire()

Callers

nothing calls this directly

Calls 4

initExpireFunction · 0.85
EXPIREBYMethod · 0.80
CloseMethod · 0.65
TTLMethod · 0.65

Tested by

no test coverage detected