2017-12-08 14:59:07 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2018-03-28 15:12:43 +00:00
|
|
|
"context"
|
|
|
|
"sync"
|
2017-12-08 14:59:07 +00:00
|
|
|
"testing"
|
2018-03-28 15:12:43 +00:00
|
|
|
"time"
|
2017-12-08 14:59:07 +00:00
|
|
|
|
2018-12-06 18:59:05 +00:00
|
|
|
cid "github.com/ipfs/go-cid"
|
|
|
|
rpc "github.com/libp2p/go-libp2p-gorpc"
|
|
|
|
peer "github.com/libp2p/go-libp2p-peer"
|
|
|
|
ma "github.com/multiformats/go-multiaddr"
|
2018-03-28 15:12:43 +00:00
|
|
|
|
2018-07-23 09:14:43 +00:00
|
|
|
types "github.com/ipfs/ipfs-cluster/api"
|
|
|
|
|
2018-03-28 15:12:43 +00:00
|
|
|
"github.com/ipfs/ipfs-cluster/api"
|
2018-03-15 13:44:18 +00:00
|
|
|
"github.com/ipfs/ipfs-cluster/api/rest"
|
|
|
|
"github.com/ipfs/ipfs-cluster/test"
|
2017-12-08 14:59:07 +00:00
|
|
|
)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
func testClients(t *testing.T, api *rest.API, f func(*testing.T, Client)) {
|
2018-03-21 08:51:20 +00:00
|
|
|
t.Run("in-parallel", func(t *testing.T) {
|
|
|
|
t.Run("libp2p", func(t *testing.T) {
|
2018-03-28 15:12:43 +00:00
|
|
|
t.Parallel()
|
2018-03-21 08:51:20 +00:00
|
|
|
f(t, testClientLibp2p(t, api))
|
|
|
|
})
|
|
|
|
t.Run("http", func(t *testing.T) {
|
2018-03-28 15:12:43 +00:00
|
|
|
t.Parallel()
|
2018-03-21 08:51:20 +00:00
|
|
|
f(t, testClientHTTP(t, api))
|
|
|
|
})
|
2018-03-15 13:44:18 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-12-08 14:59:07 +00:00
|
|
|
func TestVersion(t *testing.T) {
|
2018-03-15 13:44:18 +00:00
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-03-15 13:44:18 +00:00
|
|
|
v, err := c.Version()
|
|
|
|
if err != nil || v.Version == "" {
|
|
|
|
t.Logf("%+v", v)
|
|
|
|
t.Log(err)
|
|
|
|
t.Error("expected something in version")
|
|
|
|
}
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
2018-03-15 13:44:18 +00:00
|
|
|
|
|
|
|
testClients(t, api, testF)
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestID(t *testing.T) {
|
2018-03-15 13:44:18 +00:00
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-03-15 13:44:18 +00:00
|
|
|
id, err := c.ID()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if id.ID == "" {
|
|
|
|
t.Error("bad id")
|
|
|
|
}
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
2018-03-15 13:44:18 +00:00
|
|
|
|
|
|
|
testClients(t, api, testF)
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPeers(t *testing.T) {
|
2018-03-15 13:44:18 +00:00
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-03-15 13:44:18 +00:00
|
|
|
ids, err := c.Peers()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(ids) == 0 {
|
|
|
|
t.Error("expected some peers")
|
|
|
|
}
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
2018-03-15 13:44:18 +00:00
|
|
|
|
|
|
|
testClients(t, api, testF)
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPeersWithError(t *testing.T) {
|
2018-03-15 13:44:18 +00:00
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-03-15 13:44:18 +00:00
|
|
|
addr, _ := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/44444")
|
2018-08-30 23:14:06 +00:00
|
|
|
c, _ = NewDefaultClient(&Config{APIAddr: addr, DisableKeepAlives: true})
|
2018-03-15 13:44:18 +00:00
|
|
|
ids, err := c.Peers()
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected error")
|
|
|
|
}
|
|
|
|
if ids == nil || len(ids) != 0 {
|
|
|
|
t.Fatal("expected no ids")
|
|
|
|
}
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
2018-03-15 13:44:18 +00:00
|
|
|
|
|
|
|
testClients(t, api, testF)
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPeerAdd(t *testing.T) {
|
2018-03-15 13:44:18 +00:00
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-07-17 10:51:31 +00:00
|
|
|
id, err := c.PeerAdd(test.TestPeerID1)
|
2018-03-15 13:44:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if id.ID != test.TestPeerID1 {
|
|
|
|
t.Error("bad peer")
|
|
|
|
}
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
2018-03-15 13:44:18 +00:00
|
|
|
|
|
|
|
testClients(t, api, testF)
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPeerRm(t *testing.T) {
|
2018-03-15 13:44:18 +00:00
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-03-15 13:44:18 +00:00
|
|
|
err := c.PeerRm(test.TestPeerID1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
2018-03-15 13:44:18 +00:00
|
|
|
|
|
|
|
testClients(t, api, testF)
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPin(t *testing.T) {
|
2018-03-15 13:44:18 +00:00
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-03-15 13:44:18 +00:00
|
|
|
ci, _ := cid.Decode(test.TestCid1)
|
2018-10-19 18:19:52 +00:00
|
|
|
err := c.Pin(ci, 6, 7, "hello there")
|
2018-03-15 13:44:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
2018-03-15 13:44:18 +00:00
|
|
|
|
|
|
|
testClients(t, api, testF)
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnpin(t *testing.T) {
|
2018-03-15 13:44:18 +00:00
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-03-15 13:44:18 +00:00
|
|
|
ci, _ := cid.Decode(test.TestCid1)
|
2018-10-01 01:53:26 +00:00
|
|
|
err := c.Unpin(ci)
|
2018-03-15 13:44:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
2018-03-15 13:44:18 +00:00
|
|
|
|
|
|
|
testClients(t, api, testF)
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAllocations(t *testing.T) {
|
2018-03-15 13:44:18 +00:00
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-08-10 12:39:44 +00:00
|
|
|
pins, err := c.Allocations(types.DataType | types.MetaType)
|
2018-03-15 13:44:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(pins) == 0 {
|
|
|
|
t.Error("should be some pins")
|
|
|
|
}
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
2018-03-15 13:44:18 +00:00
|
|
|
|
|
|
|
testClients(t, api, testF)
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAllocation(t *testing.T) {
|
2018-03-15 13:44:18 +00:00
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-03-15 13:44:18 +00:00
|
|
|
ci, _ := cid.Decode(test.TestCid1)
|
2018-10-01 01:53:26 +00:00
|
|
|
pin, err := c.Allocation(ci)
|
2018-03-15 13:44:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if pin.Cid.String() != test.TestCid1 {
|
|
|
|
t.Error("should be same pin")
|
|
|
|
}
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
2018-03-15 13:44:18 +00:00
|
|
|
|
|
|
|
testClients(t, api, testF)
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStatus(t *testing.T) {
|
2018-03-15 13:44:18 +00:00
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-03-15 13:44:18 +00:00
|
|
|
ci, _ := cid.Decode(test.TestCid1)
|
2018-10-01 01:53:26 +00:00
|
|
|
pin, err := c.Status(ci, false)
|
2018-03-15 13:44:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if pin.Cid.String() != test.TestCid1 {
|
|
|
|
t.Error("should be same pin")
|
|
|
|
}
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
2018-03-15 13:44:18 +00:00
|
|
|
|
|
|
|
testClients(t, api, testF)
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStatusAll(t *testing.T) {
|
2018-03-15 13:44:18 +00:00
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
Status filters for `ipfs-cluster-ctl status`
Added filter option to `ipfs-cluster-ctl status`
When the --filter is passed, it will only fetch the peer information
where status of the pin matches with the filter value.
Valid filter values are tracker status types(i.e., "pinned",
"pin_error", "unpinning" etc), an alias of tracker status type (i.e.,
"queued" or "error"), comma separated list of tracker status type
and/or it aliases(i.e., "error,pinning")
On passing invalid filter value no status information will be shown
In particular, the filter would remove elements from []GlobalPinInfo
when none of the peers in GlobalPinInfo match the filter. If one peer
in the GlobalPinInfo matches the filter, the whole object is returned,
including the information for the other peers which may or not match it.
filter option works on statusAll("GET /pins"). For fetching pin status
for a CID("GET /pins/<cid>"), filter option would have no effect
Fixes #445
License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
2018-12-20 08:02:26 +00:00
|
|
|
pins, err := c.StatusAll("", false)
|
2018-03-15 13:44:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(pins) == 0 {
|
|
|
|
t.Error("there should be some pins")
|
|
|
|
}
|
2018-12-20 11:12:04 +00:00
|
|
|
|
|
|
|
// With local true
|
|
|
|
pins, err = c.StatusAll("", true)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(pins) != 2 {
|
|
|
|
t.Error("there should be two pins")
|
|
|
|
}
|
|
|
|
|
|
|
|
// With filter option
|
|
|
|
pins, err = c.StatusAll("pinning", false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(pins) != 1 {
|
|
|
|
t.Error("there should be one pin")
|
|
|
|
}
|
|
|
|
|
|
|
|
pins, err = c.StatusAll("pinned,error", false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(pins) != 2 {
|
|
|
|
t.Error("there should be two pins")
|
|
|
|
}
|
2018-12-26 05:45:30 +00:00
|
|
|
|
|
|
|
pins, err = c.StatusAll("invalidfilter", false)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected error")
|
|
|
|
}
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
|
|
|
|
2018-03-15 13:44:18 +00:00
|
|
|
testClients(t, api, testF)
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSync(t *testing.T) {
|
2018-03-15 13:44:18 +00:00
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-03-15 13:44:18 +00:00
|
|
|
ci, _ := cid.Decode(test.TestCid1)
|
2018-10-01 01:53:26 +00:00
|
|
|
pin, err := c.Sync(ci, false)
|
2018-03-15 13:44:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if pin.Cid.String() != test.TestCid1 {
|
|
|
|
t.Error("should be same pin")
|
|
|
|
}
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
2018-03-15 13:44:18 +00:00
|
|
|
|
|
|
|
testClients(t, api, testF)
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSyncAll(t *testing.T) {
|
2018-03-15 13:44:18 +00:00
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-03-15 13:44:18 +00:00
|
|
|
pins, err := c.SyncAll(false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(pins) == 0 {
|
|
|
|
t.Error("there should be some pins")
|
|
|
|
}
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
|
|
|
|
2018-03-15 13:44:18 +00:00
|
|
|
testClients(t, api, testF)
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRecover(t *testing.T) {
|
2018-03-15 13:44:18 +00:00
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-03-15 13:44:18 +00:00
|
|
|
ci, _ := cid.Decode(test.TestCid1)
|
2018-10-01 01:53:26 +00:00
|
|
|
pin, err := c.Recover(ci, false)
|
2018-03-15 13:44:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if pin.Cid.String() != test.TestCid1 {
|
|
|
|
t.Error("should be same pin")
|
|
|
|
}
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
2018-03-15 13:44:18 +00:00
|
|
|
|
|
|
|
testClients(t, api, testF)
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRecoverAll(t *testing.T) {
|
2018-03-15 13:44:18 +00:00
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-03-15 13:44:18 +00:00
|
|
|
_, err := c.RecoverAll(true)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
2018-03-15 13:44:18 +00:00
|
|
|
|
|
|
|
testClients(t, api, testF)
|
2017-12-08 14:59:07 +00:00
|
|
|
}
|
2018-01-18 02:49:35 +00:00
|
|
|
|
|
|
|
func TestGetConnectGraph(t *testing.T) {
|
2018-03-15 13:44:18 +00:00
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-03-15 13:44:18 +00:00
|
|
|
cg, err := c.GetConnectGraph()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(cg.IPFSLinks) != 3 || len(cg.ClusterLinks) != 3 ||
|
|
|
|
len(cg.ClustertoIPFS) != 3 {
|
|
|
|
t.Fatal("Bad graph")
|
|
|
|
}
|
2018-01-18 02:49:35 +00:00
|
|
|
}
|
2018-03-15 13:44:18 +00:00
|
|
|
|
|
|
|
testClients(t, api, testF)
|
2018-01-18 02:49:35 +00:00
|
|
|
}
|
2018-03-28 15:12:43 +00:00
|
|
|
|
2018-12-14 13:22:03 +00:00
|
|
|
func TestMetrics(t *testing.T) {
|
|
|
|
api := testAPI(t)
|
|
|
|
defer shutdown(api)
|
|
|
|
|
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-12-21 02:47:55 +00:00
|
|
|
m, err := c.Metrics("somemetricstype")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(m) == 0 {
|
|
|
|
t.Fatal("No metrics found")
|
2018-12-14 13:22:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
testClients(t, api, testF)
|
|
|
|
}
|
|
|
|
|
2018-03-28 15:12:43 +00:00
|
|
|
type waitService struct {
|
|
|
|
l sync.Mutex
|
|
|
|
pinStart time.Time
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wait *waitService) Pin(ctx context.Context, in api.PinSerial, out *struct{}) error {
|
|
|
|
wait.l.Lock()
|
|
|
|
defer wait.l.Unlock()
|
|
|
|
wait.pinStart = time.Now()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wait *waitService) Status(ctx context.Context, in api.PinSerial, out *api.GlobalPinInfoSerial) error {
|
|
|
|
wait.l.Lock()
|
|
|
|
defer wait.l.Unlock()
|
|
|
|
c1, _ := cid.Decode(in.Cid)
|
|
|
|
if time.Now().After(wait.pinStart.Add(5 * time.Second)) { //pinned
|
|
|
|
*out = api.GlobalPinInfo{
|
|
|
|
Cid: c1,
|
|
|
|
PeerMap: map[peer.ID]api.PinInfo{
|
|
|
|
test.TestPeerID1: {
|
|
|
|
Cid: c1,
|
|
|
|
Peer: test.TestPeerID1,
|
|
|
|
Status: api.TrackerStatusPinned,
|
|
|
|
TS: wait.pinStart,
|
|
|
|
},
|
|
|
|
test.TestPeerID2: {
|
|
|
|
Cid: c1,
|
|
|
|
Peer: test.TestPeerID2,
|
|
|
|
Status: api.TrackerStatusPinned,
|
|
|
|
TS: wait.pinStart,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.ToSerial()
|
|
|
|
} else { // pinning
|
|
|
|
*out = api.GlobalPinInfo{
|
|
|
|
Cid: c1,
|
|
|
|
PeerMap: map[peer.ID]api.PinInfo{
|
|
|
|
test.TestPeerID1: {
|
|
|
|
Cid: c1,
|
|
|
|
Peer: test.TestPeerID1,
|
|
|
|
Status: api.TrackerStatusPinning,
|
|
|
|
TS: wait.pinStart,
|
|
|
|
},
|
|
|
|
test.TestPeerID2: {
|
|
|
|
Cid: c1,
|
|
|
|
Peer: test.TestPeerID2,
|
|
|
|
Status: api.TrackerStatusPinned,
|
|
|
|
TS: wait.pinStart,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.ToSerial()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWaitFor(t *testing.T) {
|
|
|
|
tapi := testAPI(t)
|
|
|
|
defer shutdown(tapi)
|
|
|
|
|
|
|
|
rpcS := rpc.NewServer(nil, "wait")
|
|
|
|
rpcC := rpc.NewClientWithServer(nil, "wait", rpcS)
|
|
|
|
err := rpcS.RegisterName("Cluster", &waitService{})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
tapi.SetClient(rpcC)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-03-29 08:33:09 +00:00
|
|
|
ci, _ := cid.Decode(test.TestCid1)
|
2018-03-28 15:12:43 +00:00
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
fp := StatusFilterParams{
|
|
|
|
Cid: ci,
|
|
|
|
Local: false,
|
|
|
|
Target: api.TrackerStatusPinned,
|
|
|
|
CheckFreq: time.Second,
|
|
|
|
}
|
|
|
|
start := time.Now()
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
st, err := WaitFor(ctx, c, fp)
|
2018-03-28 15:12:43 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if time.Now().Sub(start) <= 5*time.Second {
|
|
|
|
t.Fatal("slow pin should have taken at least 5 seconds")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pi := range st.PeerMap {
|
|
|
|
if pi.Status != api.TrackerStatusPinned {
|
|
|
|
t.Error("pin info should show the item is pinned")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
2018-10-01 01:53:26 +00:00
|
|
|
err := c.Pin(ci, 0, 0, "test")
|
2018-03-28 15:12:43 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
testClients(t, tapi, testF)
|
|
|
|
}
|
2018-04-20 22:57:13 +00:00
|
|
|
|
|
|
|
func TestAddMultiFile(t *testing.T) {
|
2018-04-27 21:12:19 +00:00
|
|
|
api := testAPI(t)
|
2018-04-20 22:57:13 +00:00
|
|
|
defer api.Shutdown()
|
|
|
|
|
2018-12-17 13:55:34 +00:00
|
|
|
sth := test.NewShardingTestHelper()
|
|
|
|
defer sth.Clean(t)
|
|
|
|
|
2018-08-30 23:14:06 +00:00
|
|
|
testF := func(t *testing.T, c Client) {
|
2018-08-09 08:21:22 +00:00
|
|
|
mfr, closer := sth.GetTreeMultiReader(t)
|
|
|
|
defer closer.Close()
|
2018-08-06 10:44:44 +00:00
|
|
|
|
|
|
|
p := &types.AddParams{
|
|
|
|
PinOptions: types.PinOptions{
|
|
|
|
ReplicationFactorMin: -1,
|
|
|
|
ReplicationFactorMax: -1,
|
2018-10-19 18:19:52 +00:00
|
|
|
Name: "test something",
|
2018-08-06 10:44:44 +00:00
|
|
|
ShardSize: 1024,
|
|
|
|
},
|
|
|
|
Shard: false,
|
|
|
|
Layout: "",
|
|
|
|
Chunker: "",
|
|
|
|
RawLeaves: false,
|
|
|
|
Hidden: false,
|
|
|
|
}
|
|
|
|
|
2018-08-06 20:49:28 +00:00
|
|
|
out := make(chan *types.AddedOutput, 1)
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
for v := range out {
|
2018-10-03 21:03:30 +00:00
|
|
|
t.Logf("output: Name: %s. Hash: %s", v.Name, v.Cid)
|
2018-08-06 20:49:28 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
err := c.AddMultiFile(mfr, p, out)
|
2018-04-27 21:12:19 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-08-06 20:49:28 +00:00
|
|
|
|
|
|
|
wg.Wait()
|
2018-04-20 22:57:13 +00:00
|
|
|
}
|
2018-04-27 21:12:19 +00:00
|
|
|
|
|
|
|
testClients(t, api, testF)
|
2018-04-20 22:57:13 +00:00
|
|
|
}
|