Skip to content

Commit

Permalink
Add unit tests for webconfig poke in progress primary and supplementa…
Browse files Browse the repository at this point in the history
…ry retry sync
  • Loading branch information
nlrcomcast committed Jan 21, 2025
1 parent ab80e21 commit 899730a
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Install packages
run: |
sudo apt update
sudo apt-get -y install valgrind libcunit1 libcunit1-doc libcunit1-dev libmsgpack-dev gcovr libtool xsltproc docbook-xsl
sudo apt-get -y install valgrind libcunit1 libcunit1-doc libcunit1-dev libmsgpack-dev gcovr libtool xsltproc docbook-xsl uuid-dev
pip install codecov
- name: Make Build Directory
Expand Down
6 changes: 5 additions & 1 deletion src/webcfg_multipart.c
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,7 @@ void createCurlHeader( struct curl_slist *list, struct curl_slist **header_list,
WebcfgDebug("Failed to get systemReadyTime\n");
}

if((g_ForceSyncTransID !=NULL) && (strlen(g_ForceSyncTransID)>0))
if(strlen(g_ForceSyncTransID)>0)
{
WebcfgInfo("updating transaction_uuid with force g_ForceSyncTransID\n");
transaction_uuid = strdup(g_ForceSyncTransID);
Expand Down Expand Up @@ -2586,3 +2586,7 @@ void setForceSyncTransID(char *ForceSyncTransID)
webcfgStrncpy( g_ForceSyncTransID, ForceSyncTransID, sizeof(g_ForceSyncTransID));
}
}

const char* getForceSyncTransID() {
return g_ForceSyncTransID;
}
1 change: 1 addition & 0 deletions src/webcfg_multipart.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ size_t headr_callback(char *buffer, size_t size, size_t nitems, void* data);
size_t writer_callback_fn(void *buffer, size_t size, size_t nmemb, void *datain);
WEBCFG_STATUS processMsgpackSubdoc(char *transaction_id);
void setForceSyncTransID(char *ForceSyncTransID);
const char* getForceSyncTransID();
char* generate_trans_uuid();
#ifdef WAN_FAILOVER_SUPPORTED
void set_global_interface(char * value);
Expand Down
5 changes: 5 additions & 0 deletions src/webcfg_rbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -2461,3 +2461,8 @@ void set_global_supplementary_url(char *value)
WEBCFG_FREE(SupplementaryURLVal);
SupplementaryURLVal = strdup(value);
}

ForceSyncMsg* getForceSyncMsgQueue()
{
return ForceSyncMsgQ;
}
1 change: 1 addition & 0 deletions src/webcfg_rbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,5 @@ int addForceSyncMsgToQueue(char *ForceSync, char *ForceSyncTransID);
int updateForceSyncMsgQueue(char* trans_id);
void deleteForceSyncMsgQueue();
void DisplayQueue();
ForceSyncMsg* getForceSyncMsgQueue();
#endif
11 changes: 11 additions & 0 deletions tests/test_multipart_unittest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,16 @@ void test_processMsgpackSubdoc_failure()
CU_ASSERT_EQUAL(result, WEBCFG_FAILURE);
}

void test_setForceTransID() {
// Test with a valid transaction ID
char testTransID[] = "1234";
setForceSyncTransID(testTransID);
CU_ASSERT_STRING_EQUAL(getForceSyncTransID(), "1234");
// Test with a NULL transaction ID
setForceSyncTransID(NULL);
CU_ASSERT_STRING_EQUAL(getForceSyncTransID(), ""); // g_ForceSyncTransID should be cleared
}

