Skip to content

Commit

Permalink
Update test to make the number of barriers more deterministic
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 21, 2024
1 parent 6546d54 commit 1b9e443
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions test/integration/test_cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,21 @@ TEST(cluster, restart, setUp, tearDown, 0, cluster_params)
struct rows rows;
long n_records =
strtol(munit_parameters_get(params, "num_records"), NULL, 0);
char sql[128];
int rv;

HANDSHAKE;
OPEN;
PREPARE("CREATE TABLE test (n INT)", &stmt_id);
EXEC(stmt_id, &last_insert_id, &rows_affected);

PREPARE("INSERT INTO TEST(n) VALUES(?)", &stmt_id);
for (int i = 0; i < n_records; ++i) {
sprintf(sql, "INSERT INTO test(n) VALUES(%d)", i + 1);
PREPARE(sql, &stmt_id);
EXEC(stmt_id, &last_insert_id, &rows_affected);
struct value val = {.type = SQLITE_INTEGER, .integer = i};
rv = clientSendExec(f->client, stmt_id, &val, 1, NULL);
munit_assert_int(rv, ==, 0);
rv = clientRecvResult(f->client, &last_insert_id,
&rows_affected, NULL);
munit_assert_int(rv, ==, 0);
}

struct test_server *server = &f->servers[0];
Expand All @@ -128,7 +131,8 @@ TEST(cluster, restart, setUp, tearDown, 0, cluster_params)
* command entry.
*
* At 2200 records, the leader has generated a second checkpoint
* command, plus two barrier entries, one for each snapshot. */
* command, plus two barriers. (The number of barriers is nondeterministic;
* but we seem to get two of them pretty consistently in this test.) */
size_t fudge = n_records >= 2200 ? 6 :
n_records >= 993 ? 3 :
2;
Expand Down

0 comments on commit 1b9e443

Please sign in to comment.