Skip to content

Commit

Permalink
Merge pull request #230 from vasuki01/poke_US
Browse files Browse the repository at this point in the history
Webconfig to handle poke sync in progress scenario and resync with cloud
  • Loading branch information
sadhyama authored Sep 12, 2024
2 parents ef14253 + b443e4b commit aa980b2
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 8 deletions.
49 changes: 47 additions & 2 deletions src/webcfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ static int g_testfile = 0;
static int g_supplementarySync = 0;
static int g_webcfg_forcedsync_needed = 0;
static int g_webcfg_forcedsync_started = 0;

static int g_cloud_forcesync_retry_needed = 0;
static int g_cloud_forcesync_retry_started = 0;
/*----------------------------------------------------------------------------*/
/* Function Prototypes */
/*----------------------------------------------------------------------------*/
Expand Down Expand Up @@ -196,6 +199,11 @@ void *WebConfigMultipartTask(void *status)
WebcfgDebug("reset webcfg_forcedsync_started\n");
set_global_webcfg_forcedsync_started(0);
}
if(get_cloud_forcesync_retry_started())
{
WebcfgDebug("reset cloud_forcesync_retry_started\n");
set_cloud_forcesync_retry_started(0);
}
}

if(!wait_flag)
Expand Down Expand Up @@ -282,9 +290,16 @@ void *WebConfigMultipartTask(void *status)
ts.tv_sec += get_retry_timer();
WebcfgDebug("The retry triggers at %s\n", printTime((long long)ts.tv_sec));
}
if(get_global_webcfg_forcedsync_needed() == 1)
if(get_global_webcfg_forcedsync_needed() == 1 || get_cloud_forcesync_retry_needed() == 1)
{
WebcfgInfo("webcfg_forcedsync detected, trigger force sync with cloud.\n");
if(get_cloud_forcesync_retry_needed() == 1)
{
WebcfgInfo("Cloud force sync in progress is detected, trigger force sync with cloud.\n");
}
else
{
WebcfgInfo("webcfg_forcedsync detected, trigger force sync with cloud.\n");
}
forced_sync = 1;
wait_flag = 1;
rv = 0;
Expand All @@ -311,6 +326,14 @@ void *WebConfigMultipartTask(void *status)
set_global_webcfg_forcedsync_started(1);
WebcfgDebug("webcfg_forcedsync_needed reset to %d and webcfg_forcedsync_started %d\n", get_global_webcfg_forcedsync_needed(), get_global_webcfg_forcedsync_started());
}
//cloud_forcesync_retry_needed is set initially whenever cloud force sync is received while another sync is in progress & cloud_forcesync_retry_started is set when actual sync is started once previous sync is completed.
if(get_cloud_forcesync_retry_needed())
{
set_cloud_forcesync_retry_needed(0);
set_cloud_forcesync_retry_started(1);
WebcfgDebug("cloud_forcesync_retry_needed reset to %d and cloud_forcesync_retry_started set to %d\n",
get_cloud_forcesync_retry_needed(), get_cloud_forcesync_retry_started());
}
char *ForceSyncDoc = NULL;
char* ForceSyncTransID = NULL;

Expand Down Expand Up @@ -421,6 +444,8 @@ void *WebConfigMultipartTask(void *status)
set_global_supplementarySync(0);
set_global_webcfg_forcedsync_needed(0);
set_global_webcfg_forcedsync_started(0);
set_cloud_forcesync_retry_needed(0);
set_cloud_forcesync_retry_started(0);
#ifdef FEATURE_SUPPORT_AKER
set_send_aker_flag(false);
#endif
Expand Down Expand Up @@ -540,6 +565,26 @@ int get_global_webcfg_forcedsync_started()
{
return g_webcfg_forcedsync_started;
}

void set_cloud_forcesync_retry_needed(int value)
{
g_cloud_forcesync_retry_needed = value;
}

int get_cloud_forcesync_retry_needed()
{
return g_cloud_forcesync_retry_needed;
}

void set_cloud_forcesync_retry_started(int value)
{
g_cloud_forcesync_retry_started = value;
}

int get_cloud_forcesync_retry_started()
{
return g_cloud_forcesync_retry_started;
}
/*----------------------------------------------------------------------------*/
/* Internal functions */
/*----------------------------------------------------------------------------*/
Expand Down
5 changes: 5 additions & 0 deletions src/webcfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,9 @@ long timeVal_Diff(struct timespec *starttime, struct timespec *finishtime);
void initWebConfigClient();
pthread_t get_global_client_threadid();
void JoinThread (pthread_t threadId);

void set_cloud_forcesync_retry_needed(int value);
int get_cloud_forcesync_retry_needed();
void set_cloud_forcesync_retry_started(int value);
int get_cloud_forcesync_retry_started();
#endif
20 changes: 16 additions & 4 deletions src/webcfg_rbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1934,26 +1934,38 @@ int set_rbus_ForceSync(char* pString, int *pStatus)
}
else if(get_bootSync())
{
WebcfgInfo("Bootup sync is already in progress, Ignoring this request.\n");
WebcfgInfo("Bootup sync is already in progress, will retry later.\n");
*pStatus = 1;
set_cloud_forcesync_retry_needed(1);
return 0;
}
else if(get_maintenanceSync())
{
WebcfgInfo("Maintenance window sync is in progress, Ignoring this request.\n");
WebcfgInfo("Maintenance window sync is in progress, will retry later.\n");
*pStatus = 1;
set_cloud_forcesync_retry_needed(1);
return 0;
}
else if(strlen(ForceSyncTransID)>0)
{
WebcfgInfo("Force sync is already in progress, Ignoring this request.\n");
WebcfgInfo("Force sync is already in progress, will retry later.\n");
*pStatus = 1;
set_cloud_forcesync_retry_needed(1);
return 0;
}

