Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RCORE-2225 Loosen the FLX download progress test assertions to work with QBSv2 #7953

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

### Internals
* Reverted the bfd linker override in the Linux-armv7 toolchain file because the upstream OpenSSL issue it was working around was resolved.
* Fix a test failure in "sync progress: flx download progress add new objects while in the steady state" while running against QBSv2 ([PR #7953](https://github.com/realm/realm-core/pull/7953)).

----------------------------------------------

Expand Down
31 changes: 16 additions & 15 deletions src/realm/parser/generated/query_flex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ typedef int16_t flex_int16_t;
typedef uint16_t flex_uint16_t;
typedef int32_t flex_int32_t;
typedef uint32_t flex_uint32_t;
typedef uint64_t flex_uint64_t;
#else
typedef signed char flex_int8_t;
typedef short int flex_int16_t;
Expand Down Expand Up @@ -330,7 +331,7 @@ struct yy_buffer_state
/* Number of characters read into yy_ch_buf, not including EOB
* characters.
*/
int yy_n_chars;
yy_size_t yy_n_chars;

/* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to
Expand Down Expand Up @@ -428,7 +429,7 @@ static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner

YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner );
YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, yy_size_t len , yyscan_t yyscanner );

/* %endif */

Expand Down Expand Up @@ -495,7 +496,7 @@ static void yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner );
#define YY_DO_BEFORE_ACTION \
yyg->yytext_ptr = yy_bp; \
/* %% [2.0] code to fiddle yytext and yyleng for yymore() goes here \ */\
yyleng = (int) (yy_cp - yy_bp); \
yyleng = (yy_size_t) (yy_cp - yy_bp); \
yyg->yy_hold_char = *yy_cp; \
*yy_cp = '\0'; \
/* %% [3.0] code to copy yytext_ptr to yytext[] goes here, if %array \ */\
Expand Down Expand Up @@ -1309,8 +1310,8 @@ struct yyguts_t
size_t yy_buffer_stack_max; /**< capacity of stack. */
YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
char yy_hold_char;
int yy_n_chars;
int yyleng_r;
yy_size_t yy_n_chars;
yy_size_t yyleng_r;
char *yy_c_buf_p;
int yy_init;
int yy_start;
Expand Down Expand Up @@ -1402,7 +1403,7 @@ void yyset_out ( FILE * _out_str , yyscan_t yyscanner );



int yyget_leng ( yyscan_t yyscanner );
yy_size_t yyget_leng ( yyscan_t yyscanner );



Expand Down Expand Up @@ -1516,7 +1517,7 @@ static int input ( yyscan_t yyscanner );
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
int c = '*'; \
int n; \
yy_size_t n; \
for ( n = 0; n < max_size && \
(c = getc( yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \
Expand Down Expand Up @@ -2266,7 +2267,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)

else
{
int num_to_read =
yy_size_t num_to_read =
YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;

while ( num_to_read <= 0 )
Expand All @@ -2280,7 +2281,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)

if ( b->yy_is_our_buffer )
{
int new_size = b->yy_buf_size * 2;
yy_size_t new_size = b->yy_buf_size * 2;

if ( new_size <= 0 )
b->yy_buf_size += b->yy_buf_size / 8;
Expand Down Expand Up @@ -2338,7 +2339,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)

if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
/* Extend the array by 50%, plus the number we really need. */
int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
(void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner );
if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
Expand Down Expand Up @@ -2466,7 +2467,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)

else
{ /* need more input */
int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr);
yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
++yyg->yy_c_buf_p;

switch ( yy_get_next_buffer( yyscanner ) )
Expand Down Expand Up @@ -2935,12 +2936,12 @@ YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner)
* @param yyscanner The scanner object.
* @return the newly allocated buffer state object.
*/
YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len , yyscan_t yyscanner)
YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, yy_size_t _yybytes_len , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
char *buf;
yy_size_t n;
int i;
yy_size_t i;

