Skip to content

Commit 1ff20c4

Browse files
authored
fix: redis node upgrade optimize (#1218)
* fix: redis node upgrade optimize * fix: redis service CheckRedisOnlineOk method * fix: redis - replicas upgrate optimize * fix: redis - replica add first * fix: redis - replica update testcase expected * fix: redis destroy logic * fix: redis backup - check destroy logic * fix: TestGetRemoveNodes
1 parent 2e10768 commit 1ff20c4

7 files changed

+433
-279
lines changed

tencentcloud/commom_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,63 @@ func TestGetListIncrement(t *testing.T) {
112112

113113
}
114114

115+
func TestGetListDiffs(t *testing.T) {
116+
var (
117+
o1 = []int{1, 2, 3, 4, 5}
118+
n1 = []int{1, 2, 3, 5, 6}
119+
expectAdds1 = []int{6}
120+
expectLacks1 = []int{4}
121+
)
122+
123+
adds1, lacks1 := GetListDiffs(o1, n1)
124+
assert.Contains(t, expectAdds1, adds1[0])
125+
assert.Contains(t, expectLacks1, lacks1[0])
126+
127+
var (
128+
o2 = []int{1, 1, 3, 4, 5}
129+
n2 = []int{4, 1, 1, 5, 3}
130+
expectAdds2 = make([]int, 0)
131+
expectLacks2 = make([]int, 0)
132+
)
133+
134+
adds2, lacks2 := GetListDiffs(o2, n2)
135+
assert.Equalf(t, len(expectAdds2), len(adds2), "adds2 should be %v, got %v", expectAdds2, adds2)
136+
assert.Equalf(t, len(expectLacks2), len(lacks2), "lacks2 should be %v, got %v", expectLacks2, lacks2)
137+
138+
// TODO
139+
var (
140+
o3 = []int{1, 3, 3, 4, 4}
141+
n3 = []int{4, 3, 1, 7, 3, 6}
142+
expectAdds3 = []int{6, 7}
143+
expectLacks3 = []int{4}
144+
)
145+
146+
adds3, lacks3 := GetListDiffs(o3, n3)
147+
assert.Contains(t, expectAdds3, adds3[0])
148+
assert.Contains(t, expectAdds3, adds3[1])
149+
assert.Equalf(t, expectLacks3, lacks3, "lacks3 should be %v, got %v", expectLacks3, lacks3)
150+
151+
var (
152+
o4 = []int{1, 2, 3, 4, 5}
153+
n4 = []int{4}
154+
expectAdds4 = make([]int, 0)
155+
expectLacks4 = []int{1, 2, 3, 5}
156+
)
157+
158+
adds4, lacks4 := GetListDiffs(o4, n4)
159+
assert.Equalf(t, len(expectAdds4), len(adds4), "adds4 should be %v, got %v", expectAdds4, adds4)
160+
assert.Contains(t, expectLacks4, lacks4[0])
161+
assert.Contains(t, expectLacks4, lacks4[1])
162+
assert.Contains(t, expectLacks4, lacks4[2])
163+
assert.Contains(t, expectLacks4, lacks4[3])
164+
165+
adds5, lacks5 := GetListDiffs([]int{100003, 100004}, []int{100003, 100003, 100004})
166+
assert.Equalf(t, 1, len(adds5), "")
167+
assert.Equalf(t, 0, len(lacks5), "")
168+
assert.Contains(t, []int{100003, 100003, 100004}, adds5[0])
169+
170+
}
171+
115172
func TestIsExpectError(t *testing.T) {
116173

117174
err := sdkErrors.NewTencentCloudSDKError("ClientError.NetworkError", "", "")

tencentcloud/common.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,31 @@ func GetListIncrement(o []int, n []int) (result []int, err error) {
321321
return
322322
}
323323

324+
func GetListDiffs(o []int, n []int) (adds []int, lacks []int) {
325+
fillArr := func(arr []int, v int, count int) []int {
326+
for i := 0; i < count; i++ {
327+
arr = append(arr, v)
328+
}
329+
return arr
330+
}
331+
diffs := map[int]int{}
332+
for _, v := range o {
333+
diffs[v] -= 1
334+
}
335+
for _, v := range n {
336+
diffs[v] += 1
337+
}
338+
log.Printf("DIFFS: %v", diffs)
339+
for num, count := range diffs {
340+
if count < 0 {
341+
lacks = fillArr(lacks, num, -count)
342+
} else if count > 0 {
343+
adds = fillArr(adds, num, count)
344+
}
345+
}
346+
return
347+
}
348+
324349
//GoRoutine Limit
325350
type GoRoutineLimit struct {
326351
Count int

tencentcloud/resource_tc_redis_backup_config_test.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,14 @@ func testAccTencentCloudRedisBackupConfigDestroy(s *terraform.State) error {
7878
continue
7979
}
8080
time.Sleep(5 * time.Second)
81-
_, _, info, err := service.CheckRedisOnlineOk(ctx, rs.Primary.ID)
82-
83-
if info != nil {
84-
if *info.Status == REDIS_STATUS_ISOLATE || *info.Status == REDIS_STATUS_TODELETE {
85-
return nil
86-
}
87-
}
81+
has, isolated, err := service.CheckRedisDestroyOk(ctx, rs.Primary.ID)
8882
if err != nil {
8983
return err
9084
}
91-
85+
if !has || isolated {
86+
return nil
87+
}
88+
return fmt.Errorf("instance %s still exists", rs.Primary.ID)
9289
}
9390
return nil
9491
}

0 commit comments

Comments
 (0)