else if(get_global_webcfg_forcedsync_started() ==1)
{
WebcfgInfo("Webcfg forced sync is in progress, Ignoring this request & will retry later.\n");
WebcfgInfo("Webcfg forced sync is in progress, will retry later.\n");
*pStatus = 1;
set_cloud_forcesync_retry_needed(1);
return 0;
}
else if(get_cloud_forcesync_retry_started() == 1)
{
WebcfgInfo("Cloud force sync retry is in progress, will retry later.\n");
*pStatus = 1;
set_cloud_forcesync_retry_needed(1);
return 0;
}
else
Expand Down
24 changes: 23 additions & 1 deletion tests/test_rbus_fr.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,33 @@ void set_global_webcfg_forcedsync_needed(int value)
UNUSED(value);
}

void set_cloud_forcesync_retry_needed(int value)
{
UNUSED(value);
}

int get_global_webcfg_forcedsync_needed()
{
return false;
}

bool get_global_webcfg_forcedsync_started_flag = false;
int get_cloud_forcesync_retry_needed()
{
return true;
}

bool get_global_webcfg_forcedsync_started_flag = false;
int get_global_webcfg_forcedsync_started()
{
return get_global_webcfg_forcedsync_started_flag;
}

bool get_cloud_forcesync_retry_started_flag = false;
int get_cloud_forcesync_retry_started()
{
return get_cloud_forcesync_retry_started_flag;
}

int get_global_supplementarySync()
{
return 0;
Expand Down Expand Up @@ -196,6 +212,12 @@ 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;
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;
}

void test_setForceSync_failure()
Expand Down
75 changes: 74 additions & 1 deletion tests/test_webcfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,16 @@ void test_forcedsync()
assert_int_equal(get_global_webcfg_forcedsync_needed(), 0);
}

void test_forcedsync_without_wait()
{
unsigned long status = 0;
set_global_webcfg_forcedsync_needed(1);
initWebConfigMultipartTask(status);
pthread_cond_signal(get_global_sync_condition());
sleep(6);
assert_int_equal(get_global_webcfg_forcedsync_needed(), 0);
}

void test_maintenanceSync_trigger()
{
maintenance_sync_lock = false;
Expand Down Expand Up @@ -477,6 +487,61 @@ void test_supplementarySync_and_ForceSync()
assert_non_null(get_global_mpThreadId());
}

void test_cloud_forcesync_success()
{
unsigned long status = 0;
initWebConfigMultipartTask(status);
sleep(6);
set_cloud_forcesync_retry_needed(1);
pthread_cond_signal(get_global_sync_condition());
sleep(6);
assert_int_equal(get_cloud_forcesync_retry_needed(), 0);
}

void test_cloud_forcesync_success_without_wait()
{
unsigned long status = 0;
set_cloud_forcesync_retry_needed(1);
initWebConfigMultipartTask(status);
pthread_cond_signal(get_global_sync_condition());
sleep(6);
assert_int_equal(get_cloud_forcesync_retry_needed(), 0);
}

void test_cloud_forcesync_failure()
{
unsigned long status = 0;
initWebConfigMultipartTask(status);
sleep(6);
set_cloud_forcesync_retry_needed(0);
assert_int_equal(get_cloud_forcesync_retry_needed(), 0);
}

void test_set_cloud_forcesync_retry_started()
{
int value = 0;
set_cloud_forcesync_retry_started(value);
assert_int_equal(get_cloud_forcesync_retry_started(), 0);
}

void test_get_cloud_forcesync_retry_started()
{
set_cloud_forcesync_retry_started(1);
assert_int_equal(get_cloud_forcesync_retry_started(), 1);
}

void test_set_cloud_forcesync_retry_needed()
{
int value = 0;
set_cloud_forcesync_retry_needed(value);
assert_int_equal(get_cloud_forcesync_retry_needed(), 0);
}

void test_get_cloud_forcesync_retry_needed()
{
set_cloud_forcesync_retry_needed(1);
assert_int_equal(get_cloud_forcesync_retry_needed(), 1);
}

/*----------------------------------------------------------------------------*/
/* External Functions */
Expand All @@ -499,10 +564,18 @@ int main(int argc, char *argv[])
cmocka_unit_test(test_handlehttpResponse_429),
cmocka_unit_test(test_handlehttpResponse_5xx),
cmocka_unit_test(test_forcedsync),
cmocka_unit_test(test_forcedsync_without_wait),
cmocka_unit_test(test_supplementarySync_and_ForceSync),
cmocka_unit_test(test_maintenanceSync_check),
cmocka_unit_test(test_maintenanceSync_trigger),
cmocka_unit_test(test_doc_retry)
cmocka_unit_test(test_doc_retry),
cmocka_unit_test(test_cloud_forcesync_success),
cmocka_unit_test(test_cloud_forcesync_success_without_wait),
cmocka_unit_test(test_cloud_forcesync_failure),
cmocka_unit_test(test_set_cloud_forcesync_retry_started),
cmocka_unit_test(test_get_cloud_forcesync_retry_started),
cmocka_unit_test(test_set_cloud_forcesync_retry_needed),
cmocka_unit_test(test_get_cloud_forcesync_retry_needed)
};
return cmocka_run_group_tests(tests, NULL, 0);
}

0 comments on commit aa980b2

Please sign in to comment.