Skip to content

Commit 3a2d1a8

Browse files
committed
Fix unittest failures caused by stale mock parameters and outdated test setup
- xactdesc_test: fix segfault by initializing record->record before accessing main_data; use xl_xact_prepare instead of TwoPhaseFileHeader to match xact_desc's actual parsing; update expected output format - checkpointer_test, gp_replication_test, procarray_test: update LWLockHeldByMe mock parameter name from 'l' to 'lock' - postinit_test: add expect_any for new HaveNFreeProcs 'nfree' parameter - replication/test/Makefile: remove shmqueue_mock.o (shmqueue.c was deleted)
1 parent bd3f2ec commit 3a2d1a8

7 files changed

Lines changed: 47 additions & 49 deletions

File tree

src/backend/access/rmgrdesc/test/xactdesc_test.c

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,75 +16,72 @@ static void
1616
test_xactdescprepareCommit(void **state)
1717
{
1818
StringInfo buf = makeStringInfo();
19+
const char *gid = "4242424242-0000000042";
20+
Size gidlen = strlen(gid) + 1;
21+
Size datalen = MAXALIGN(sizeof(xl_xact_prepare)) + MAXALIGN(gidlen);
1922

20-
XLogReaderState *record = palloc(sizeof(XLogReaderState));
21-
XLogRecGetData(record) = palloc(sizeof(TwoPhaseFileHeader));
22-
record->record = palloc(sizeof(TwoPhaseFileHeader));
23+
XLogReaderState *record = palloc0(sizeof(XLogReaderState));
24+
record->record = palloc0(sizeof(DecodedXLogRecord));
25+
XLogRecGetData(record) = palloc0(datalen);
2326

2427
XLogRecGetInfo(record) = XLOG_XACT_PREPARE;
25-
TwoPhaseFileHeader* tpfh = (TwoPhaseFileHeader*) XLogRecGetData(record);
28+
xl_xact_prepare *xlrec = (xl_xact_prepare *) XLogRecGetData(record);
2629

27-
tpfh->prepared_at = 617826371830030;
28-
tpfh->tablespace_oid_to_delete_on_commit = 42;
29-
tpfh->tablespace_oid_to_delete_on_abort = InvalidOid;
30-
31-
/* Can not use save_state() here, so emulate it */
32-
tpfh->gidlen = strlen("4242424242-0000000042") + 1;
33-
strcpy((char *)tpfh + sizeof(*tpfh), "4242424242-0000000042");
30+
xlrec->prepared_at = 617826371830030;
31+
xlrec->gidlen = gidlen;
32+
memcpy((char *) xlrec + MAXALIGN(sizeof(xl_xact_prepare)), gid, gidlen);
3433

3534
xact_desc(buf, record);
3635

37-
assert_string_equal("at = 2019-07-30 18:26:11.83003+00; gid = 4242424242-0000000042; tablespace_oid_to_delete_on_commit = 42", buf->data);
36+
assert_string_equal("gid 4242424242-0000000042: 2019-07-30 18:26:11.83003+00", buf->data);
3837
}
3938

