Skip to content

Commit

Permalink
Incorporate new dqlite API in an existing test
Browse files Browse the repository at this point in the history
Signed-off-by: Cole Miller <[email protected]>
  • Loading branch information
cole-miller committed Aug 14, 2024
1 parent 6a2bb3c commit 6546d54
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
24 changes: 23 additions & 1 deletion test/integration/test_cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ TEST(cluster, restart, setUp, tearDown, 0, cluster_params)
long n_records =
strtol(munit_parameters_get(params, "num_records"), NULL, 0);
char sql[128];
int rv;

HANDSHAKE;
OPEN;
Expand All @@ -112,7 +113,28 @@ TEST(cluster, restart, setUp, tearDown, 0, cluster_params)

struct test_server *server = &f->servers[0];
test_server_stop(server);
test_server_start(server, params);

test_server_prepare(server, params);
uint64_t last_entry_index;
uint64_t last_entry_term;
rv = dqlite_node_describe_last_entry(server->dqlite,
&last_entry_index,
&last_entry_term);
munit_assert_int(rv, ==, 0);
/* When we've inserted 0 records, there are two entries:
* the initial configuration and the CREATE TABLE transaction.
*
* At 993 records, the leader has generated one legacy checkpoint
* command entry.
*
* At 2200 records, the leader has generated a second checkpoint
* command, plus two barrier entries, one for each snapshot. */
size_t fudge = n_records >= 2200 ? 6 :
n_records >= 993 ? 3 :
2;
munit_assert_ullong(last_entry_index, ==, n_records + fudge);
munit_assert_ullong(last_entry_term, ==, 1);
test_server_run(server);

/* The table is visible after restart. */
HANDSHAKE;
Expand Down
13 changes: 12 additions & 1 deletion test/lib/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void test_server_tear_down(struct test_server *s)
test_dir_tear_down(s->dir);
}

void test_server_start(struct test_server *s, const MunitParameter params[])
void test_server_prepare(struct test_server *s, const MunitParameter params[])
{
int rv;

Expand Down Expand Up @@ -128,13 +128,24 @@ void test_server_start(struct test_server *s, const MunitParameter params[])
munit_assert_int(rv, ==, 0);
}
}
}

void test_server_run(struct test_server *s)
{
int rv;

rv = dqlite_node_start(s->dqlite);
munit_assert_int(rv, ==, 0);

test_server_client_connect(s, &s->client);
}

void test_server_start(struct test_server *s, const MunitParameter params[])
{
test_server_prepare(s, params);
test_server_run(s);
}

struct client_proto *test_server_client(struct test_server *s)
{
return &s->client;
Expand Down
8 changes: 7 additions & 1 deletion test/lib/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ void test_server_setup(struct test_server *s,
/* Cleanup the test server. */
void test_server_tear_down(struct test_server *s);

/* Start the test server. */
/* Set up the test server without running it. */
void test_server_prepare(struct test_server *s, const MunitParameter params[]);

/* Run the test server after setting it up. */
void test_server_run(struct test_server *s);

/* Start the test server. Equivalent to test_server_prepare + test_server_run. */
void test_server_start(struct test_server *s, const MunitParameter params[]);

/* Stop the test server. */
Expand Down

0 comments on commit 6546d54

Please sign in to comment.