From 6dfb939f22b0c04e169e331711c705444b708cb0 Mon Sep 17 00:00:00 2001 From: slzhou Date: Thu, 14 Sep 2023 14:11:50 +0800 Subject: [PATCH] enhance: enhance test case --- include/common/tmsg.h | 7 +------ source/client/src/clientMain.c | 15 ++++++++++++++- tests/script/api/whiteListTest.c | 10 +++++++--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 2dd4af3441..9d1a8a9189 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -876,14 +876,9 @@ typedef struct { int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq); int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq); -typedef union { - struct { - uint64_t ip_mask; - }; - struct { +typedef struct SIpV4Range{ uint32_t ip; uint32_t mask; - }; } SIpV4Range; typedef struct { diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index fd7a57d847..7902d6029e 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -178,8 +178,21 @@ int32_t fetchWhiteListCallbackFn(void* param, SDataBuf* pMsg, int32_t code) { SGetUserWhiteListRsp wlRsp; tDeserializeSGetUserWhiteListRsp(pMsg->pData, pMsg->len, &wlRsp); - pInfo->userCbFn(pInfo->userParam, code, taos, wlRsp.numWhiteLists, &wlRsp.pWhiteLists->ip_mask); + uint64_t* pWhiteLists = taosMemoryMalloc(wlRsp.numWhiteLists * sizeof(uint64_t)); + if (pWhiteLists == NULL) { + taosMemoryFree(pMsg->pData); + taosMemoryFree(pMsg->pEpSet); + taosMemoryFree(pInfo); + tFreeSGetUserWhiteListRsp(&wlRsp); + } + for (int i = 0; i < wlRsp.numWhiteLists; ++i) { + pWhiteLists[i] = ((uint64_t)wlRsp.pWhiteLists[i].mask << 32) | wlRsp.pWhiteLists[i].ip; + } + + pInfo->userCbFn(pInfo->userParam, code, taos, wlRsp.numWhiteLists, pWhiteLists); + + taosMemoryFree(pWhiteLists); taosMemoryFree(pMsg->pData); taosMemoryFree(pMsg->pEpSet); taosMemoryFree(pInfo); diff --git a/tests/script/api/whiteListTest.c b/tests/script/api/whiteListTest.c index 9e5eec2ef6..1fe377f0f5 100644 --- a/tests/script/api/whiteListTest.c +++ b/tests/script/api/whiteListTest.c @@ -64,7 +64,7 @@ void __taos_async_whitelist_cb(void *param, int code, TAOS *taos, int numOfWhite if (code == 0) { printf("fetch whitelist cb. user: %s numofWhitelist: %d\n", param ? (char*)param : NULL, numOfWhiteLists); for (int i = 0; i < numOfWhiteLists; ++i) { - printf(" %d: %16x\n", i, pWhiteList[i]); + printf(" %d: 0x%llx\n", i, pWhiteList[i]); } } else { printf("fetch whitelist cb error %d\n", code); @@ -118,8 +118,11 @@ int main(int argc, char *argv[]) { } createUsers(taos, argv[1]); - sleep(1); - + while (nWhiteListVerNotified < 10) { + printf("white list update notified %d times\n", nWhiteListVerNotified); + sleep(1); + } + printf("succeed in getting white list nofication. %d times\n", nWhiteListVerNotified); dropUsers(taos); taos_close(taos); taos_cleanup(); @@ -163,4 +166,5 @@ void createUsers(TAOS *taos, const char *host) { taos_fetch_whitelist_a(taosu[i], __taos_async_whitelist_cb, users[i]); } + }