Skip to content

Commit 8cbe57a

Browse files
Inbar BadianInbar Badian
Inbar Badian
authored and
Inbar Badian
committedJun 10, 2018
[FAB-10594] nhance pull test
added new senario where we fetch from a peer that has a data which is not purged Change-Id: I315f8e5147c20da8b926705289385785c6899252 Signed-off-by: Inbar Badian <Inbar.Badian@ibm.com>
1 parent e80be10 commit 8cbe57a

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed
 

‎gossip/privdata/pull_test.go

+37-10
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ type dataRetrieverMock struct {
113113
}
114114

115115
func (dr *dataRetrieverMock) CollectionRWSet(dig *proto.PvtDataDigest) (*util.PrivateRWSetWithConfig, error) {
116-
return dr.Called(dig).Get(0).(*util.PrivateRWSetWithConfig), dr.Called(dig).Error(1)
116+
args := dr.Called(dig)
117+
return args.Get(0).(*util.PrivateRWSetWithConfig), args.Error(1)
117118
}
118119

119120
type receivedMsg struct {
@@ -720,19 +721,18 @@ func TestPullerAvoidPullingPurgedData(t *testing.T) {
720721
factoryMock := &collectionAccessFactoryMock{}
721722
accessPolicyMock2 := &collectionAccessPolicyMock{}
722723
accessPolicyMock2.Setup(1, 2, func(data fcommon.SignedData) bool {
723-
return bytes.Equal(data.Identity, []byte("p2")) || bytes.Equal(data.Identity, []byte("p1"))
724+
return bytes.Equal(data.Identity, []byte("p1"))
724725
}, []string{"org1", "org2"})
725726
factoryMock.On("AccessPolicy", mock.Anything, mock.Anything).Return(accessPolicyMock2, nil)
726727

727-
policyStore := newCollectionStore().
728-
withPolicy("col1", uint64(100)).
729-
thatMapsTo("p1", "p2", "p3")
728+
policyStore := newCollectionStore().withPolicy("col1", uint64(100)).thatMapsTo("p1", "p2", "p3").
729+
withPolicy("col2", uint64(1000)).thatMapsTo("p1", "p2", "p3")
730730

731731
// p2 is at ledger height 1, while p2 is at 111 which is beyond BTL defined for col1 (100)
732732
p1 := gn.newPuller("p1", policyStore, factoryMock, membership(peerData{"p2", uint64(1)},
733733
peerData{"p3", uint64(111)})...)
734734

735-
transientStore := &util.PrivateRWSetWithConfig{
735+
privateData1 := &util.PrivateRWSetWithConfig{
736736
RWSet: newPRWSet(),
737737
CollectionConfig: &fcommon.CollectionConfig{
738738
Payload: &fcommon.CollectionConfig_StaticCollectionConfig{
@@ -742,6 +742,16 @@ func TestPullerAvoidPullingPurgedData(t *testing.T) {
742742
},
743743
},
744744
}
745+
privateData2 := &util.PrivateRWSetWithConfig{
746+
RWSet: newPRWSet(),
747+
CollectionConfig: &fcommon.CollectionConfig{
748+
Payload: &fcommon.CollectionConfig_StaticCollectionConfig{
749+
StaticCollectionConfig: &fcommon.StaticCollectionConfig{
750+
Name: "col2",
751+
},
752+
},
753+
},
754+
}
745755

746756
p2 := gn.newPuller("p2", policyStore, factoryMock)
747757
p3 := gn.newPuller("p3", policyStore, factoryMock)
@@ -752,20 +762,37 @@ func TestPullerAvoidPullingPurgedData(t *testing.T) {
752762
Namespace: "ns1",
753763
}
754764

755-
p2.PrivateDataRetriever.(*dataRetrieverMock).On("CollectionRWSet", dig1).Return(transientStore, nil)
765+
dig2 := &proto.PvtDataDigest{
766+
TxId: "txID1",
767+
Collection: "col2",
768+
Namespace: "ns1",
769+
}
756770

757-
p3.PrivateDataRetriever.(*dataRetrieverMock).On("CollectionRWSet", dig1).Return(transientStore, nil).
771+
p2.PrivateDataRetriever.(*dataRetrieverMock).On("CollectionRWSet", dig1).Return(privateData1, nil)
772+
p3.PrivateDataRetriever.(*dataRetrieverMock).On("CollectionRWSet", dig1).Return(privateData1, nil).
758773
Run(
759-
func(mock.Arguments) {
774+
func(arg mock.Arguments) {
760775
assert.Fail(t, "we should not fetch private data from peers where it was purged")
761776
},
762777
)
763778

779+
p3.PrivateDataRetriever.(*dataRetrieverMock).On("CollectionRWSet", dig2).Return(privateData2, nil)
780+
p2.PrivateDataRetriever.(*dataRetrieverMock).On("CollectionRWSet", dig2).Return(privateData2, nil).
781+
Run(
782+
func(mock.Arguments) {
783+
assert.Fail(t, "we should not fetch private data of collection2 from peer 2")
784+
785+
},
786+
)
787+
764788
dasf := &digestsAndSourceFactory{}
765-
d2s := dasf.mapDigest(dig1).toSources("p3", "p2").create()
789+
d2s := dasf.mapDigest(dig1).toSources("p3", "p2").mapDigest(dig2).toSources("p3").create()
766790
// trying to fetch missing pvt data for block seq 1
767791
fetchedMessages, err := p1.fetch(d2s, uint64(1))
792+
768793
assert.NoError(t, err)
769794
assert.Equal(t, 1, len(fetchedMessages.PurgedElements))
770795
assert.Equal(t, dig1, fetchedMessages.PurgedElements[0])
796+
p3.PrivateDataRetriever.(*dataRetrieverMock).AssertNumberOfCalls(t, "CollectionRWSet", 1)
797+
771798
}

0 commit comments

Comments
 (0)