new pin-test: sharded pins sharing a shard in cdag
License: MIT Signed-off-by: Wyatt Daviau <wdaviau@cs.stanford.edu>
This commit is contained in:
parent
433928d3df
commit
ecec7c24b0
161
cluster_test.go
161
cluster_test.go
|
@ -98,6 +98,10 @@ func (ipfs *mockConnector) BlockGet(c *cid.Cid) ([]byte, error) {
|
|||
return test.TestShardData, nil
|
||||
case test.TestCdagCid:
|
||||
return test.TestCdagData, nil
|
||||
case test.TestShardCid2:
|
||||
return test.TestShard2Data, nil
|
||||
case test.TestCdagCid2:
|
||||
return test.TestCdagData2, nil
|
||||
default:
|
||||
return nil, errors.New("block not found")
|
||||
}
|
||||
|
@ -242,26 +246,32 @@ func TestClusterPin(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func pinDirectShard(t *testing.T, cl *Cluster) {
|
||||
func singleShardedPin(t *testing.T, cl *Cluster) {
|
||||
cShard, _ := cid.Decode(test.TestShardCid)
|
||||
cCdag, _ := cid.Decode(test.TestCdagCid)
|
||||
cMeta, _ := cid.Decode(test.TestMetaRootCid)
|
||||
parents := cid.NewSet()
|
||||
parents.Add(cCdag)
|
||||
shardPin := api.Pin{
|
||||
Cid: cShard,
|
||||
Type: api.ShardType,
|
||||
ReplicationFactorMin: -1,
|
||||
ReplicationFactorMax: -1,
|
||||
Recursive: true,
|
||||
Parents: parents,
|
||||
}
|
||||
err := cl.Pin(shardPin)
|
||||
if err != nil {
|
||||
t.Fatal("pin should have worked:", err)
|
||||
pinMeta(t, cl, []*cid.Cid{cShard}, cCdag, cMeta)
|
||||
}
|
||||
|
||||
func pinMeta(t *testing.T, cl *Cluster, shardCids []*cid.Cid, cCdag, cMeta *cid.Cid) {
|
||||
for _, cShard := range shardCids {
|
||||
parents := cid.NewSet()
|
||||
parents.Add(cCdag)
|
||||
shardPin := api.Pin{
|
||||
Cid: cShard,
|
||||
Type: api.ShardType,
|
||||
ReplicationFactorMin: -1,
|
||||
ReplicationFactorMax: -1,
|
||||
Recursive: true,
|
||||
Parents: parents,
|
||||
}
|
||||
err := cl.Pin(shardPin)
|
||||
if err != nil {
|
||||
t.Fatal("shard pin should have worked:", err)
|
||||
}
|
||||
}
|
||||
|
||||
parents = cid.NewSet()
|
||||
parents := cid.NewSet()
|
||||
parents.Add(cMeta)
|
||||
cdagPin := api.Pin{
|
||||
Cid: cCdag,
|
||||
|
@ -270,9 +280,8 @@ func pinDirectShard(t *testing.T, cl *Cluster) {
|
|||
ReplicationFactorMax: -1,
|
||||
Recursive: false,
|
||||
Parents: parents,
|
||||
Clusterdag: cShard,
|
||||
}
|
||||
err = cl.Pin(cdagPin)
|
||||
err := cl.Pin(cdagPin)
|
||||
if err != nil {
|
||||
t.Fatal("pin should have worked:", err)
|
||||
}
|
||||
|
@ -293,7 +302,7 @@ func TestClusterPinMeta(t *testing.T) {
|
|||
defer cleanRaft()
|
||||
defer cl.Shutdown()
|
||||
|
||||
pinDirectShard(t, cl)
|
||||
singleShardedPin(t, cl)
|
||||
}
|
||||
|
||||
func TestClusterUnpinShardFail(t *testing.T) {
|
||||
|
@ -301,7 +310,7 @@ func TestClusterUnpinShardFail(t *testing.T) {
|
|||
defer cleanRaft()
|
||||
defer cl.Shutdown()
|
||||
|
||||
pinDirectShard(t, cl)
|
||||
singleShardedPin(t, cl)
|
||||
// verify pins
|
||||
if len(cl.Pins()) != 3 {
|
||||
t.Fatal("should have 3 pins")
|
||||
|
@ -325,7 +334,7 @@ func TestClusterUnpinMeta(t *testing.T) {
|
|||
defer cleanRaft()
|
||||
defer cl.Shutdown()
|
||||
|
||||
pinDirectShard(t, cl)
|
||||
singleShardedPin(t, cl)
|
||||
// verify pins
|
||||
if len(cl.Pins()) != 3 {
|
||||
t.Fatal("should have 3 pins")
|
||||
|
@ -339,6 +348,118 @@ func TestClusterUnpinMeta(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func pinTwoParentsOneShard(t *testing.T, cl *Cluster) {
|
||||
singleShardedPin(t, cl)
|
||||
|
||||
cShard, _ := cid.Decode(test.TestShardCid)
|
||||
cShard2, _ := cid.Decode(test.TestShardCid2)
|
||||
cCdag2, _ := cid.Decode(test.TestCdagCid2)
|
||||
cMeta2, _ := cid.Decode(test.TestMetaRootCid2)
|
||||
pinMeta(t, cl, []*cid.Cid{cShard, cShard2}, cCdag2, cMeta2)
|
||||
|
||||
shardPin, err := cl.PinGet(cShard)
|
||||
if err != nil {
|
||||
t.Fatal("pin should be in state")
|
||||
}
|
||||
if shardPin.Parents.Len() != 2 {
|
||||
t.Fatal("unexpected parent set in shared shard")
|
||||
}
|
||||
|
||||
shardPin2, err := cl.PinGet(cShard2)
|
||||
if shardPin2.Parents.Len() != 1 {
|
||||
t.Fatal("unexpected parent set in unshared shard")
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal("pin should be in state")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClusterPinShardTwoParents(t *testing.T) {
|
||||
cl, _, _, _, _ := testingCluster(t)
|
||||
defer cleanRaft()
|
||||
defer cl.Shutdown()
|
||||
|
||||
pinTwoParentsOneShard(t, cl)
|
||||
|
||||
cShard, _ := cid.Decode(test.TestShardCid)
|
||||
shardPin, err := cl.PinGet(cShard)
|
||||
if err != nil {
|
||||
t.Fatal("double pinned shard should be pinned")
|
||||
}
|
||||
if shardPin.Parents == nil || shardPin.Parents.Len() != 2 {
|
||||
t.Fatal("double pinned shard should have two parents")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClusterUnpinShardSecondParent(t *testing.T) {
|
||||
cl, _, _, _, _ := testingCluster(t)
|
||||
defer cleanRaft()
|
||||
defer cl.Shutdown()
|
||||
|
||||
pinTwoParentsOneShard(t, cl)
|
||||
if len(cl.Pins()) != 6 {
|
||||
t.Fatal("should have 6 pins")
|
||||
}
|
||||
cMeta2, _ := cid.Decode(test.TestMetaRootCid2)
|
||||
err := cl.Unpin(cMeta2)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
pinDelay()
|
||||
|
||||
if len(cl.Pins()) != 3 {
|
||||
t.Fatal("should have 3 pins")
|
||||
}
|
||||
|
||||
cShard, _ := cid.Decode(test.TestShardCid)
|
||||
cCdag, _ := cid.Decode(test.TestCdagCid)
|
||||
shardPin, err := cl.PinGet(cShard)
|
||||
if err != nil {
|
||||
t.Fatal("double pinned shard node should still be pinned")
|
||||
}
|
||||
if shardPin.Parents == nil || shardPin.Parents.Len() != 1 ||
|
||||
!shardPin.Parents.Has(cCdag) {
|
||||
t.Fatalf("shard node should have single original parent %v", shardPin.Parents.Keys())
|
||||
}
|
||||
}
|
||||
|
||||
func TestClusterUnpinShardFirstParent(t *testing.T) {
|
||||
cl, _, _, _, _ := testingCluster(t)
|
||||
defer cleanRaft()
|
||||
defer cl.Shutdown()
|
||||
|
||||
pinTwoParentsOneShard(t, cl)
|
||||
if len(cl.Pins()) != 6 {
|
||||
t.Fatal("should have 6 pins")
|
||||
}
|
||||
|
||||
cMeta, _ := cid.Decode(test.TestMetaRootCid)
|
||||
err := cl.Unpin(cMeta)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if len(cl.Pins()) != 4 {
|
||||
t.Fatal("should have 4 pins")
|
||||
}
|
||||
|
||||
cShard, _ := cid.Decode(test.TestShardCid)
|
||||
cShard2, _ := cid.Decode(test.TestShardCid2)
|
||||
cCdag2, _ := cid.Decode(test.TestCdagCid2)
|
||||
shardPin, err := cl.PinGet(cShard)
|
||||
if err != nil {
|
||||
t.Fatal("double pinned shard node should still be pinned")
|
||||
}
|
||||
if shardPin.Parents == nil || shardPin.Parents.Len() != 1 ||
|
||||
!shardPin.Parents.Has(cCdag2) {
|
||||
t.Fatal("shard node should have single original parent")
|
||||
}
|
||||
_, err = cl.PinGet(cShard2)
|
||||
if err != nil {
|
||||
t.Fatal("other shard shoud still be pinned too")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClusterPins(t *testing.T) {
|
||||
cl, _, _, _, _ := testingCluster(t)
|
||||
defer cleanRaft()
|
||||
|
|
15
test/cids.go
15
test/cids.go
|
@ -19,12 +19,17 @@ var (
|
|||
// ipfs mock fails when pinning this CID.
|
||||
ErrorCid = "QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmc"
|
||||
// Shard and Cdag Cids
|
||||
TestShardCid = "zdpuAoiNm1ntWx6jpgcReTiCWFHJSTpvTw4bAAn9p6yDnznqh"
|
||||
TestCdagCid = "zdpuApF6HZBu8rscHSVJ7ra3VSYWc5dJnnxt42bGKyZ1a4qPo"
|
||||
TestMetaRootCid = "QmYCLpFCj9Av8NFjkQogvtXspnTDFWaizLpVFEijHTH4eV"
|
||||
TestShardCid = "zdpuAoiNm1ntWx6jpgcReTiCWFHJSTpvTw4bAAn9p6yDnznqh"
|
||||
TestShardCid2 = "zdpuAmUorxmxhrk96mVxQTuUi6QioKzKQKK8XvzU5WURU4Qea"
|
||||
TestCdagCid = "zdpuAyVKsP6xvx1p81pKi7faxUs2GuD2ZG4o3CwMycvCLyuhK"
|
||||
TestCdagCid2 = "zdpuAynm14qkpVPMMazNjkz3nJYhtTXJ3TpRp5aEkoMHBwmKc"
|
||||
TestMetaRootCid = "QmYCLpFCj9Av8NFjkQogvtXspnTDFWaizLpVFEijHTH4eV"
|
||||
TestMetaRootCid2 = "QmUatEiCFxtckNae8XyDVGwL1WZq8cVKTMacDkqz8zAE3q"
|
||||
|
||||
TestShardData, _ = hex.DecodeString("a16130d82a58230012209273fd63ec94bed5abb219b2d9cb010cabe4af7b0177292d4335eff50464060a")
|
||||
TestCdagData, _ = hex.DecodeString("a16130d82a5825000171122030e9b9b4f1bc4b5a3759a93b4e77983cd053f84174e1b0cd628dc6c32fb0da14")
|
||||
TestShardData, _ = hex.DecodeString("a16130d82a58230012209273fd63ec94bed5abb219b2d9cb010cabe4af7b0177292d4335eff50464060a")
|
||||
TestShard2Data, _ = hex.DecodeString("a26130d82a5823001220a736215b7487e753686cc4e965ca62dc45d46303ef35349aee69a647c22ac57f6131d82a58230012205ccb8c75199ea2b1ef52a03ecaaa3186dd04fe0f8133aa0b2d5195c3c0844a10")
|
||||
TestCdagData, _ = hex.DecodeString("a16130d82a5825000171122030e9b9b4f1bc4b5a3759a93b4e77983cd053f84174e1b0cd628dc6c32fb0da14")
|
||||
TestCdagData2, _ = hex.DecodeString("a26130d82a582500017112200fb89a9189514be1d5418e0890367992b651af390f06d3751c672cba6c00b4276131d82a5825000171122030e9b9b4f1bc4b5a3759a93b4e77983cd053f84174e1b0cd628dc6c32fb0da14")
|
||||
|
||||
TestPeerID1, _ = peer.IDB58Decode("QmXZrtE5jQwXNqCJMfHUTQkvhQ4ZAnqMnmzFMJfLewuabc")
|
||||
TestPeerID2, _ = peer.IDB58Decode("QmUZ13osndQ5uL4tPWHXe3iBgBgq9gfewcBMSCAuMBsDJ6")
|
||||
|
|
Loading…
Reference in New Issue
Block a user