Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
Signed-off-by: Cole Miller <[email protected]>
  • Loading branch information
cole-miller committed Apr 30, 2024
1 parent cca8090 commit 65a0edf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
14 changes: 9 additions & 5 deletions test/raft/integration/test_uv_init.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#include "../../../src/raft.h"
#include "../../../src/raft/byte.h"
#include "../../../src/raft/uv_encoding.h"
#include "../lib/runner.h"
#include "../lib/uv.h"

#include <linux/magic.h>
#include <sys/vfs.h>

#define BAD_FORMAT 3
#define BAD_FORMAT_STR "3"

/******************************************************************************
*
* Fixture with a non-initialized raft_io instance and uv dependencies.
Expand Down Expand Up @@ -224,12 +228,12 @@ TEST(init, metadataOneBadFormat, setUp, tearDown, 0, NULL)
{
struct fixture *f = data;
WRITE_METADATA_FILE(1, /* Metadata file index */
3, /* Format */
BAD_FORMAT, /* Format */
1, /* Version */
1, /* Term */
0 /* Voted for */);
INIT_ERROR(f->dir, RAFT_MALFORMED,
"decode content of metadata1: bad format version 3");
"decode content of metadata1: bad format version " BAD_FORMAT_STR);
return MUNIT_OK;
}

Expand All @@ -238,7 +242,7 @@ TEST(init, metadataOneBadVersion, setUp, tearDown, 0, NULL)
{
struct fixture *f = data;
WRITE_METADATA_FILE(1, /* Metadata file index */
2, /* Format */
UV__DISK_FORMAT, /* Format */
0, /* Version */
1, /* Term */
0 /* Voted for */);
Expand All @@ -253,12 +257,12 @@ TEST(init, metadataOneAndTwoSameVersion, setUp, tearDown, 0, NULL)
{
struct fixture *f = data;
WRITE_METADATA_FILE(1, /* Metadata file index */
2, /* Format */
UV__DISK_FORMAT, /* Format */
2, /* Version */
3, /* Term */
0 /* Voted for */);
WRITE_METADATA_FILE(2, /* Metadata file index */
2, /* Format */
UV__DISK_FORMAT, /* Format */
2, /* Version */
2, /* Term */
0 /* Voted for */);
Expand Down
16 changes: 11 additions & 5 deletions test/raft/integration/test_uv_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "../../../src/raft/byte.h"
#include "../../../src/raft/uv.h"
#include "../../../src/raft/uv_encoding.h"
#include "../lib/runner.h"
#include "../lib/uv.h"

Expand Down Expand Up @@ -578,10 +579,11 @@ TEST(load, openSegmentWithIncompleteBatch, setUp, tearDown, 0, NULL)
TEST(load, openSegmentWithIncompleteFirstBatch, setUp, tearDown, 0, NULL)
{
struct fixture *f = data;
uint8_t buf[4 * WORD_SIZE] = {
2, 0, 0, 0, 0, 0, 0, 0, /* Format version */
uint8_t buf[5 * WORD_SIZE] = {
UV__DISK_FORMAT, 0, 0, 0, 0, 0, 0, 0, /* Format version */
0, 0, 0, 0, 0, 0, 0, 0, /* CRC32 checksums */
0, 0, 0, 0, 0, 0, 0, 0, /* Number of entries */
0, 0, 0, 0, 0, 0, 0, 0, /* Local data size */
0, 0, 0, 0, 0, 0, 0, 0 /* Batch data */
};
APPEND(1, 1);
Expand Down Expand Up @@ -1633,7 +1635,7 @@ TEST(load, openSegmentWithIncompleteBatchHeader, setUp, tearDown, 0, NULL)
DirTruncateFile(f->dir, "open-1", offset);
LOAD_ERROR(RAFT_IOERR,
"load open segment open-1: entries batch 1 starting at byte 8: "
"read header: short read: 8 bytes instead of 24");
"read header: short read: 8 bytes instead of 16");
return MUNIT_OK;
}

Expand All @@ -1646,15 +1648,19 @@ TEST(load, openSegmentWithIncompleteBatchData, setUp, tearDown, 0, NULL)
WORD_SIZE + /* Number of entries */
WORD_SIZE + /* Entry term */
WORD_SIZE + /* Entry type and data size */
WORD_SIZE +
WORD_SIZE / 2 /* Partial entry data */;

#ifdef DQLITE_NEXT
offset += WORD_SIZE; /* Local data size */
#endif

APPEND(1, 1);
UNFINALIZE(1, 1, 1);
DirTruncateFile(f->dir, "open-1", offset);

LOAD_ERROR(RAFT_IOERR,
"load open segment open-1: entries batch 1 starting at byte 8: "
"read data: short read: 4 bytes instead of 24");
"read data: short read: 4 bytes instead of 8");
return MUNIT_OK;
}

Expand Down
13 changes: 7 additions & 6 deletions test/raft/integration/test_uv_set_term.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../../../src/raft.h"
#include "../../../src/raft/byte.h"
#include "../../../src/raft/uv_encoding.h"
#include "../lib/runner.h"
#include "../lib/uv.h"

Expand Down Expand Up @@ -88,7 +89,7 @@ static void closeCb(struct raft_io *io)
char filename[strlen("metadataN") + 1]; \
sprintf(filename, "metadata%d", N); \
DirReadFile(f->dir, filename, buf2, sizeof buf2); \
munit_assert_int(byteGet64(&cursor), ==, 2); \
munit_assert_int(byteGet64(&cursor), ==, UV__DISK_FORMAT); \
munit_assert_int(byteGet64(&cursor), ==, VERSION); \
munit_assert_int(byteGet64(&cursor), ==, TERM); \
munit_assert_int(byteGet64(&cursor), ==, VOTED_FOR); \
Expand Down Expand Up @@ -184,7 +185,7 @@ TEST(set_term, metadataOneExists, setUpDeps, tearDown, 0, NULL)
{
struct fixture *f = data;
WRITE_METADATA_FILE(1, /* Metadata file index */
2, /* Format */
UV__DISK_FORMAT, /* Format */
1, /* Version */
1, /* Term */
0 /* Voted for */);
Expand All @@ -200,12 +201,12 @@ TEST(set_term, metadataOneIsGreater, setUpDeps, tearDown, 0, NULL)
{
struct fixture *f = data;
WRITE_METADATA_FILE(1, /* Metadata file index */
2, /* Format */
UV__DISK_FORMAT, /* Format */
3, /* Version */
3, /* Term */
0 /* Voted for */);
WRITE_METADATA_FILE(2, /* Metadata file index */
2, /* Format */
UV__DISK_FORMAT, /* Format */
2, /* Version */
2, /* Term */
0 /* Voted for */);
Expand All @@ -223,12 +224,12 @@ TEST(set_term, metadataTwoIsGreater, setUpDeps, tearDown, 0, NULL)
{
struct fixture *f = data;
WRITE_METADATA_FILE(1, /* Metadata file index */
2, /* Format */
UV__DISK_FORMAT, /* Format */
1, /* Version */
1, /* Term */
0 /* Voted for */);
WRITE_METADATA_FILE(2, /* Metadata file index */
2, /* Format */
UV__DISK_FORMAT, /* Format */
2, /* Version */
2, /* Term */
0 /* Voted for */);
Expand Down

0 comments on commit 65a0edf

Please sign in to comment.