Add test about local allocation
This commit is contained in:
parent
07b4971277
commit
7e389d551c
46
add_test.go
46
add_test.go
|
@ -4,6 +4,7 @@ package ipfscluster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -25,7 +26,7 @@ func TestAdd(t *testing.T) {
|
||||||
|
|
||||||
waitForLeaderAndMetrics(t, clusters)
|
waitForLeaderAndMetrics(t, clusters)
|
||||||
|
|
||||||
t.Run("local", func(t *testing.T) {
|
t.Run("default", func(t *testing.T) {
|
||||||
params := api.DefaultAddParams()
|
params := api.DefaultAddParams()
|
||||||
params.Shard = false
|
params.Shard = false
|
||||||
params.Name = "testlocal"
|
params.Name = "testlocal"
|
||||||
|
@ -56,6 +57,49 @@ func TestAdd(t *testing.T) {
|
||||||
|
|
||||||
runF(t, clusters, f)
|
runF(t, clusters, f)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("local_one_allocation", func(t *testing.T) {
|
||||||
|
params := api.DefaultAddParams()
|
||||||
|
params.Shard = false
|
||||||
|
params.Name = "testlocal"
|
||||||
|
params.ReplicationFactorMin = 1
|
||||||
|
params.ReplicationFactorMax = 1
|
||||||
|
params.Local = true
|
||||||
|
mfr, closer := sth.GetTreeMultiReader(t)
|
||||||
|
defer closer.Close()
|
||||||
|
r := multipart.NewReader(mfr, mfr.Boundary())
|
||||||
|
ci, err := clusters[2].AddFile(r, params)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if ci.String() != test.ShardingDirBalancedRootCID {
|
||||||
|
t.Fatal("unexpected root CID for local add")
|
||||||
|
}
|
||||||
|
|
||||||
|
// We need to sleep a lot because it takes time to
|
||||||
|
// catch up on a first/single pin on crdts
|
||||||
|
time.Sleep(10 * time.Second)
|
||||||
|
|
||||||
|
f := func(t *testing.T, c *Cluster) {
|
||||||
|
pin := c.StatusLocal(ctx, ci)
|
||||||
|
if pin.Error != "" {
|
||||||
|
t.Error(pin.Error)
|
||||||
|
}
|
||||||
|
fmt.Println(pin)
|
||||||
|
switch c.id {
|
||||||
|
case clusters[2].id:
|
||||||
|
if pin.Status != api.TrackerStatusPinned {
|
||||||
|
t.Error("item should be pinned and is", pin.Status)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if pin.Status != api.TrackerStatusRemote {
|
||||||
|
t.Errorf("item should only be allocated to cluster2")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runF(t, clusters, f)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddWithUserAllocations(t *testing.T) {
|
func TestAddWithUserAllocations(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user