delayed_test.go 688 Bytes
Newer Older
Hector Sanjuan's avatar
Hector Sanjuan committed
1 2 3 4 5 6 7
package delayed

import (
	"testing"
	"time"

	datastore "github.com/ipfs/go-datastore"
Steven Allen's avatar
Steven Allen committed
8
	dstest "github.com/ipfs/go-datastore/test"
Hector Sanjuan's avatar
Hector Sanjuan committed
9 10 11 12 13 14 15
	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")
16
	err := d.Put(k, []byte("value"))
Hector Sanjuan's avatar
Hector Sanjuan committed
17 18 19 20 21 22 23 24 25 26 27
	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")
	}
}
Steven Allen's avatar
Steven Allen committed
28 29 30 31

func TestDelayedAll(t *testing.T) {
	dstest.SubtestAll(t, New(datastore.NewMapDatastore(), delay.Fixed(time.Millisecond)))
}