#ifdef WEBCONFIG_BIN_SUPPORT
void test_processMsgpackSubdoc_msgpack_failure()
{
Expand Down Expand Up @@ -1279,6 +1289,7 @@ void add_suites( CU_pSuite *suite )
CU_add_test( *suite, "test readFromFile_success", test_readFromFile_success);
CU_add_test( *suite, "test readFromFile_failure", test_readFromFile_failure);
CU_add_test( *suite, "test processMsgpackSubdoc_failure", test_processMsgpackSubdoc_failure);
CU_add_test( *suite, "test reset_global_eventFlag", test_setForceTransID);
#ifdef WEBCONFIG_BIN_SUPPORT
CU_add_test( *suite, "test processMsgpackSubdoc_msgpack_failure", test_processMsgpackSubdoc_msgpack_failure);
CU_add_test( *suite, "test processMsgpackSubdoc_setValues_rbus", test_processMsgpackSubdoc_setValues_rbus);
Expand Down
83 changes: 79 additions & 4 deletions tests/test_rbus_fr.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,59 @@ void set_global_supplementarySync(int value)
/* Tests */
/*----------------------------------------------------------------------------*/

void test_addForceSyncMsgToQueue(void)
{
int ret = -1;
ret = addForceSyncMsgToQueue("root", "TID1");
CU_ASSERT_EQUAL(ret, 0);
deleteForceSyncMsgQueue();
}

void test_DisplayQueue()
{
addForceSyncMsgToQueue("ForceSync1", "TransID1");
DisplayQueue();
deleteForceSyncMsgQueue();
}

void test_deleteForceSyncMsgQueue()
{
CU_ASSERT_EQUAL(addForceSyncMsgToQueue("ForceSync1", "TransID1"), 0);
CU_ASSERT_PTR_NOT_NULL(getForceSyncMsgQueue());
deleteForceSyncMsgQueue();
CU_ASSERT_PTR_NULL(getForceSyncMsgQueue());
}

void test_updateForceSyncMsgQueue_Failure()
{
char *trans_id = NULL;
int result = updateForceSyncMsgQueue(trans_id);
CU_ASSERT_EQUAL(result, 0);
}

void test_updateForceSyncMsgQueue_found(void) {
// Initialize the ForceSyncMsg queue with two same doc entrys and different trasaction ids
char* pString1 = "{ \"value\":\"telemetry\", \"transaction_id\":\"12345\"}";
char* pString2 = "{ \"value\":\"telemetry\", \"transaction_id\":\"54321\"}";
int session_status = 0;
set_rbus_ForceSync(pString1,&session_status);
set_rbus_ForceSync(pString2,&session_status);

char *str = NULL;
char* transID = NULL;
int retGet = get_rbus_ForceSync(&str, &transID);
CU_ASSERT_EQUAL(retGet,1);
CU_ASSERT_STRING_EQUAL(transID,"54321"); //Latest trasation id should receive
}

// Test cases for set_rbus_ForceSync & get_rbus_ForceSync
void test_setForceSync()
{
int session_status = 0;
int ret = set_rbus_ForceSync("root", &session_status);
CU_ASSERT_EQUAL(0,session_status);
CU_ASSERT_EQUAL(1,ret);

get_webcfgReady_flag = false;
ret = set_rbus_ForceSync("root", &session_status);
CU_ASSERT_EQUAL(2,session_status);
Expand All @@ -212,12 +257,37 @@ void test_setForceSync()
CU_ASSERT_EQUAL(1,session_status);
CU_ASSERT_EQUAL(0,ret);
get_global_webcfg_forcedsync_started_flag = false;
get_cloud_forcesync_retry_started_flag = true;

get_cloud_forcesync_retry_started_flag = true;
ret = set_rbus_ForceSync("root", &session_status);
CU_ASSERT_EQUAL(1,session_status);
CU_ASSERT_EQUAL(0,ret);
get_cloud_forcesync_retry_started_flag = false;
get_cloud_forcesync_retry_started_flag = false;

ret = set_rbus_ForceSync("root,telemetry", &session_status);
CU_ASSERT_EQUAL(1,session_status);
CU_ASSERT_EQUAL(0,ret);
ret = set_rbus_ForceSync("telemetry,root", &session_status);
CU_ASSERT_EQUAL(1,session_status);
CU_ASSERT_EQUAL(0,ret);

set_rbus_ForceSync("root", &session_status);
ret = set_rbus_ForceSync("telemetry,root", &session_status);
CU_ASSERT_EQUAL(1,session_status);
CU_ASSERT_EQUAL(0,ret);
ForceSyncMsg* head = getForceSyncMsgQueue();
CU_ASSERT_PTR_NOT_NULL(head); // Ensure queue is not null
// Check the first node contains "telemetry"
CU_ASSERT_PTR_NOT_NULL(head->ForceSyncVal);
CU_ASSERT_STRING_EQUAL(head->ForceSyncVal, "telemetry");
// Move to the next node and check it contains "root"
ForceSyncMsg* second = head->next;
CU_ASSERT_PTR_NOT_NULL(second); // Ensure the second node exists
CU_ASSERT_PTR_NOT_NULL(second->ForceSyncVal);
CU_ASSERT_STRING_EQUAL(second->ForceSyncVal, "root");
// Ensure there are no more nodes in the queue
CU_ASSERT_PTR_NULL(second->next);
deleteForceSyncMsgQueue();
}

void test_setForceSync_failure()
Expand Down Expand Up @@ -1866,6 +1936,11 @@ void add_suites( CU_pSuite *suite )
CU_add_test( *suite, "test rbusWebcfgEventHandler", test_rbusWebcfgEventHandler);
CU_add_test( *suite, "test fetchMpBlobData", test_fetchMpBlobData);
CU_add_test( *suite, "test webcfg_util_method", test_webcfg_util_method);
CU_add_test( *suite, "test addForceSyncMsgToQueue", test_addForceSyncMsgToQueue);
CU_add_test( *suite, "test DisplayQueue", test_DisplayQueue);
CU_add_test( *suite, "test deleteForceSyncMsgQueue_simple", test_deleteForceSyncMsgQueue);
CU_add_test( *suite, "test updateForceSyncMsgQueue", test_updateForceSyncMsgQueue_Failure);
CU_add_test( *suite, "test DisplayQueue", test_updateForceSyncMsgQueue_found);
#ifdef WAN_FAILOVER_SUPPORTED
CU_add_test( *suite, "test eventReceiveHandler", test_eventReceiveHandler);
CU_add_test( *suite, "test subscribeTo_CurrentActiveInterface_Event", test_subscribeTo_CurrentActiveInterface_Event);
Expand Down

0 comments on commit 899730a

Please sign in to comment.