/* Get memory for full buffer, including space for trailing EOB's. */
n = (yy_size_t) (_yybytes_len + 2);
Expand Down Expand Up @@ -2999,7 +3000,7 @@ static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner)
do \
{ \
/* Undo effects of setting up yytext. */ \
int yyless_macro_arg = (n); \
yy_size_t yyless_macro_arg = (n); \
YY_LESS_LINENO(yyless_macro_arg);\
yytext[yyleng] = yyg->yy_hold_char; \
yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
Expand Down Expand Up @@ -3087,7 +3088,7 @@ FILE *yyget_out (yyscan_t yyscanner)
/** Get the length of the current token.
* @param yyscanner The scanner object.
*/
int yyget_leng (yyscan_t yyscanner)
yy_size_t yyget_leng (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyleng;
Expand Down
7 changes: 4 additions & 3 deletions src/realm/parser/generated/query_flex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ typedef int16_t flex_int16_t;
typedef uint16_t flex_uint16_t;
typedef int32_t flex_int32_t;
typedef uint32_t flex_uint32_t;
typedef uint64_t flex_uint64_t;
#else
typedef signed char flex_int8_t;
typedef short int flex_int16_t;
Expand Down Expand Up @@ -278,7 +279,7 @@ struct yy_buffer_state
/* Number of characters read into yy_ch_buf, not including EOB
* characters.
*/
int yy_n_chars;
yy_size_t yy_n_chars;

/* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to
Expand Down Expand Up @@ -339,7 +340,7 @@ void yypop_buffer_state ( yyscan_t yyscanner );

YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner );
YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, yy_size_t len , yyscan_t yyscanner );

/* %endif */

Expand Down Expand Up @@ -459,7 +460,7 @@ void yyset_out ( FILE * _out_str , yyscan_t yyscanner );



int yyget_leng ( yyscan_t yyscanner );
yy_size_t yyget_leng ( yyscan_t yyscanner );



Expand Down
56 changes: 38 additions & 18 deletions test/object-store/sync/session/progress_notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1305,12 +1305,6 @@ TEMPLATE_TEST_CASE("sync progress: upload progress", "[sync][baas][progress]", P

namespace {
struct EstimatesAreValid : Catch::Matchers::MatcherGenericBase {
size_t initial_object_count = 0;
EstimatesAreValid(size_t initial_count = 0)
: initial_object_count(initial_count)
{
}

bool match(std::vector<double> const& entries) const
{
// Download progress should always end with an estimate of 1
Expand All @@ -1333,18 +1327,10 @@ struct EstimatesAreValid : Catch::Matchers::MatcherGenericBase {
if (size == 1)
return true;

// The actual progress for the first message should be the number of
// objects downloaded divided by the total number of objects, but in
// practice the server starts with a lower estimate so that's only an
// upper bound.
double expected_first = double(initial_object_count + 1) / (initial_object_count + size);
if (entries.front() > expected_first + .01)
return false;

// As each of our DOWNLOAD messages have a fixed size, the progress
// estimate should go up by the same amount each time.
double expected_step = (1.0 - entries.front()) / (size - 1);
for (size_t i = 1; i < size; ++i) {
double expected_step = 1.0 / size;
for (size_t i = 0; i < size; ++i) {
Comment on lines -1346 to +1333
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we always assume that the first entry in the list is 0?
What if the progress notification was registered while the transfer has already been started and the first one or more progress items were missed?
(I am thinking of one of my planned test cases for the client reset progress notifications, where the download callback is registered while the fresh realm download is already in progress).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current tests all register the notification before doing anything which would produce notifications. Tests in the future which do something different will need different checks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM - thanks

double expected = entries.front() + i * expected_step;
if (!WithinRel(entries[i], 0.1).match(expected)) {
return false;
Expand All @@ -1355,7 +1341,41 @@ struct EstimatesAreValid : Catch::Matchers::MatcherGenericBase {

std::string describe() const override
{
return "estimated progress must progress from non-1 to 1 in fixed-size non-zero steps";
return "estimated progress must progress from 0 to 1 in fixed-size non-zero steps";
}
};

struct HistoryScanEstimatesAreValid : Catch::Matchers::MatcherGenericBase {
bool match(std::vector<double> const& entries) const
{
// Download progress should always end with an estimate of 1
if (entries.empty() || entries.back() != 1)
return false;

// All estimates should be between 0 and 1
for (double estimate : entries) {
if (estimate < 0 || estimate > 1)
return false;
}

// With QBSv2, an offline client reconnecting performs a history scan
// and the progress reported is the progress through versions rather
// than download progress. This means that we can't assume anything
// beyond what is strictly guaranteed: each reported progress must be
// greater than the previous one, with the exception that 0.9999 can be
// repeated.
double prev = entries.front();
for (size_t i = 1; i < entries.size(); ++i) {
if (entries[i] < prev || (entries[i] == prev && prev != 0.9999))
return false;
prev = entries[i];
}
return true;
}

std::string describe() const override
{
return "estimated progress must monotonically increase from less than 1 to 1";
}
};
} // namespace
Expand Down Expand Up @@ -1550,7 +1570,7 @@ TEST_CASE("sync progress: flx download progress", "[sync][baas][progress]") {
suspended_realm->sync_session()->resume();
wait_for_download(*suspended_realm);
REQUIRE(suspended_estimates.size() >= 5);
REQUIRE_THAT(suspended_estimates, EstimatesAreValid(5));
REQUIRE_THAT(suspended_estimates, HistoryScanEstimatesAreValid());
}

SECTION("cleanup") {
Expand Down
Loading