Skip to content

Commit

Permalink
[Test](build index) enhance build index with clone test case with ret…
Browse files Browse the repository at this point in the history
…ry logic apache#42348 (apache#42364)

cherry pick from apache#42348
  • Loading branch information
airborne12 authored Oct 24, 2024
1 parent 851e278 commit 9d65317
Showing 1 changed file with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,33 @@ suite("test_build_index_with_clone_fault_injection", "nonConcurrent"){
return "wait_timeout"
}

def assertShowBuildIndexWithRetry = { tbl, expectedState, expectedMsg, maxRetries, waitSeconds ->
int attempt = 0
while (attempt < maxRetries) {
def show_build_index = sql_return_maparray("show build index where TableName = \"${tbl}\" ORDER BY JobId DESC LIMIT 1")
if (show_build_index && show_build_index.size() > 0) {
def currentState = show_build_index[0].State
def currentMsg = show_build_index[0].Msg
if (currentState == expectedState && currentMsg == expectedMsg) {
logger.info("Attempt ${attempt + 1}: State and Msg match expected values.")
return
} else {
logger.warn("Attempt ${attempt + 1}: Expected State='${expectedState}' and Msg='${expectedMsg}', but got State='${currentState}' and Msg='${currentMsg}'. Retrying after ${waitSeconds} second(s)...")
}
} else {
logger.warn("Attempt ${attempt + 1}: show_build_index is empty or null. Retrying after ${waitSeconds} second(s)...")
}
attempt++
if (attempt < maxRetries) {
sleep(waitSeconds * 1000)
}
}
def finalBuildIndex = sql_return_maparray("show build index where TableName = \"${tbl}\" ORDER BY JobId DESC LIMIT 1")
assertTrue(finalBuildIndex && finalBuildIndex.size() > 0, "show_build_index is empty or null after ${maxRetries} attempts")
assertEquals(expectedState, finalBuildIndex[0].State, "State does not match after ${maxRetries} attempts")
assertEquals(expectedMsg, finalBuildIndex[0].Msg, "Msg does not match after ${maxRetries} attempts")
}

def tbl = 'test_build_index_with_clone'
try {
GetDebugPoint().enableDebugPointForAllBEs("EngineCloneTask.wait_clone")
Expand Down Expand Up @@ -84,9 +111,8 @@ suite("test_build_index_with_clone_fault_injection", "nonConcurrent"){
sql """ build index idx_k2 on ${tbl} """
// sleep 5s to wait for the build index job report table is unstable
sleep(5000)
def show_build_index = sql_return_maparray("show build index where TableName = \"${tbl}\" ORDER BY JobId DESC LIMIT 1")
assertEquals('WAITING_TXN', show_build_index[0].State)
assertEquals('table is unstable', show_build_index[0].Msg)

assertShowBuildIndexWithRetry(tbl, 'WAITING_TXN', 'table is unstable', 3, 5)

def state = wait_for_last_build_index_on_table_finish(tbl, timeout)
assertEquals(state, "FINISHED")
Expand Down

0 comments on commit 9d65317

Please sign in to comment.