Beispiel #1
0
/* Creates a SessionStateArray of the specified number of entry */
static void
CreateSessionStateArray(int numEntries)
{
	MaxBackends = numEntries;

	IsUnderPostmaster = false;

	assert_true(NULL == AllSessionStateEntries);

	SessionStateArray *fakeSessionStateArray = NULL;
	fakeSessionStateArray = malloc(SessionState_ShmemSize());

	will_return(ShmemInitStruct, fakeSessionStateArray);
	will_assign_value(ShmemInitStruct, foundPtr, false);

	expect_any_count(ShmemInitStruct, name, 1);
	expect_any_count(ShmemInitStruct, size, 1);
	expect_any_count(ShmemInitStruct, foundPtr, 1);

	SessionState_ShmemInit();

	/* The lookup should always work, whether under postmaster or not */
	assert_true(AllSessionStateEntries == fakeSessionStateArray);

}
Beispiel #2
0
/*
 * Checks if SessionState_ShmemInit does nothing under postmaster.
 * Note, it is *only* expected to re-attach with an existing array.
 */
void
test__SessionState_ShmemInit__NoOpUnderPostmaster(void **state)
{
	AllSessionStateEntries = NULL;
	IsUnderPostmaster = true;

	static SessionStateArray fakeSessionStateArray;
	/* Initilize with some non-zero values */
	fakeSessionStateArray.maxSession = 0;
	fakeSessionStateArray.numSession = 0;
	fakeSessionStateArray.sessions = NULL;
	fakeSessionStateArray.freeList = NULL;
	fakeSessionStateArray.usedList = NULL;

	will_return(ShmemInitStruct, &fakeSessionStateArray);
	will_assign_value(ShmemInitStruct, foundPtr, true);

	expect_any_count(ShmemInitStruct, name, 1);
	expect_any_count(ShmemInitStruct, size, 1);
	expect_any_count(ShmemInitStruct, foundPtr, 1);

	SessionState_ShmemInit();

	/* The lookup should always work, whether under postmaster or not */
	assert_true(AllSessionStateEntries == &fakeSessionStateArray);
	/* All the struct properties should be unchanged */
	assert_true(AllSessionStateEntries->maxSession == 0);
	assert_true(AllSessionStateEntries->numSession == 0);
	assert_true(AllSessionStateEntries->sessions == NULL);
	assert_true(AllSessionStateEntries->freeList == NULL &&
			AllSessionStateEntries->usedList == NULL);

	/* Undo the assignment for next test */
	AllSessionStateEntries = NULL;
}
Beispiel #3
0
/*
 * Checks if RedZoneHandler_ShmemInit() properly initializes the global variables
 * as the postmaster
 */
void
test__RedZoneHandler_ShmemInit__InitializesGlobalVarsWhenPostmaster(void **state)
{
	vmemTrackerInited = false;
	IsUnderPostmaster = false;

	/* Assign weird value to test the re-initialization */
	fakeIsRunawayDetector = 1234;
	isRunawayDetector = NULL;

	expect_any_count(ShmemInitStruct, name, 2);
	expect_any_count(ShmemInitStruct, size, 2);
	expect_any_count(ShmemInitStruct, foundPtr, 2);
	will_assign_value(ShmemInitStruct, foundPtr, false);
	will_assign_value(ShmemInitStruct, foundPtr, false);
	will_return_count(ShmemInitStruct, &fakeIsRunawayDetector, 2);

	/*
	 * When vmem limit is not activated or runaway_detector_activation_percent is
	 * set to 0,, red zone should be very high (i.e., red-zone will be disabled).
	 * Note, it doesn't matter what runaway_detector_activation_percent is set for
	 * this test, as the VmemTracker_ConvertVmemMBToChunks is returning 0.
	 */
	will_return(VmemTracker_ConvertVmemMBToChunks, 0);
	expect_any(VmemTracker_ConvertVmemMBToChunks, mb);

	RedZoneHandler_ShmemInit();

	assert_true(isRunawayDetector == &fakeIsRunawayDetector);
	assert_true(redZoneChunks == INT32_MAX);
	assert_true(*isRunawayDetector == 0);

	/*
	 * When the activation percent is set to 100, we will not even attempt calculating
	 * the redZoneChunks and instead assign INT32_MAX directly. Note, we don't even
	 * call VmemTracker_ConvertVmemMBToChunks()
	 */
	runaway_detector_activation_percent = 100;
	redZoneChunks = 0;
	RedZoneHandler_ShmemInit();
	assert_true(redZoneChunks == INT32_MAX);
}
Beispiel #4
0
/* 
 * Tests that cdbdisp_dispatchPlan handles a plan size overflow 
 * when splan_len_uncompressed * num_slices.
 */
void
test__cdbdisp_dispatchPlan__Overflow_plan_size_in_kb(void **state)
{
	bool		success = false;

	struct CdbDispatcherState *ds = (struct CdbDispatcherState *)
		palloc0(sizeof(struct CdbDispatcherState));

	struct QueryDesc *queryDesc = (struct QueryDesc *)
		palloc0(sizeof(QueryDesc));

	_init_cdbdisp_dispatchPlan(queryDesc);

	/* Set max plan to a value that will require handling INT32 
	 * overflow of the current plan size */
	gp_max_plan_size = INT_MAX;

	queryDesc->plannedstmt->planTree = (struct Plan *)palloc0(sizeof(struct Plan));

	/* Set num_slices and uncompressed_size to be INT_MAX-1 to force overflow */
	queryDesc->plannedstmt->planTree->nMotionNodes = INT_MAX-1;

	expect_any(serializeNode, node);
	expect_any(serializeNode, size);
	expect_any(serializeNode, uncompressed_size_out);
	will_assign_value(serializeNode, uncompressed_size_out, INT_MAX-1);
	will_return(serializeNode, NULL);

	PG_TRY();
	{
		cdbdisp_dispatchPlan(queryDesc, true, true, ds);
	}
	PG_CATCH();
	{
		/* Verify that we get the correct error (limit exceeded) */
		ErrorData *edata = CopyErrorData();

		StringInfo message = makeStringInfo();
		appendStringInfo(message,
						 "Query plan size limit exceeded, current size: "  UINT64_FORMAT "KB, max allowed size: %dKB",
						 ((INT_MAX-1)*(INT_MAX-1)/(uint64)1024), INT_MAX);

		if (edata->elevel == ERROR &&
			strncmp(edata->message, message->data, message->len))
		{
			success = true;
		}

	}
	PG_END_TRY();

	assert_true(success);
}
Beispiel #5
0
/*
 * Checks if RedZoneHandler_ShmemInit() properly initializes the global variables
 * when under postmaster
 */
void
test__RedZoneHandler_ShmemInit__InitializesUnderPostmaster(void **state)
{
	vmemTrackerInited = false;
	IsUnderPostmaster = true;

	/* Assign weird value to test the re-initialization */
	fakeIsRunawayDetector = 1234;
	isRunawayDetector = NULL;

	expect_any(ShmemInitStruct, name);
	expect_any(ShmemInitStruct, size);
	expect_any(ShmemInitStruct, foundPtr);
	will_assign_value(ShmemInitStruct, foundPtr, true);
	will_return(ShmemInitStruct, &fakeIsRunawayDetector);

	/* For testing that we don't change this value */
	redZoneChunks = 1234;
	RedZoneHandler_ShmemInit();

	assert_true(isRunawayDetector == &fakeIsRunawayDetector);
	assert_true(redZoneChunks == 1234);
	assert_true(*isRunawayDetector == 1234);
}