2018-07-11 14:56:38 +02:00
|
|
|
package caches
|
2018-07-11 13:56:02 +02:00
|
|
|
|
|
|
|
import (
|
2021-04-15 19:06:34 +02:00
|
|
|
"github.com/alice-lg/alice-lg/pkg/api"
|
2018-07-11 13:56:02 +02:00
|
|
|
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
NeighborsCache Tests
|
|
|
|
*/
|
|
|
|
|
|
|
|
func TestNeighborsCacheSetGet(t *testing.T) {
|
|
|
|
cache := NewNeighborsCache(false)
|
|
|
|
|
2021-10-15 17:17:11 +02:00
|
|
|
response := &api.NeighborsResponse{
|
|
|
|
Response: api.Response{
|
2021-10-27 18:04:35 +00:00
|
|
|
Meta: &api.Meta{
|
2021-10-15 17:17:11 +02:00
|
|
|
TTL: time.Now().UTC().Add(23 * time.Millisecond),
|
|
|
|
},
|
2018-07-11 13:56:02 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if cache.Get() != nil {
|
|
|
|
t.Error("There should not be anything cached yet!")
|
|
|
|
}
|
|
|
|
|
|
|
|
cache.Set(response)
|
|
|
|
|
|
|
|
fromCache := cache.Get()
|
|
|
|
if fromCache != response {
|
|
|
|
t.Error("Expected", response, "got", fromCache)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait a bit
|
2018-07-11 15:09:44 +02:00
|
|
|
time.Sleep(33 * time.Millisecond)
|
2018-07-11 13:56:02 +02:00
|
|
|
|
|
|
|
fromCache = cache.Get()
|
|
|
|
if fromCache != nil {
|
|
|
|
t.Error("Expected empty cache result, got:", fromCache)
|
|
|
|
}
|
|
|
|
}
|