593
}
594
595
>
func (s *HistoryEventsSuite) TestForkDeleteBranch_DeleteBaseBranchFirst() {
history_store.go
596
>
treeID := uuid.NewString()
597
>
branchID := uuid.NewString()
598
>
br1Token, err := s.store.GetHistoryBranchUtil().NewHistoryBranch(
599
>
uuid.NewString(),
600
>
uuid.NewString(),
601
>
uuid.NewString(),
602
>
treeID,
603
>
&branchID,
604
>
[]*persistencespb.HistoryBranchRange{},
605
>
time.Duration(0),
606
>
time.Duration(0),
607
>
time.Duration(0),
608
>
)
609
>
s.NoError(err)
610
>
611
>
eventsPacket0 := s.newHistoryEvents(
612
>
[]int64{1, 2, 3},
613
>
rand.Int63(),
614
>
0,
615
>
)
616
>
s.appendHistoryEvents(s.ShardID, br1Token, eventsPacket0)
617
>
618
>
s.appendHistoryEvents(s.ShardID, br1Token, s.newHistoryEvents(
619
>
[]int64{4, 5},
620
>
eventsPacket0.transactionID+1,
621
>
eventsPacket0.transactionID,
622
>
))
623
>
624
>
br2Token := s.forkHistoryBranch(s.ShardID, br1Token, 4)
625
>
eventsPacket1 := s.newHistoryEvents(
626
>
[]int64{4, 5},
627
>
eventsPacket0.transactionID+2,
628
>
eventsPacket0.transactionID,
629
>
)
630
>
s.appendHistoryEvents(s.ShardID, br2Token, eventsPacket1)
631
>
632
>
// delete branch1, should only delete branch1:[4,5], keep branch1:[1,2,3] as it is used as ancestor by branch2
633
>
s.deleteHistoryBranch(s.ShardID, br1Token)
634
>
// verify branch1:[1,2,3] still remains
635
>
protorequire.ProtoSliceEqual(s.T(), eventsPacket0.events, s.listAllHistoryEvents(s.ShardID, br1Token))
636
>
// verify branch2 is not affected
637
>
protorequire.ProtoSliceEqual(s.T(), append(eventsPacket0.events, eventsPacket1.events...), s.listAllHistoryEvents(s.ShardID, br2Token))
638
>
639
>
// delete branch2, should delete branch2:[4,5], and also should delete ancestor branch1:[1,2,3] as it is no longer
640
>
// used by anyone
641
>
s.deleteHistoryBranch(s.ShardID, br2Token)
642
>
643
>
// at this point, both branch1 and branch2 are deleted.
644
>
_, err = s.store.ReadHistoryBranch(s.Ctx, &p.ReadHistoryBranchRequest{
645
>
ShardID: s.ShardID,
646
>
BranchToken: br1Token,
647
>
MinEventID: common.FirstEventID,
648
>
MaxEventID: common.LastEventID,
649
>
PageSize: 1,
650
>
})
651
>
s.Error(err, "Workflow execution history not found.")
652
>
653
>
_, err = s.store.ReadHistoryBranch(s.Ctx, &p.ReadHistoryBranchRequest{
654
>
ShardID: s.ShardID,
655
>
BranchToken: br2Token,
656
>
MinEventID: common.FirstEventID,
657
>
MaxEventID: common.LastEventID,
658
>
PageSize: 1,
659
>
})
660
>
s.Error(err, "Workflow execution history not found.")
661
>
}
662
663
func (s *HistoryEventsSuite) TestForkDeleteBranch_DeleteForkedBranchFirst() {