4039
static void
4140
test_xactdescprepareAbort(void **state)
4241
{
4342
StringInfo buf = makeStringInfo();
43+
const char *gid = "1111111111-0000000001";
44+
Size gidlen = strlen(gid) + 1;
45+
Size datalen = MAXALIGN(sizeof(xl_xact_prepare)) + MAXALIGN(gidlen);
4446

45-
XLogReaderState *record = palloc(sizeof(XLogReaderState));
46-
XLogRecGetData(record) = palloc(sizeof(TwoPhaseFileHeader));
47-
record->record = palloc(sizeof(TwoPhaseFileHeader));
47+
XLogReaderState *record = palloc0(sizeof(XLogReaderState));
48+
record->record = palloc0(sizeof(DecodedXLogRecord));
49+
XLogRecGetData(record) = palloc0(datalen);
4850

4951
XLogRecGetInfo(record) = XLOG_XACT_PREPARE;
50-
TwoPhaseFileHeader* tpfh = (TwoPhaseFileHeader*) XLogRecGetData(record);
51-
52-
tpfh->prepared_at = 617826371830030;
53-
tpfh->tablespace_oid_to_delete_on_commit = InvalidOid;
54-
tpfh->tablespace_oid_to_delete_on_abort = 42;
52+
xl_xact_prepare *xlrec = (xl_xact_prepare *) XLogRecGetData(record);
5553

56-
/* Can not use save_state() here, so emulate it */
57-
tpfh->gidlen = strlen("4242424242-0000000042") + 1;
58-
strcpy((char *)tpfh + sizeof(*tpfh), "4242424242-0000000042");
54+
xlrec->prepared_at = 617826371830030;
55+
xlrec->gidlen = gidlen;
56+
memcpy((char *) xlrec + MAXALIGN(sizeof(xl_xact_prepare)), gid, gidlen);
5957

6058
xact_desc(buf, record);
6159

62-
assert_string_equal("at = 2019-07-30 18:26:11.83003+00; gid = 4242424242-0000000042; tablespace_oid_to_delete_on_abort = 42", buf->data);
60+
assert_string_equal("gid 1111111111-0000000001: 2019-07-30 18:26:11.83003+00", buf->data);
6361
}
6462

6563
static void
6664
test_xactdescprepareNone(void **state)
6765
{
6866
StringInfo buf = makeStringInfo();
67+
const char *gid = "9999999999-0000000099";
68+
Size gidlen = strlen(gid) + 1;
69+
Size datalen = MAXALIGN(sizeof(xl_xact_prepare)) + MAXALIGN(gidlen);
6970

70-
XLogReaderState *record = palloc(sizeof(XLogReaderState));
71-
XLogRecGetData(record) = palloc(sizeof(TwoPhaseFileHeader));
72-
record->record = palloc(sizeof(TwoPhaseFileHeader));
71+
XLogReaderState *record = palloc0(sizeof(XLogReaderState));
72+
record->record = palloc0(sizeof(DecodedXLogRecord));
73+
XLogRecGetData(record) = palloc0(datalen);
7374

7475
XLogRecGetInfo(record) = XLOG_XACT_PREPARE;
75-
TwoPhaseFileHeader* tpfh = (TwoPhaseFileHeader*) XLogRecGetData(record);
76-
77-
tpfh->prepared_at = 617826371830030;
78-
tpfh->tablespace_oid_to_delete_on_commit = InvalidOid;
79-
tpfh->tablespace_oid_to_delete_on_abort = InvalidOid;
76+
xl_xact_prepare *xlrec = (xl_xact_prepare *) XLogRecGetData(record);
8077

81-
/* Can not use save_state() here, so emulate it */
82-
tpfh->gidlen = strlen("4242424242-0000000042") + 1;
83-
strcpy((char *)tpfh + sizeof(*tpfh), "4242424242-0000000042");
78+
xlrec->prepared_at = 0;
79+
xlrec->gidlen = gidlen;
80+
memcpy((char *) xlrec + MAXALIGN(sizeof(xl_xact_prepare)), gid, gidlen);
8481

8582
xact_desc(buf, record);
8683

87-
assert_string_equal("at = 2019-07-30 18:26:11.83003+00; gid = 4242424242-0000000042", buf->data);
84+
assert_string_equal("gid 9999999999-0000000099: 2000-01-01 00:00:00+00", buf->data);
8885
}
8986

9087
int

