From 6546d543d339691c1ee1f185cbcd02aa4a6be1ba Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Tue, 13 Aug 2024 23:26:28 -0400 Subject: [PATCH] Incorporate new dqlite API in an existing test Signed-off-by: Cole Miller --- test/integration/test_cluster.c | 24 +++++++++++++++++++++++- test/lib/server.c | 13 ++++++++++++- test/lib/server.h | 8 +++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/test/integration/test_cluster.c b/test/integration/test_cluster.c index 57f605cff..bd507f17e 100644 --- a/test/integration/test_cluster.c +++ b/test/integration/test_cluster.c @@ -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; @@ -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; diff --git a/test/lib/server.c b/test/lib/server.c index 89d4060cb..1bfdb6b98 100644 --- a/test/lib/server.c +++ b/test/lib/server.c @@ -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; @@ -128,6 +128,11 @@ 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); @@ -135,6 +140,12 @@ void test_server_start(struct test_server *s, const MunitParameter params[]) 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; diff --git a/test/lib/server.h b/test/lib/server.h index 7e0dc111b..8b559108e 100644 --- a/test/lib/server.h +++ b/test/lib/server.h @@ -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. */