Skip to content

Commit f500a26

Browse files
daverigbytrondn
authored andcommitted
basic_engine_testsuite: Relax get_item_info expiry time assert
The get_item_info test in basic_engine_testsuite tries to check that the returned expiry time is the same as the requested value, however this is an incorrect use of the API. The input value to item_allocate() is a memcache protocol time (i.e. <30 days; treat as relative time from now, otherwise treat as time since Unix epoch), but the `exptime` member of the item_info struct is a rel_time_t - i.e. a time relative to when the memcached server starts. For example if item_allocate() is called with an expiry of '1', but the server has already been up for 5 seconds then get_item_info() will return a exptime of '6' (assuming no time has passed between the two calls). Therefore relax the assert to just check that the returned value is greater or equal to the requested value. Fixes intermittant test failure in basic_engine_testsuite: assertion failed [ii.exptime == exp] at memcached/testsuite/basic/basic_engine_testsuite.cc:451 Called from: platform/libplatform.so.0.1.0(cb_assert_die+0x66) [0x504bf66] basic_engine_testsuite.so() [0x7405c14] memcached/engine_testapp() [0x403570] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed) [0x56eb76d] memcached/engine_testapp() [0x4038fd] Killed Change-Id: I18f765ae09772fe9c1dad631865d71c50f3cb739 Reviewed-on: http://review.couchbase.org/52706 Tested-by: buildbot <[email protected]> Reviewed-by: Trond Norbye <[email protected]>
1 parent 5e0f0cc commit f500a26

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

testsuite/basic/basic_engine_testsuite.cc

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,46 @@
55
#include <unistd.h>
66
#include <platform/platform.h>
77
#include "basic_engine_testsuite.h"
8+
9+
#include <iostream>
810
#include <vector>
911
#include <sstream>
1012

1113
struct test_harness test_harness;
1214

15+
16+
// Checks that a and b are equal; if not then assert.
17+
#define assert_equal(a, b) assert_equal_impl((a), (b), #a, #b, __FILE__, __LINE__)
18+
19+
// Checkt that a >= b; if not then assert.
20+
#define assert_ge(a, b) assert_ge_impl((a), (b), #a, #b, __FILE__, __LINE__)
21+
22+
template<typename T>
23+
static void assert_equal_impl(const T& a_value, const T& b_value,
24+
const char* a_name, const char* b_name,
25+
const char* file, int line) {
26+
if (a_value != b_value) {
27+
std::stringstream ss;
28+
ss << "Check '" << a_name << " == " << b_name << "' failed - '"
29+
<< a_value << " == " << b_value << "' at " << file << ":" << line;
30+
std::cerr << ss.str() << std::endl;
31+
abort();
32+
}
33+
}
34+
35+
template<typename T>
36+
static void assert_ge_impl(const T& a_value, const T& b_value,
37+
const char* a_name, const char* b_name,
38+
const char* file, int line) {
39+
if (a_value < b_value) {
40+
std::stringstream ss;
41+
ss << "Check '" << a_name << " >= " << b_name << "' failed - '"
42+
<< a_value << " >= " << b_value << "' at " << file << ":" << line;
43+
std::cerr << ss.str() << std::endl;
44+
abort();
45+
}
46+
}
47+
1348
/*
1449
* Make sure that get_info returns something and that repeated calls to it
1550
* return the same something.
@@ -443,12 +478,15 @@ static enum test_result get_item_info_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h
443478
cb_assert(h1->store(h, NULL, test_item, &cas, OPERATION_SET,0) == ENGINE_SUCCESS);
444479
/* Had this been actual code, there'd be a connection here */
445480
cb_assert(h1->get_item_info(h, NULL, test_item, &ii) == true);
446-
cb_assert(ii.cas == cas);
447-
cb_assert(ii.flags == 0);
481+
assert_equal(cas, ii.cas);
482+
assert_equal(0u, ii.flags);
448483
cb_assert(strcmp(key,static_cast<const char*>(ii.key)) == 0);
449-
cb_assert(ii.nkey == strlen(key));
450-
cb_assert(ii.nbytes == 1);
451-
cb_assert(ii.exptime == exp);
484+
assert_equal(uint16_t(strlen(key)), ii.nkey);
485+
assert_equal(1u, ii.nbytes);
486+
// exptime is a rel_time_t; i.e. seconds since server started. Therefore can only
487+
// check that the returned value is at least as large as the value
488+
// we requested (i.e. not in the past).
489+
assert_ge(ii.exptime, exp);
452490
h1->release(h, NULL, test_item);
453491
return SUCCESS;
454492
}

0 commit comments

Comments
 (0)