src/backend/postmaster/test/checkpointer_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ test__ForwardSyncRequest_enqueue(void **state)
6161
expect_value(LWLockRelease, lock, CheckpointerCommLock);
6262
will_be_called(LWLockRelease);
6363
#ifdef USE_ASSERT_CHECKING
64-
expect_value(LWLockHeldByMe, l, CheckpointerCommLock);
64+
expect_value(LWLockHeldByMe, lock, CheckpointerCommLock);
6565
will_return(LWLockHeldByMe, true);
6666
#endif
6767
/*

src/backend/replication/test/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ gp_replication.t: \
1111
$(MOCK_DIR)/backend/utils/error/elog_mock.o \
1212
$(MOCK_DIR)/backend/utils/misc/guc_gp_mock.o \
1313
$(MOCK_DIR)/backend/storage/lmgr/lwlock_mock.o \
14-
$(MOCK_DIR)/backend/storage/ipc/shmqueue_mock.o \
1514
$(MOCK_DIR)/backend/access/hash/hash_mock.o \
1615
$(MOCK_DIR)/backend/utils/fmgr/fmgr_mock.o \

src/backend/replication/test/gp_replication_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ expect_lwlock(LWLockMode lockmode, int count)
3232
will_return(LWLockAcquire, true);
3333

3434
#ifdef USE_ASSERT_CHECKING
35-
expect_value_count(LWLockHeldByMe, l, FTSReplicationStatusLock, count);
35+
expect_value_count(LWLockHeldByMe, lock, FTSReplicationStatusLock, count);
3636
will_return_count(LWLockHeldByMe, true, count);
3737
#endif
3838

src/backend/storage/ipc/test/procarray_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ test__CreateDistributedSnapshot(void **state)
5151
setup();
5252

5353
#ifdef USE_ASSERT_CHECKING
54-
expect_value_count(LWLockHeldByMe, l, ProcArrayLock, -1);
54+
expect_value_count(LWLockHeldByMe, lock, ProcArrayLock, -1);
5555
will_return_count(LWLockHeldByMe, true, -1);
5656
#endif
5757

src/backend/utils/init/test/postinit_test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ test_check_superuser_connection_limit_error(void **state)
4545
am_ftshandler = false;
4646

4747
expect_value(HaveNFreeProcs, n, RESERVED_FTS_CONNECTIONS);
48+
expect_any(HaveNFreeProcs, nfree);
4849
will_return(HaveNFreeProcs, false);
4950

5051
expect_ereport(FATAL);
@@ -69,6 +70,7 @@ test_check_superuser_connection_limit_ok_with_free_procs(void **state)
6970
am_ftshandler = false;
7071

7172
expect_value(HaveNFreeProcs, n, RESERVED_FTS_CONNECTIONS);
73+
expect_any(HaveNFreeProcs, nfree);
7274
will_return(HaveNFreeProcs, true);
7375

7476
/*

src/backend/utils/misc/faultinjector.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,22 +1031,22 @@ HandleFaultMessage(const char* msg)
10311031

10321032
StringInfoData buf;
10331033
pq_beginmessage(&buf, 'T');
1034-
pq_sendint(&buf, Natts_fault_message_response, 2);
1034+
pq_sendint16(&buf, Natts_fault_message_response);
10351035

10361036
pq_sendstring(&buf, "status");
1037-
pq_sendint(&buf, 0, 4); /* table oid */
1038-
pq_sendint(&buf, Anum_fault_message_response_status, 2); /* attnum */
1039-
pq_sendint(&buf, TEXTOID, 4); /* type oid */
1040-
pq_sendint(&buf, -1, 2); /* typlen */
1041-
pq_sendint(&buf, -1, 4); /* typmod */
1042-
pq_sendint(&buf, 0, 2); /* format code */
1037+
pq_sendint32(&buf, 0); /* table oid */
1038+
pq_sendint16(&buf, Anum_fault_message_response_status); /* attnum */
1039+
pq_sendint32(&buf, TEXTOID); /* type oid */
1040+
pq_sendint16(&buf, -1); /* typlen */
1041+
pq_sendint32(&buf, -1); /* typmod */
1042+
pq_sendint16(&buf, 0); /* format code */
10431043
pq_endmessage(&buf);
10441044

10451045
/* Send a DataRow message */
10461046
pq_beginmessage(&buf, 'D');
1047-
pq_sendint(&buf, Natts_fault_message_response, 2); /* # of columns */
1047+
pq_sendint16(&buf, Natts_fault_message_response); /* # of columns */
10481048

1049-
pq_sendint(&buf, len, 4);
1049+
pq_sendint32(&buf, len);
10501050
pq_sendbytes(&buf, result, len);
10511051
pq_endmessage(&buf);
10521052
EndCommand(&qc, DestRemote, false);

0 commit comments

Comments
 (0)