delayed_test.go 518 Bytes
Newer Older
Hector Sanjuan's avatar
Hector Sanjuan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
package delayed

import (
	"testing"
	"time"

	datastore "github.com/ipfs/go-datastore"
	delay "github.com/ipfs/go-ipfs-delay"
)

func TestDelayed(t *testing.T) {
	d := New(datastore.NewMapDatastore(), delay.Fixed(time.Second))
	now := time.Now()
	k := datastore.NewKey("test")
15
	err := d.Put(k, []byte("value"))
Hector Sanjuan's avatar
Hector Sanjuan committed
16 17 18 19 20 21 22 23 24 25 26
	if err != nil {
		t.Fatal(err)
	}
	_, err = d.Get(k)
	if err != nil {
		t.Fatal(err)
	}
	if time.Since(now) < 2*time.Second {
		t.Fatal("There should have been a delay of 1 second in put and in get")
	}
}