提交 beca7f9a 编写于 作者: H Heikki Linnakangas

Remove silly unit tests on GUC.

Without assertions, the only thing that was checked was that
numProcsPerSegment() returns 1, when the
gp_resqueue_priority_cpucores_per_segment is 1. That seems excessive, as
numProcsPerSegment() is a trivial function that just returns the value
of gp_resqueue_priority_cpucores_per_segment.

With assertions, it checked that an assertion is thrown if
gp_resqueue_priority_cpucores_per_segment has an invalid value. That seems
excessive, because those assertions are just extra sanity checks. The GUC's
minimum and maximum values prevent it from having invalid values in the
first place.

Linking each mock test program takes a few seconds, so this shaves some
time off the build+unit test process.
上级 7e30fb4b
......@@ -2,8 +2,6 @@ subdir=src/backend/postmaster
top_builddir=../../../..
include $(top_builddir)/src/Makefile.global
TARGETS=backoff syslogger
TARGETS=syslogger
include $(top_builddir)/src/backend/mock.mk
backoff.t: $(MOCK_DIR)/backend/utils/error/assert_mock.o
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include "cmockery.h"
#include "c.h"
#include "../backoff.c"
#include "postgres.h"
#ifdef USE_ASSERT_CHECKING
/* Function passed to the testing framework in order to catch
* the failed assertion.
*/
void
_ExceptionalCondition( )
{
PG_RE_THROW();
}
/* Calls _ExceptionalCondition after ExceptionalCondition is
executed. */
void
_AssertionSetting()
{
expect_any(ExceptionalCondition,conditionName);
expect_any(ExceptionalCondition,errorType);
expect_any(ExceptionalCondition,fileName);
expect_any(ExceptionalCondition,lineNumber);
will_be_called_with_sideeffect(ExceptionalCondition,&_ExceptionalCondition,NULL);
}
#endif
/* Tests that calling numProcsPerSegment doesn't change the value of gp_resqueue_priority_cpucores_per_segment. */
void
test__numProcsPerSegment__VerifyImmutableAssignment(void **state)
{
gp_resqueue_priority_cpucores_per_segment = 1;
gp_enable_resqueue_priority = 1;
/* backoffSingleton is required to be non-null for successful execution of numProcsPerSegment. */
backoffSingleton = 1;
build_guc_variables();
assert_true(numProcsPerSegment() == 1);
}
#ifdef USE_ASSERT_CHECKING
/* Tests assigning gp_resqueue_priority_cpucores_per_segment a negative
* number. */
void
test__numProcsPerSegment__NotNegative(void **state)
{
gp_enable_resqueue_priority = 1;
backoffSingleton = 1;
gp_resqueue_priority_cpucores_per_segment = -1;
build_guc_variables();
_AssertionSetting();
/* Catch Mocked Assertion */
PG_TRY();
{
numProcsPerSegment();
}
PG_CATCH();
{
return;
}
PG_END_TRY();
assert_true(false);
}
#endif
#ifdef USE_ASSERT_CHECKING
/* Tests assigning gp_resqueue_priority_cpucores_per_segment = 0; */
void
test__numProcsPerSegment__NotZero(void **state)
{
gp_enable_resqueue_priority = 1;
backoffSingleton = 1;
gp_resqueue_priority_cpucores_per_segment = 0;
build_guc_variables();
_AssertionSetting();
/* Catch Mocked Assertion */
PG_TRY();
{
numProcsPerSegment();
}
PG_CATCH();
{
return;
}
PG_END_TRY();
assert_true(false);
}
#endif
int
main(int argc, char* argv[]) {
cmockery_parse_arguments(argc, argv);
const UnitTest tests[] = {
unit_test(test__numProcsPerSegment__VerifyImmutableAssignment)
#ifdef USE_ASSERT_CHECKING
, unit_test(test__numProcsPerSegment__NotNegative)
, unit_test(test__numProcsPerSegment__NotZero)
#endif
};
return run_tests(tests);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册