Skip to content

Commit

Permalink
Webconfig to handle poke sync in progress scenario and resync with cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
vasuki01 committed Sep 11, 2024
1 parent ef14253 commit e9ecad4
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 8 deletions.
50 changes: 48 additions & 2 deletions src/webcfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ static int g_testfile = 0;
static int g_supplementarySync = 0;
static int g_webcfg_forcedsync_needed = 0;
static int g_webcfg_forcedsync_started = 0;

//Added to resync with cloud for poke in progress requests
static int g_cloud_forcesync_retry_needed = 0;
static int g_cloud_forcesync_retry_started = 0;
/*----------------------------------------------------------------------------*/
/* Function Prototypes */
/*----------------------------------------------------------------------------*/
Expand Down Expand Up @@ -196,6 +200,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 +291,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("Forcesync_Inprogress detected, Retrying force sync with cloud.\n");
}
else
{
WebcfgInfo("webcfg_forcedsync detected, trigger force sync with cloud.\n");
}

Check warning on line 303 in src/webcfg.c

View check run for this annotation

Codecov / codecov/patch

src/webcfg.c#L303

Added line #L303 was not covered by tests
forced_sync = 1;
wait_flag = 1;
rv = 0;
Expand All @@ -311,6 +327,13 @@ 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());
}
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,9 @@ 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);
WebcfgDebug("Setting cloud_forcesync_retry_needed and cloud_forcesync_retry_started flag to 0\n");
#ifdef FEATURE_SUPPORT_AKER
set_send_aker_flag(false);
#endif
Expand Down Expand Up @@ -540,6 +566,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;
}

Check warning on line 578 in src/webcfg.c

View check run for this annotation

Codecov / codecov/patch

src/webcfg.c#L578

Added line #L578 was not covered by tests

void set_cloud_forcesync_retry_started(int value)
{
g_cloud_forcesync_retry_started = value;

Check warning on line 582 in src/webcfg.c

View check run for this annotation

Codecov / codecov/patch

src/webcfg.c#L581-L582

Added lines #L581 - L582 were not covered by tests
}

int get_cloud_forcesync_retry_started()
{
return g_cloud_forcesync_retry_started;
}

Check warning on line 588 in src/webcfg.c

View check run for this annotation

Codecov / codecov/patch

src/webcfg.c#L588

Added line #L588 was not covered by tests
/*----------------------------------------------------------------------------*/
/* 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
27 changes: 23 additions & 4 deletions src/webcfg_rbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1932,28 +1932,47 @@ int set_rbus_ForceSync(char* pString, int *pStatus)
*pStatus = 2;
return 0;
}
// cloud_forcesync_retry_needed is set initially whenever cloud force sync is received and detected previous sync is in progress internally &
// cloud_forcesync_retry_started is set when actual sync is started once previous sync is completed.
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);
WebcfgDebug("cloud_forcesync_retry_needed set to %d \n", get_cloud_forcesync_retry_needed());
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);
WebcfgDebug("cloud_forcesync_retry_needed set to %d \n", get_cloud_forcesync_retry_needed());

Check warning on line 1950 in src/webcfg_rbus.c

View check run for this annotation

Codecov / codecov/patch

src/webcfg_rbus.c#L1949-L1950

Added lines #L1949 - L1950 were not covered by tests
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);
WebcfgDebug("cloud_forcesync_retry_needed set to %d \n", get_cloud_forcesync_retry_needed());
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);
WebcfgDebug("cloud_forcesync_retry_needed set to %d \n", get_cloud_forcesync_retry_needed());
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);
WebcfgDebug("cloud_forcesync_retry_needed set to %d \n", get_cloud_forcesync_retry_needed());
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()
{

Check warning on line 76 in tests/test_rbus_fr.c

View check run for this annotation

Codecov / codecov/patch

tests/test_rbus_fr.c#L76

Added line #L76 was not covered by tests
return true;
}

Check warning on line 78 in tests/test_rbus_fr.c

View check run for this annotation

Codecov / codecov/patch

tests/test_rbus_fr.c#L78

Added line #L78 was not covered by tests

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()
{

Check warning on line 88 in tests/test_rbus_fr.c

View check run for this annotation

Codecov / codecov/patch

tests/test_rbus_fr.c#L88

Added line #L88 was not covered by tests
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_set_cloud_forcesync_retry_needed),
cmocka_unit_test(test_get_cloud_forcesync_retry_started),
cmocka_unit_test(test_get_cloud_forcesync_retry_needed)
};
return cmocka_run_group_tests(tests, NULL, 0);
}

0 comments on commit e9ecad4

Please sign in to comment.