@@ -78,6 +78,35 @@ func Test_compactionPlanHandler_execCompactionPlan(t *testing.T) {
7878 false ,
7979 nil ,
8080 },
81+ {
82+ "test exec compaction failed" ,
83+ fields {
84+ plans : map [int64 ]* compactionTask {},
85+ sessions : & SessionManager {
86+ sessions : struct {
87+ sync.RWMutex
88+ data map [int64 ]* Session
89+ }{
90+ data : map [int64 ]* Session {
91+ 1 : {client : & mockDataNodeClient {ch : ch , compactionResp : & commonpb.Status {ErrorCode : commonpb .ErrorCode_CacheFailed }}},
92+ },
93+ },
94+ },
95+ chManager : & ChannelManager {
96+ store : & ChannelStore {
97+ channelsInfo : map [int64 ]* NodeChannelInfo {
98+ 1 : {NodeID : 1 , Channels : []* channel {{Name : "ch1" }}},
99+ },
100+ },
101+ },
102+ },
103+ args {
104+ signal : & compactionSignal {id : 100 },
105+ plan : & datapb.CompactionPlan {PlanID : 1 , Channel : "ch1" , Type : datapb .CompactionType_MergeCompaction },
106+ },
107+ true ,
108+ nil ,
109+ },
81110 }
82111 for _ , tt := range tests {
83112 t .Run (tt .name , func (t * testing.T ) {
@@ -93,9 +122,19 @@ func Test_compactionPlanHandler_execCompactionPlan(t *testing.T) {
93122 if err == nil {
94123 <- ch
95124 task := c .getCompaction (tt .args .plan .PlanID )
96- assert .Equal (t , tt .args .plan , task .plan )
97- assert .Equal (t , tt .args .signal , task .triggerInfo )
98- assert .Equal (t , 1 , c .executingTaskNum )
125+ if ! tt .wantErr {
126+ assert .Equal (t , tt .args .plan , task .plan )
127+ assert .Equal (t , tt .args .signal , task .triggerInfo )
128+ assert .Equal (t , 1 , c .executingTaskNum )
129+ } else {
130+ assert .Eventually (t ,
131+ func () bool {
132+ c .mu .RLock ()
133+ defer c .mu .RUnlock ()
134+ return c .executingTaskNum == 0 && len (c .parallelCh [1 ]) == 0
135+ },
136+ 5 * time .Second , 100 * time .Millisecond )
137+ }
99138 }
100139 })
101140 }
@@ -455,7 +494,8 @@ func Test_compactionPlanHandler_updateCompaction(t *testing.T) {
455494 fields fields
456495 args args
457496 wantErr bool
458- expired []int64
497+ timeout []int64
498+ failed []int64
459499 unexpired []int64
460500 }{
461501 {
@@ -484,7 +524,7 @@ func Test_compactionPlanHandler_updateCompaction(t *testing.T) {
484524 },
485525 },
486526 3 : {
487- state : completed ,
527+ state : executing ,
488528 dataNodeID : 2 ,
489529 plan : & datapb.CompactionPlan {
490530 PlanID : 3 ,
@@ -519,6 +559,8 @@ func Test_compactionPlanHandler_updateCompaction(t *testing.T) {
519559 compactionStateResp : & datapb.CompactionStateResponse {
520560 Results : []* datapb.CompactionStateResult {
521561 {PlanID : 1 , State : commonpb .CompactionState_Executing },
562+ {PlanID : 3 , State : commonpb .CompactionState_Completed , Result : & datapb.CompactionResult {PlanID : 3 }},
563+ {PlanID : 4 , State : commonpb .CompactionState_Executing },
522564 },
523565 },
524566 }},
@@ -528,7 +570,8 @@ func Test_compactionPlanHandler_updateCompaction(t *testing.T) {
528570 },
529571 args {ts : tsoutil .ComposeTS (ts .Add (5 * time .Second ).UnixNano ()/ int64 (time .Millisecond ), 0 )},
530572 false ,
531- []int64 {2 , 4 },
573+ []int64 {4 },
574+ []int64 {2 },
532575 []int64 {1 , 3 },
533576 },
534577 }
@@ -543,7 +586,12 @@ func Test_compactionPlanHandler_updateCompaction(t *testing.T) {
543586 err := c .updateCompaction (tt .args .ts )
544587 assert .Equal (t , tt .wantErr , err != nil )
545588
546- for _ , id := range tt .expired {
589+ for _ , id := range tt .timeout {
590+ task := c .getCompaction (id )
591+ assert .Equal (t , timeout , task .state )
592+ }
593+
594+ for _ , id := range tt .failed {
547595 task := c .getCompaction (id )
548596 assert .Equal (t , failed , task .state )
549597 }
0 commit comments